{"_id":"@sphereon/openid4vci-client","_rev":"119-772ff60cf4fae8f8e7bef4c34f54b088","name":"@sphereon/openid4vci-client","dist-tags":{"latest":"0.4.0","unstable":"0.4.1-unstable.245","next":"0.4.1-next.246"},"versions":{"0.3.0":{"name":"@sphereon/openid4vci-client","version":"0.3.0","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","main":"dist/main/index.js","types":"dist/main/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"scripts":{"build":"run-p build:*","build:main":"tsc -p tsconfig.build.json","clean":"rimraf dist coverage","watch":"tsc -w","fix":"run-s fix:*","fix:prettier":"prettier \"{lib,tests}/**/*.ts\" --write","fix:lint":"eslint . --ext .ts --fix","test":"run-s build test:*","test:lint":"eslint . --ext .ts","test:prettier":"prettier \"{lib,tests}/**/*.ts\" --list-different","test:cov":"jest --ci --coverage && codecov","uninstall":"rimraf dist coverage yarn.lock package-lock.json node_modules"},"engines":{"node":">=14"},"dependencies":{"@sphereon/ssi-types":"0.8.1-unstable.86","debug":"^4.3.4","bs58":"^5.0.0","cross-fetch":"^3.1.5","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^28.1.8","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","prettier":"^2.7.1","rimraf":"^3.0.2","ts-jest":"^29.0.3","ts-node":"^10.9.1","typescript":"4.6.4"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"licenseText":"                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [2022] [Sphereon B.V.]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n","_id":"@sphereon/openid4vci-client@0.3.0","dist":{"shasum":"a57ac9d5cee02bb439a749b6d1f0aa95c5fcb55d","integrity":"sha512-mAzlc1kewSSHUHvoVHD5nhcbD+Xm8pDFqjZEh6nj8dPRYphoLJWiUIyo1pzp3TaDdlmJb8pSz5gwAmLiX0AN/w==","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.3.0.tgz","fileCount":51,"unpackedSize":192810,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDzXbEAgiJr0CIirli3YF62DoTsnMm0CbyTwdhxFCKZcgIhAM3+9uPsXw/UAtJZwzquJIHeljJPL8Visi+kYfC1O660"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjeUISACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmomGA//RDFljvEBGVdG022m8GaYwyUwZgqtS04Iojp6X1GMJ7oNC4fG\r\nDdTrjybZTciquMM3koBwIIDuCOR/VDKrlaHzYBynqQorFU3sob+T2AtnBCl6\r\nSrZF35lX+jy2vtiEn/nPf85xON+s+a54bSVjjj34klrxNH4R6WWmnA72DF4j\r\n8baqatWbwHgirdeZ+P7APhMEWSMSgHAdJh0WuSNd0N9aG0DR5jbwk2nKgmsO\r\nWQULGaVBuqnewojYneE8/ie2YND8/54fwvUK/6Os6XGyi6jw43mh8rabcfFY\r\nJYF55eByxkNzQ0bzG1woU5X46o0e+bLOYLT9/IpVm+Iay9jDUxPDd5Ps8I8u\r\nbm0hXcBcNnQcVFkDMZYlarhN05jIWyKkmq5QGVjyozi8b2vnqefYnDzGazck\r\nX/bamFyWUWa+km6txVUytDbUB7RxmY3YAQAymjiGsrzpAOJYswaUXKmftUCt\r\nimCDgIyZ4LUtve5boZpGW/vzRxHA/PWmoordXp0/EdN916SQwYRZDbFgK0EY\r\nxfm5ExCVXWEapW4z2hPtC+1ekNNXyBhuXIOPaBzXXAgX5qWM79AsiPDj2691\r\n4SLyH7e/ohYugRCTV5O5CQLT0uanNzAYz1wKza6gKaeS2k2+pjoRbySB8RIp\r\nb32CdDbqGDkX3f7lYzxZn2QJcpAqM2n8xK8=\r\n=4f1J\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.3.0_1668891154502_0.7133808825454431"},"_hasShrinkwrap":false},"0.3.1-unstable.0":{"name":"@sphereon/openid4vci-client","version":"0.3.1-unstable.0","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","main":"dist/main/index.js","types":"dist/main/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"scripts":{"build":"run-p build:*","build:main":"tsc -p tsconfig.build.json","clean":"rimraf dist coverage","watch":"tsc -w","fix":"run-s fix:*","fix:prettier":"prettier \"{lib,tests}/**/*.ts\" --write","fix:lint":"eslint . --ext .ts --fix","test":"run-s build test:*","test:lint":"eslint . --ext .ts","test:prettier":"prettier \"{lib,tests}/**/*.ts\" --list-different","test:cov":"jest --ci --coverage && codecov","uninstall":"rimraf dist coverage yarn.lock package-lock.json node_modules"},"engines":{"node":">=14"},"dependencies":{"@sphereon/ssi-types":"0.8.1-unstable.86","debug":"^4.3.4","bs58":"^5.0.0","cross-fetch":"^3.1.5","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^28.1.8","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","prettier":"^2.7.1","rimraf":"^3.0.2","ts-jest":"^29.0.3","ts-node":"^10.9.1","typescript":"4.6.4"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"licenseText":"                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [2022] [Sphereon B.V.]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n","_id":"@sphereon/openid4vci-client@0.3.1-unstable.0","dist":{"shasum":"3452bdb65012b66e527db82709503306ddd938b7","integrity":"sha512-Cdm7+uRh/N4NBUbWLS+WD7IMl7vWjuW4fa7g9kZoEPhxxAw7ji5qAtbCR9JUgqjyBBQsGSnWtaCIUpBR6/LLZA==","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.3.1-unstable.0.tgz","fileCount":51,"unpackedSize":193639,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIC7xLGFnWwhDiHPnwNr9Zhp0ri9tproTFCCE2rHCN6ruAiBzoBEwT26LqyN8n3unMLAzGX6jkRtVJwtDUEL7oEthTA=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjeVELACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmr0lQ//Vmt/c6qj/nu/DcvYtieISS23NgVlJGmKeyBbIcVx6ebdCEvD\r\n39r7Ax/9z4tzWsdHHfmHHLaBPz+l431ojo72YMB7CuHPz0k0EAHEzUqkAE63\r\nlc5oFHnYkGn/SNfXzpnf2lyvrN/rJRGcDYer1swXfeXSu2efdzvNYVhmg1tp\r\no0kI9mGdcb0Z0U8eHdVlyIGh3ELfxIggsfGTRn+qhuJhN6MLIIDDFcMyrMrC\r\nRClbzbsW9XM1LIuKo6uxkge9WCZs7pfIxEAQ2c7Dz91YVb3JDk9Vag9Dnzsu\r\nWunzgUCjARNkVpbBveokiVnhDDOt4t0T9RuG+nISVvJRDEoS29aBk+IXmVEo\r\nOeUzVlxM/5W0gzzH1F2d67bMllhrkK+ZlMsRrE26aK7Y0ZUykxKFKrJnMv/8\r\nAPhJ+76iMAa5C18QsGo9htiKQXS+5qTH3lru8L4Xpn7CJ+pYbNIL19FkNAQ3\r\nMb4WReCYI4n3s41cBeNgjsw9agzz+U3R2RE4uhzpJxqx7vF2nHiUHmtSIUrt\r\nntI7kyh9bcwZWWoOkTN4hTKSqlqGzsEugJwptfC1vPwsHNfe1+JuuycD139/\r\nPODZqax/oe3/1joQIoD4MaaTZFzNScqlQ9ax3twFCQA5nPqrAi1PanBPLH80\r\netHeGS+OeDt3ynxQd9QTiGTr4sdOLR8qUF8=\r\n=Z7Pt\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.3.1-unstable.0_1668894986842_0.4512015741153965"},"_hasShrinkwrap":false},"0.3.1-unstable.1":{"name":"@sphereon/openid4vci-client","version":"0.3.1-unstable.1","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","main":"dist/main/index.js","types":"dist/main/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"scripts":{"build":"run-p build:*","build:main":"tsc -p tsconfig.build.json","clean":"rimraf dist coverage","watch":"tsc -w","fix":"run-s fix:*","fix:prettier":"prettier \"{lib,tests}/**/*.ts\" --write","fix:lint":"eslint . --ext .ts --fix","test":"run-s build test:*","test:lint":"eslint . --ext .ts","test:prettier":"prettier \"{lib,tests}/**/*.ts\" --list-different","test:cov":"jest --ci --coverage && codecov","uninstall":"rimraf dist coverage yarn.lock package-lock.json node_modules"},"engines":{"node":">=14"},"dependencies":{"@sphereon/ssi-types":"0.8.1-unstable.86","debug":"^4.3.4","bs58":"^5.0.0","cross-fetch":"^3.1.5","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^28.1.8","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","prettier":"^2.7.1","rimraf":"^3.0.2","ts-jest":"^29.0.3","ts-node":"^10.9.1","typescript":"4.6.4"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"licenseText":"                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [2022] [Sphereon B.V.]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n","_id":"@sphereon/openid4vci-client@0.3.1-unstable.1","dist":{"shasum":"b898c776c7e3be3ebb160e18dbc362013d65b0ea","integrity":"sha512-Ss+z6754RkZh8jeaOqFLymrqKMbwugEcFAgHzWdER5l6F1ANUrn4Qg6a8aUsCfkM8UT69L7hIumBvtIduTWUyQ==","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.3.1-unstable.1.tgz","fileCount":51,"unpackedSize":196361,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDs1Wc2Fk+1YIbRGLZpNvMGFM5hD0/uwwzVbSgMnDtvWAIgUr+m+xcoLsg+07WBnBKDCoL5UKPL/uYF/7qJHWzDTwM="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjeXAAACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoiyQ//YqCFrzAn3xDYNdsEyerFfUu4VolWaKHu8FFSayAL1KoYhd/m\r\nzYYF/XqL4xV70MGDa9hr8hNEjxhQHOkguzJ2TyB27nCUK+2DUsXcBwE2fVtn\r\nyAcCFLuefiratCkVKXIYEU8Ackgwdod2gcA+aD97c1B2vucf50iH0BIxxiN2\r\nQc5aHzmdICPq0Duon6O9M0pP/UBGpgjDiMQ9/MG1AYXk7twMgWjE3eEYkNc3\r\njFIX6MM7jbB2qvt/GA46LLpUZlkSwryF5s8N5ndwkmFx2kvY3bWIUkI5KawJ\r\n9Urb7HKMyLp5HgZIJGstf7HkpigFZEJfzCEWCo46xmFAG83v4bcGoVIQyWrd\r\nLjXiy+mOoRSCv7l0nOY26g23RZ/p9TLFy9Mz6tnLEDEf57Wtc9D+B/lJhVBc\r\nXMDiT+Y4V7yYne9/88KtJVWJh8Nc8cWpFXHHHfa1w32VmwTQJb6Bo69jBbUc\r\n+2H9c2HWQFREg74Q6QJULMT8rEhlRo/kmd3GVN0C9eBDZ8fCugHOI0WjWJUJ\r\nfNMeSBUseP930nD3u7hHx772pD4WZmH+96u+DFmYzrwOhzWW/nbXVdd8LsPS\r\nZRfU8VBPCLA+000XrPei12uj/0mLHgjUJK01JGfrj/tMk+GGOtprRMmcmjGo\r\nu7FAW55x9bR13uQAj+UWn4JtO2eqklXHKCo=\r\n=etAc\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.3.1-unstable.1_1668902911942_0.9922706830501193"},"_hasShrinkwrap":false},"0.3.1-unstable.2":{"name":"@sphereon/openid4vci-client","version":"0.3.1-unstable.2","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","main":"dist/main/index.js","types":"dist/main/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"scripts":{"build":"run-p build:*","build:main":"tsc -p tsconfig.build.json","clean":"rimraf dist coverage","watch":"tsc -w","fix":"run-s fix:*","fix:prettier":"prettier \"{lib,tests}/**/*.ts\" --write","fix:lint":"eslint . --ext .ts --fix","test":"run-s build test:*","test:lint":"eslint . --ext .ts","test:prettier":"prettier \"{lib,tests}/**/*.ts\" --list-different","test:cov":"jest --ci --coverage && codecov","uninstall":"rimraf dist coverage yarn.lock package-lock.json node_modules"},"engines":{"node":">=14"},"dependencies":{"@sphereon/ssi-types":"0.8.1-unstable.86","debug":"^4.3.4","bs58":"^5.0.0","cross-fetch":"^3.1.5","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^28.1.8","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","prettier":"^2.7.1","rimraf":"^3.0.2","ts-jest":"^29.0.3","ts-node":"^10.9.1","typescript":"4.6.4"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"licenseText":"                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [2022] [Sphereon B.V.]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n","_id":"@sphereon/openid4vci-client@0.3.1-unstable.2","dist":{"shasum":"2436af8c8af44c45ea3fc31530d18f7497fec626","integrity":"sha512-+JKb0pubZByRPu8y0HBo7I5dmO/VmQollSb7z9wNTbIfiDMghS4wI72mo0VQ5hSipcS2eBU8k+thyL6/iJyWdw==","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.3.1-unstable.2.tgz","fileCount":51,"unpackedSize":196952,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBfRDiOM/MGWaxUyw4TIT3ni40MBZwv26UgBPTL8sxhoAiBdFemtgCRvVX8g7BMDsVOfTGholxxL4ER3V1WGRYpGEQ=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjeZQ/ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqRthAAjYZTaFWBUo9EiWjW7hny5rymz/PfT3qaGh5a3Pqh3r+r4HwL\r\nIvqCOQidbii3ft65qEPXTQ9iG2dHvmlhf3gTBUyA9PTDKt1nb3rAaDBbNk3z\r\nOZVfrbXA7hMtvb7zmP6x/HZi0pk06dxkdf69ghDbmze0KBYpJQZ+HUNr0/z+\r\nc967/9K0UINx/jERq/EH3K5Zs/Y/MxALs+/c227Cgf703+d/7Mxd+ko+R9Kc\r\nmnKHr3qLyog4gbxnILWxo0Rto0d+tDZn5oDCzQJ3/agTVLx5g6UzCRThsrjF\r\nn0P9HUpn8kgNJ8a5E499evGFB+Tm0rS5QGiYGc0fkjvG+fLo4vbovSNd4RW3\r\nNvHT3p8CSoGDFF02Xx/Oo0FJpJhF+khBj5Dku5XEhmqJyztxrKAXVfOjLc+C\r\nlSqxVxskfGlCmY/wfdsVqGlJyu/yZOH+OUZ6v2FvZIoK/0A8+wpLJo6eaI76\r\nI9NWBo+HrnY7xRktNHtQ0C/GEYSbUxhHr2eVxUdHLEg70rrqgtHvI4/0l6iO\r\n5UYPYnQ6T9fUak228S2JlPq6pWu3xAZ4W28slMsoExnBzsUXJqap7k+Lap0G\r\ny0klO01M04AGu5eIkbaeuLS3qAk4aIPzwhkgVh6/Sk8KIELnmKb2Vq6k+JEb\r\ndOaVS/oTuWFrr6++4yWxfAzM4gd5lPomNEY=\r\n=AmAW\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.3.1-unstable.2_1668912191765_0.8828979867684674"},"_hasShrinkwrap":false},"0.3.1-unstable.3":{"name":"@sphereon/openid4vci-client","version":"0.3.1-unstable.3","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","main":"dist/main/index.js","types":"dist/main/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"scripts":{"build":"run-p build:*","build:main":"tsc -p tsconfig.build.json","clean":"rimraf dist coverage","watch":"tsc -w","fix":"run-s fix:*","fix:prettier":"prettier \"{lib,tests}/**/*.ts\" --write","fix:lint":"eslint . --ext .ts --fix","test":"run-s build test:*","test:lint":"eslint . --ext .ts","test:prettier":"prettier \"{lib,tests}/**/*.ts\" --list-different","test:cov":"jest --ci --coverage && codecov","uninstall":"rimraf dist coverage yarn.lock package-lock.json node_modules"},"engines":{"node":">=14"},"dependencies":{"@sphereon/ssi-types":"0.8.1-unstable.86","debug":"^4.3.4","bs58":"^5.0.0","cross-fetch":"^3.1.5","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^28.1.8","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","prettier":"^2.7.1","rimraf":"^3.0.2","ts-jest":"^29.0.3","ts-node":"^10.9.1","typescript":"4.6.4"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"licenseText":"                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [2022] [Sphereon B.V.]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n","_id":"@sphereon/openid4vci-client@0.3.1-unstable.3","dist":{"shasum":"350d5cf8b46d25adec0101859baaa7affd45ffe5","integrity":"sha512-U8wTENLfysr3TVd9L7clIPLJnC0FbHMRkgU6rdQElN123jnTUPSdxkdEE77sQEV409kvVSrBYS3Vq3vtxtZ4KQ==","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.3.1-unstable.3.tgz","fileCount":51,"unpackedSize":197168,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCxWX9Kbg3b8cdnobRRVLtsCXeA1/PUYfQp4qzzKzSV+wIgBmxD0bPGVtGHo/axpaZD1+WenfgDjQZjtyg5ICQPVfI="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjeZ+qACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrM1BAAnJ/7E4F/VqY2918WW7NurDBidoQ3F4xa+S7BFC7ZkOftRENk\r\ncw1V/wqAzZoqv+uQxX5zb4GUV3us0oIUmHUtFIdX1a7A4AYpyzhKBpbtlbob\r\nExefq0FxIUvpkgsS3K2U2jtFCNxr6mXjKdVbL0pKMHcW3M9J8Yy2UyNEJg7R\r\nKT1ahUfGPX7rgQEkq3sX08yOD6Huwc+4t26T4jhJVY37eZD/cET040FCx7C6\r\n3piwyUb0Eofh05b2YHVqBTk0YjqlUY/hjgEzuEjcnwSosrnEX+Eqdm10Fgj6\r\n6rqIItqTH/XVqxCxdKlyQ1kfWFTA3kO24JlJWKrH5V4OJccfi9UZNK7gOPbX\r\n63zgkKhNEBcsnV90wQ5SQwL84myFmYYjjniPuRDN6a0NhWgatOk/awV/juiy\r\nLNU3nrHi0Gkp8CfU7wefoWX0/y8koWgTjxkZVUZTRAp6raP40reyaJnrVyJp\r\nF1V0IFeZMGcPWtIYKJalcdjylNYre8d+ucpLqQsldn9IFV0coYkB6jfRx18N\r\ngqDcD+X2ZMnJzV1lDlJ6v95u0n2NdPa6+an1KRaxxGNyeg9jol815Qh4xo7L\r\nF8v/YU/qyqJi+yw5cOahbPGbTmDubefBFgxVHKlNB4y6AC6s4HW80o+mWwi7\r\nTW2GpXVuFI37vfluLvW8qrXv1aEPOPu4osc=\r\n=S2Yn\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.3.1-unstable.3_1668915114662_0.9988719843930334"},"_hasShrinkwrap":false},"0.3.1-unstable.4":{"name":"@sphereon/openid4vci-client","version":"0.3.1-unstable.4","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","main":"dist/main/index.js","types":"dist/main/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"scripts":{"build":"run-p build:*","build:main":"tsc -p tsconfig.build.json","clean":"rimraf dist coverage","watch":"tsc -w","fix":"run-s fix:*","fix:prettier":"prettier \"{lib,tests}/**/*.ts\" --write","fix:lint":"eslint . --ext .ts --fix","test":"run-s build test:*","test:lint":"eslint . --ext .ts","test:prettier":"prettier \"{lib,tests}/**/*.ts\" --list-different","test:cov":"jest --ci --coverage && codecov","uninstall":"rimraf dist coverage yarn.lock package-lock.json node_modules"},"engines":{"node":">=14"},"dependencies":{"@sphereon/ssi-types":"0.8.1-unstable.86","debug":"^4.3.4","bs58":"^5.0.0","cross-fetch":"^3.1.5","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^28.1.8","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","prettier":"^2.7.1","rimraf":"^3.0.2","ts-jest":"^29.0.3","ts-node":"^10.9.1","typescript":"4.6.4"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"licenseText":"                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [2022] [Sphereon B.V.]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n","_id":"@sphereon/openid4vci-client@0.3.1-unstable.4","dist":{"shasum":"e8445b194ddc31671f549ee6c2fb580ef4859855","integrity":"sha512-V1+GDLmJwVHeB/s1rYWHKVN37S950YXySFHTW2R3EA05grKoQ4z91Bu5Kl2jxXqBlZhZ7xUM/c8RwSpep5CECA==","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.3.1-unstable.4.tgz","fileCount":51,"unpackedSize":198032,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIENUugVFI/SlQJhUUpdfK4a8Z/gV2Mc4hO2Lo2Ds2saBAiEA12ppaP37WRzCxY+fFd7ACYotYPeLAs3gy+pLrkg0QRw="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjeaKUACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmr2rQ//U6d1iXVoDfinApjAqnbODXsRjVdLKS+kv+xHkiIv1dY5Ic0L\r\nqQ8+d57sF1Y5mlvh480+YrN0s18d3fZ8Umm96a+OrVSS/KloZA5N0CQPZ6pC\r\nIFE4SGFjGq+8iLvB/Cx1WvS0FuKmpq6x7OAcgDFiCf8I8GvDMkcMXKAo0Vl9\r\n/G3miravX5FBzF/QQfyIJxn6zpWviVlz6bf5i0Uf4jugZM+mMZ6tOgjuMdl4\r\nmqiSUM0s7DMD36FWq45FLvkkVno6zVGxl2Xef8oElAlehWR0L9rEY4LvSYAP\r\nkq10hIrupnMg6/qFJnda31qhMOOjtXmneStfP/r6LMp+JUlRBJU/cJKcIejh\r\nUW6CDX39tEURq3s3lCfHp2V3a0DoJtGUyScKRcZWE5Bt+2/+ehhKq2P3yhua\r\nkoSspUVRM8PSy4cXdRDEQP7IgxtI9muDOFEFVMlQYvWgOWNOQpXYwvXjzKuA\r\njyFN+q5jV9GPttztgNTIvH6J3vVzE9BdO4PSYJOEGaON5tsR9O9hdrfkPxIK\r\nSQrgFRqcvx9yEvXBkhQV3fmgE08+yV5GY1YR7dYukWrNwuBFghWtZtdoB8mO\r\nawlVfxae/IOYDLqGXf67ObhAfe5x/94U7DhdBrlC//tv05V8v9CKinuhBU3a\r\nTuP8I6Z8HBrwzjaXiAngkY9XoDLmf8NONhg=\r\n=pNec\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.3.1-unstable.4_1668915860771_0.03901005127722912"},"_hasShrinkwrap":false},"0.3.1":{"name":"@sphereon/openid4vci-client","version":"0.3.1","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","main":"dist/main/index.js","types":"dist/main/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"scripts":{"build":"run-p build:*","build:main":"tsc -p tsconfig.build.json","clean":"rimraf dist coverage","watch":"tsc -w","fix":"run-s fix:*","fix:prettier":"prettier \"{lib,tests}/**/*.ts\" --write","fix:lint":"eslint . --ext .ts --fix","test":"run-s build test:*","test:lint":"eslint . --ext .ts","test:prettier":"prettier \"{lib,tests}/**/*.ts\" --list-different","test:cov":"jest --ci --coverage && codecov","uninstall":"rimraf dist coverage yarn.lock package-lock.json node_modules"},"engines":{"node":">=14"},"dependencies":{"@sphereon/ssi-types":"0.8.1-unstable.86","debug":"^4.3.4","bs58":"^5.0.0","cross-fetch":"^3.1.5","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^28.1.8","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","prettier":"^2.7.1","rimraf":"^3.0.2","ts-jest":"^29.0.3","ts-node":"^10.9.1","typescript":"4.6.4"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"licenseText":"                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [2022] [Sphereon B.V.]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n","_id":"@sphereon/openid4vci-client@0.3.1","dist":{"shasum":"fcce058bfeaf963241524475230da53934a868a6","integrity":"sha512-n8cS23ew+XyZqg9cP+EAez4bQSHfKiiPeaSvUuYLUYRSDRFJetvrkNr25iAxRfTNcHF7R9ay5VxYvz4/MvaQYg==","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.3.1.tgz","fileCount":51,"unpackedSize":195926,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCNwNY4txs7ONBTyuhpe208psxON3+oQCo8Ab6jiv1bRQIhAM2wstezBSTmZ4xBJgE52DpgvQsnngFlyL9xU4rPLUNw"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjehZpACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmraBw//byQpN553oh4LK5E6sb5fFXJ77xb1L+TjCKMNyorZTZPVhEaq\r\nhpQk4An+0TmBfTpSV3/McmE1+6ly5CR8kADO8cRA7kY+wyGNCsyEES3GuaL4\r\nmdSQdTqgYfi9FTaYSVFEM4LwfRrbCBLayh75JuPB5VEpFnuf7v81CfNl2ayo\r\nWvjr+FDGjTNybVhs6Epq7yic05yNklF1LxNM0uNKZeaPTwVEvlryJL2iDWX0\r\nelZdt3hWMx/7iIW17hbUIz8NDfr3PbkK5ZjzlhM7Wj1NtMHncwwvZYPg0T6B\r\n3C2KsEv0HnskFDLBn677Xr27a7ArS9AFEMkQdP0H2eUyxh0jEH3vV8fWnRie\r\np6VquwPQhg7FZj3TEJ3Rnvqay8EPbEjPRmREuTZgaQwKBVBlTWOkGCN3q92X\r\nc9n5nbjXCeDo62DLSIJIL5bWFyrnQhOe89BRB5VgQa0cYV1C13KOsPHwt3KV\r\nQaK5P1wu8X9arbsTnT9uzDTTAIGC/qEn8Q3E4gtUwaijRmLMPkLZiyUn1JBQ\r\nDHrQ6U//2Wji6qAyi36aWQRni2dV+aREKKbSez7CAsxqB8vIXLw7SCwdHILv\r\n8b9ruDAyPXb8QF1EYqT4C0nqIC3WLX9dcnlVUYMnPJRuKg3/mu0Gv9Qw3nlE\r\nzz6x+j0xToMsY8xkyQ7pt6JWdwJ71U90vkY=\r\n=FJwv\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.3.1_1668945513692_0.5208471579244609"},"_hasShrinkwrap":false},"0.3.2-unstable.1":{"name":"@sphereon/openid4vci-client","version":"0.3.2-unstable.1","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","main":"dist/main/index.js","types":"dist/main/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"scripts":{"build":"run-p build:*","build:main":"tsc -p tsconfig.build.json","clean":"rimraf dist coverage","watch":"tsc -w","fix":"run-s fix:*","fix:prettier":"prettier \"{lib,tests}/**/*.ts\" --write","fix:lint":"eslint . --ext .ts --fix","test":"run-s build test:*","test:lint":"eslint . --ext .ts","test:prettier":"prettier \"{lib,tests}/**/*.ts\" --list-different","test:cov":"jest --ci --coverage && codecov","uninstall":"rimraf dist coverage yarn.lock package-lock.json node_modules"},"engines":{"node":">=14"},"dependencies":{"@sphereon/ssi-types":"0.8.1-unstable.86","bs58":"^5.0.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^28.1.8","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","prettier":"^2.7.1","rimraf":"^3.0.2","ts-jest":"^29.0.3","ts-node":"^10.9.1","typescript":"4.6.4"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"licenseText":"                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [2022] [Sphereon B.V.]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n","_id":"@sphereon/openid4vci-client@0.3.2-unstable.1","dist":{"shasum":"0b4363945cf784c542d49159f953862ba3d10935","integrity":"sha512-7l6e2eR+LGYiNjt4ZEnZEObVyFij3KYpFciFBqTNnrVA7vC/6tB0wDk9SSaN4h0UxQvf3kNYuCbox9EpwKx09w==","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.3.2-unstable.1.tgz","fileCount":51,"unpackedSize":197837,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDyzXypB1JjPRgsnBvrXtZFSjfnTC6hO0gKfyunPqPYIgIgIjWQoGsxm00FeN75u7F55ITHZRXZAQZyjd2BhW8qUJw="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJje2BkACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoDLxAAl8n02wYvzFAlQvTvqcOASzaA5MPcLJnPMhBIxtEMzMyquWcG\r\nkUZndT1HQSVh9FaFDhyOoxKBnSLZXBFl8RARfrvf+hqh7zxM71K6pLHaoJph\r\ngzNdgm/ppxgDQGpnfo0+jQ6x2hfKr62TPhsCN+YBC7oqeDoyQeRD65I4xenD\r\nZkX022ffK7B8fVUHNFU7HzT+hjrNeP0eyBchATSvALhO1Yw3Y5/A26ge7Wic\r\nyIeO2FCHttW9fjSO7UthEKf6SOVP4rF7bayAwWujfdfUhYdJ+mQLIiMm5HHG\r\nYzLngZm8SDvb4NYOaSvLLimpmyyA0gRsW2YKG3SK5/ytP+6pO5ez7VSTumln\r\naR/SvwmtELvBxl1PhEr/xePnbqHJ7wkoOdnEKLtcdSv1itq7dlRTlCftAcOP\r\n/Zc+sJ3NjyNy3OdOGW3QzNJqdvtLN6CMXJ4RXJes3kjsqkWIo/6REx+O7m6H\r\n+T9/B1O/l0qo3d/Q2BA9H/7n470NiiB97yZ3aPLN8vkSF0GfdFuMRFXjd2PV\r\nBaYVWdSY03UgdbFtnLrBU0YRnHYJY88TBOKyJqriwFyYJyyPolW7MT0cpJTz\r\nwjImqxA4cwl9QHnXC8TTRdpunoskD2HVJOwq6U7OKLhBCi1PbXmzNx+9U+Po\r\nbXYCifuAjWDT9C8A7UaQsB4gPkjjb17AFvE=\r\n=pcJt\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.3.2-unstable.1_1669029988289_0.6770126670824657"},"_hasShrinkwrap":false},"0.3.2":{"name":"@sphereon/openid4vci-client","version":"0.3.2","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","main":"dist/main/index.js","types":"dist/main/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"scripts":{"build":"run-p build:*","build:main":"tsc -p tsconfig.build.json","clean":"rimraf dist coverage","watch":"tsc -w","fix":"run-s fix:*","fix:prettier":"prettier \"{lib,tests}/**/*.ts\" --write","fix:lint":"eslint . --ext .ts --fix","test":"run-s build test:*","test:lint":"eslint . --ext .ts","test:prettier":"prettier \"{lib,tests}/**/*.ts\" --list-different","test:cov":"jest --ci --coverage && codecov","uninstall":"rimraf dist coverage yarn.lock package-lock.json node_modules"},"engines":{"node":">=14"},"dependencies":{"@sphereon/ssi-types":"0.8.1-unstable.86","bs58":"^5.0.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^28.1.8","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","prettier":"^2.7.1","rimraf":"^3.0.2","ts-jest":"^29.0.3","ts-node":"^10.9.1","typescript":"4.6.4"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"licenseText":"                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [2022] [Sphereon B.V.]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n","_id":"@sphereon/openid4vci-client@0.3.2","dist":{"shasum":"f442a68c1532d293ea8d5770a41a0b5fdac7b810","integrity":"sha512-EeIKwQi0caSWlTr0hW417A/WXBEzFm656Ig6e9Un/fGbi19Cz7woX7cOgF0oxC/rXF5IdQQqoC0dAJ6B54mcVQ==","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.3.2.tgz","fileCount":51,"unpackedSize":196550,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCpJx2x3PDwGb46iQ7hYBI33ZFdmz+6aQsZGOz+8SZoNgIgTqfUHiubchS+atrElbBayA6QsUeJIpMMA4e+4qWJsiU="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJje2bMACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpCbRAAgvrxrPgHvBdUqz8JJRqRWzxPHHtvB1ueaxfl/3DwazKZjR5r\r\nsCf7uJ/pGz0lL4G7Wyl+f1oVkL8j/BQrNlRfpcHHRuhZH2dHItMdBmkM9JuM\r\nAyH3uaBXt2jvI9Hek0cVUa6dazASTADtr673mjmpsMOO//sgUe9RRzCKxyPM\r\nvk+rea5FyctpwzNaVubMFnTjlzelFi6hWkkQwcKx2LV42t6bgd4lEH6jUnN7\r\npudNt5nJlMrPBl1u2IdPLDQH2nUFoSWvhh9+l17plD7si64uRb85qO7IFhq3\r\nFW0BXFnYiqmold+rViPfb8pXa3coOOSLqS14KaqnUWpY4ftJVVbp8Z4NsZ9C\r\nyrakfjEfDN5rZ3jdanWwJvIp0M19b77GlWwiwFfu8ZjODAz+qlUzS+LCC2sC\r\nmNPYMdXVFVpp7I5wK/XQLtpEbziQHIuTP8Ygmb7tF5L13XxtlPbl8pbKoSGD\r\nveCpMTS9Fs0QeU6N+rMkUszbv9Esqb860HUhZjiv5LHwCLMJxWE2Kd01ntsC\r\noc3H3TxhvcRorm/lV8QRIUvdIOddlKESi/WDbJEDv1j04JnpvaVvuY/rg+eQ\r\nOi7vU6Ca0uWaQLuFWvFqJ5APcCYhzdh6MsdOJq2rvWr3JYej/wyftVyIaIvf\r\ngvTFweoFg0VGebUDPyv3ciJTxIIQ3jWfrLM=\r\n=VODo\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.3.2_1669031628334_0.47568744706241883"},"_hasShrinkwrap":false},"0.3.3":{"name":"@sphereon/openid4vci-client","version":"0.3.3","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","main":"dist/main/index.js","types":"dist/main/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"scripts":{"build":"run-p build:*","build:main":"tsc -p tsconfig.build.json","clean":"rimraf dist coverage","watch":"tsc -w","fix":"run-s fix:*","fix:prettier":"prettier \"{lib,tests}/**/*.ts\" --write","fix:lint":"eslint . --ext .ts --fix","test":"run-s build test:*","test:lint":"eslint . --ext .ts","test:prettier":"prettier \"{lib,tests}/**/*.ts\" --list-different","test:cov":"jest --ci --coverage && codecov","uninstall":"rimraf dist coverage yarn.lock package-lock.json node_modules"},"engines":{"node":">=14"},"dependencies":{"@sphereon/ssi-types":"0.8.1-unstable.86","bs58":"^5.0.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^28.1.8","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","prettier":"^2.7.1","rimraf":"^3.0.2","ts-jest":"^29.0.3","ts-node":"^10.9.1","typescript":"4.6.4"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"licenseText":"                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [2022] [Sphereon B.V.]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n","_id":"@sphereon/openid4vci-client@0.3.3","dist":{"shasum":"da5c0d12d63ae9d9fb6b774bff467ef9f2143b68","integrity":"sha512-86BdzPSoPy/im1vBDXpXANtsbCxdKbxdl7Q3DbpxHQSaahXUxACT3kjYU81SI2qmFxYe0wUXfP/ZvBC6yTAKBg==","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.3.3.tgz","fileCount":51,"unpackedSize":196724,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICdrk1kp9eoLu/1axog0jrtWxq7KbfCi631FcUMuzAx+AiBOjtjEHze4TuvmPbccbR9TDbHBVltFYs7uKJ2HNaiQ9Q=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjf2EPACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpXhQ//fuvrmmJ2jfAVSHvz1HiPDjQZotqc6zyQjkuMf19Ih00pUykf\r\nxvlwmT99g3C7j+U9wtpZiDWgeuAUjSKvKc1sURSMuRgXk06LTpbnME/6tUny\r\nmmDjLm9HdUikeu5/GF7q46pPVV+NL51A0RBfkbbHN6qiOlLUzkdCCssQ+i/d\r\nd59H4Mpe0kQoj0Mw6Zfd4lRtn7KqYXuI9kDYrS98qrlK7IgdXnlUBfODtA03\r\n6vX/vrpmNmWgwX5Pk9qzxxmwk7NoU2IR0mZA8wut337A/4bP0GmJZSZCGsIw\r\nO+wRtlXlcZcSD+jQjxn3GL7Vp7pC89dWTWiZeevT8l4HgdHFR/kV/+2lil5r\r\n5Y6ah/uBvuIfIJrhkcDu2hWak+nk/T4HrEu5o/RV7iz5EMRxF/IHcIuTLt0S\r\nrqMxXjN/msQ6nf8aVSWR1fgKkNOwewkJ/VYsv+3cx7rtTM4NWcSzHDtVtqzD\r\nIj0mYp88N3Xig29KJlR85xC6pnhZRjxVS8TDY8NWfdCpK8xtOHddIz9F2t3J\r\njHP01kzVBESavCU4vT8ZJqrukk36u+cV4zVzO41rOQwqmvNzj2dgr+ExAuCT\r\nmNYwOAumZOw85rHu33td9wg+eob2JUZZHebAQPJtBWnKt9utEcsY8bqvkOI/\r\n903geur1saLnP7VWG8J8is5M0f8WbR7H4Ko=\r\n=ynXv\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.3.3_1669292303256_0.7956982363528038"},"_hasShrinkwrap":false},"0.3.4":{"name":"@sphereon/openid4vci-client","version":"0.3.4","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","main":"dist/main/index.js","types":"dist/main/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"scripts":{"build":"run-p build:*","build:main":"tsc -p tsconfig.build.json","clean":"rimraf dist coverage","watch":"tsc -w","fix":"run-s fix:*","fix:prettier":"prettier \"{lib,tests}/**/*.ts\" --write","fix:lint":"eslint . --ext .ts --fix","test":"run-s build test:*","test:lint":"eslint . --ext .ts","test:prettier":"prettier \"{lib,tests}/**/*.ts\" --list-different","test:cov":"jest --ci --coverage && codecov","uninstall":"rimraf dist coverage yarn.lock package-lock.json node_modules"},"engines":{"node":">=14"},"dependencies":{"@sphereon/ssi-types":"0.8.1-unstable.86","bs58":"^5.0.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^28.1.8","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","prettier":"^2.7.1","rimraf":"^3.0.2","ts-jest":"^29.0.3","ts-node":"^10.9.1","typescript":"4.6.4"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"licenseText":"                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [2022] [Sphereon B.V.]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n","_id":"@sphereon/openid4vci-client@0.3.4","dist":{"shasum":"b0a3b840fbfb853a6ee0db88c001a718ffdf79b6","integrity":"sha512-JzB2Ot+oGUkwn7ROJQ9AumayajDARKm4B+V+5mzfWzi1CIjvDeHWE1X9q4Gx8o/q9OvaFxXLZtapASqNv8msQw==","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.3.4.tgz","fileCount":51,"unpackedSize":197143,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDanJW/2lcCVdS/zuYjtt25mKhVj40NTEUgLskZz/xgqAIhALyo9xOrQ3XAhuht1ujgWTEJ3YqHkKw13HW6NwpHRRMc"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjf2a3ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqFzw/+MKtOgGTB4xXDA9pgta4a5XKx1WBPWjCwAOh0H74FoAUHsDHq\r\nMBwGSgSxQoWBav/xo/guPStnechIO7Flc3/1n/o6v5X2TB2U3pmBCYczYzMf\r\ncE6oL1G4eu4HMv+vDgpuyBPFtPuUTKTxUMokW6GPMfaRKY3ingLJsf2VO/gR\r\nwZ2H6lul/Cyuqbm+d6n7dg3+HmXfmPDk/ILkWhB9RRn7k8+YnsInkKpztcG0\r\nVV8t/1VHrsdNQP1ijPyRFVf9JKtJlmtgyqDcyCVzab89bp2wHDiwhlMseSdP\r\ntA6NB7d+3RdvsrQzE0LEwd5498suqn4z38tXoLtKtjMgUNFtTWTdwVLkrt1f\r\nsbnkRWJ8vFfiAK/YQIljY8h62D3ir5Viu1g1dBq5NApHo4LF1Auc6Yy1k7Pv\r\nebavNcOaFXy7kURHI6fvm7GPkqRjwEnPmhAhXF5hHvjBORasMJqVQqn5XV/Y\r\njX3ZcZQ5OOtTMURwD4Nz/+HX5Pkd4j9Y+9Qjix26Gfl4VDerFWa3xuZec8Es\r\narXm6F9z6tNLVyjmdbO09fpt4vvvhnSqIxU8oico6ASSP9UsFOYIwUnDiS3T\r\nRBZZ85s8kgUIVpfee5C+fMZjktCMlm10UFdJ6XngD2JagT2jz2n7h18mMOV/\r\njxhBMzybYCvXY448S9f1BueqAvWAvlMHySE=\r\n=ttVp\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.3.4_1669293750848_0.9175550250829168"},"_hasShrinkwrap":false},"0.3.5":{"name":"@sphereon/openid4vci-client","version":"0.3.5","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","main":"dist/main/index.js","types":"dist/main/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"scripts":{"build":"run-p build:*","build:main":"tsc -p tsconfig.build.json","clean":"rimraf dist coverage","watch":"tsc -w","fix":"run-s fix:*","fix:prettier":"prettier \"{lib,tests}/**/*.ts\" --write","fix:lint":"eslint . --ext .ts --fix","test":"run-s build test:*","test:lint":"eslint . --ext .ts","test:prettier":"prettier \"{lib,tests}/**/*.ts\" --list-different","test:cov":"jest --ci --coverage && codecov","uninstall":"rimraf dist coverage yarn.lock package-lock.json node_modules"},"engines":{"node":">=14"},"dependencies":{"cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@sphereon/ssi-types":"^0.8.1-unstable.135","@types/jest":"^28.1.8","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","prettier":"^2.7.1","rimraf":"^3.0.2","ts-jest":"^29.0.3","ts-node":"^10.9.1","typescript":"4.6.4"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"licenseText":"                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [2022] [Sphereon B.V.]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n","_id":"@sphereon/openid4vci-client@0.3.5","dist":{"shasum":"8a88e0311f19af271e1c068c2d048766fa4ed661","integrity":"sha512-qHG9N9C7Sk62L6ii0s9U6ub78/38zAYafTAtpdsT8ah/a/UqGErms6niYA6ptmQJwEDqWp6lK5zzbi/SqQcpqg==","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.3.5.tgz","fileCount":51,"unpackedSize":197094,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFc9+bPxiY2YnxM1AaGGaQmW56zqVjILPJtE2b0lE379AiB1YteR5l3+Hei+WO0GGLCI0RTN4iEnxHXPEdJz5ps3qg=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjvc+hACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmrdvg//fiXHSiY9J0uwNlLcLl198icKut7gNLE+ir6jXtN5aymTjJ5n\r\nWbudUlYlXwy5b3se8cRuy/j0s/aSBOIWtUYdLuY7vtOKeSllX7b/yVyoT24i\r\nmLJMWmJc2jA8SMYFmBCp1Ahj4Z/eH+/Rpg5zq6Pclu1qCLRS/xD0IwDofOLN\r\nFo2czVRBUZ6kGaJoMXjnSIWjF3N8xYcsUSfVGjAmKuemhmAGdPSbZBylCaCr\r\nUkxl3gGGJkTEBDAgId0ZEUjHJLO3r+M3e7ouxGWv/8BsisEpswMNYgRQoTy1\r\nAXYAmtToveJO7DxsYavSy5B1b0L28aE3LIwdoGWtBPIdJFvqoAFiUGSKDGhx\r\npKbmG1+H5/GC0pGHozdQHsuS/mVfVyBMw4LAQeeon7NGXdtQbyDovIz46wu0\r\nKH8wvfQnNEZhdBDxeiqOfLQj+2os3n3IlTt0npXjiP6IUZkr+/hGcKCoKjkp\r\nHpXWP4Cme/FjJku5wPHudneRZNLxBpt88oZ5yuIdge0tqdb1Gwg8koGHgxrb\r\nTTkL0K4ebuJi1UpPg1AobDCJk7lC3qXnubyBPWMICRK1ixnom2wPiM6SHKXt\r\nFb5vyVpjoNaRp/wmIrP2xkJ1/r0gmUj98vurSPN9grRuFnu0LMuoiVfaRnDi\r\n+H84x1NZWO2XW6pyczcx2tCEOnU4CPBYPww=\r\n=7NPw\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.3.5_1673383841114_0.4223336242596989"},"_hasShrinkwrap":false},"0.3.6":{"name":"@sphereon/openid4vci-client","version":"0.3.6","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","main":"dist/main/index.js","types":"dist/main/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"scripts":{"build":"run-p build:*","build:main":"tsc -p tsconfig.build.json","clean":"rimraf dist coverage","watch":"tsc -w","fix":"run-s fix:*","fix:prettier":"prettier \"{lib,tests}/**/*.ts\" --write","fix:lint":"eslint . --ext .ts --fix","test":"run-s build test:*","test:lint":"eslint . --ext .ts","test:prettier":"prettier \"{lib,tests}/**/*.ts\" --list-different","test:cov":"jest --ci --coverage && codecov","uninstall":"rimraf dist coverage yarn.lock package-lock.json node_modules"},"engines":{"node":">=14"},"dependencies":{"@sphereon/ssi-types":"^0.8.1-next.123","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^28.1.8","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","prettier":"^2.7.1","rimraf":"^3.0.2","ts-jest":"^29.0.3","ts-node":"^10.9.1","typescript":"4.6.4"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"licenseText":"                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [2022] [Sphereon B.V.]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n","_id":"@sphereon/openid4vci-client@0.3.6","dist":{"shasum":"70bd76bb888b458274007170e2bb7e784849cbbe","integrity":"sha512-C336F3VPMu1LSQAv1rn1KkXOVC3JxbrUzMzOBFlJfSKfnSxfqTqGSK0NTJLnAwGNOEAQ1M4Q/2KIXbDIaTU4Ww==","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.3.6.tgz","fileCount":51,"unpackedSize":198658,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFKod/3ZAa+4F2Sb1iAw2pmQUIp8oUVVJ+IW39DiAQWQAiA/BElQFbMn9vk+AhDes5ovPCQTVZ8UpW9BEzDImDrqJg=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjv1PuACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpeeA/+Lhcc6bTTHlHUsZ+fEIkJCo+1pKDB8tI0EL0TOBEFyhpfYEhy\r\nPkAgiooUtm3W57l1eokARJR7f2Jn5BYG2fgBkn+oKyqc89Xd+4Z5w1ElNV7H\r\ng6G3cRI/IWP77k5HRdE5KdovczS9UbiKDbZV0SkdVv3IBuOGRsb75u5m7OvU\r\n14pozY1XHQNT0rTf8N3b44SySKLCZI+foeDrBrngzqiStgyBMXDPIYcgcYkm\r\nHrdvdeB7us6lIoecMc4UrJOUQPeC1GOmQmolbhN2rDkxgPBtNFXaSlou09b1\r\niIbIQwvyQLb4J/Avzownajuy5iFMkUgbo3EKms06BQkzmp2QuvH79mAd9mpn\r\nJ+pr9gGFMAiM1st8ltti3IYywbPwQseqMCqhpOVU++JFSPIhZVMBqi9ESIVw\r\nWMTP+pUrZGP0goYsb2TkSQOrIGpqZbKhx9bFln8yQEaOT7xGfdA2FjwQDFJ1\r\n2RaBeefYqmZSGv9kRXtxKykF6fipCL5KeIKf9/Pb4EEbsugQgpKADN7xbdT6\r\n33nP/DTNSweqO3PJhEOjDauj1mTotVpJ8r7L/BqtP9r9UqT021PMaeB1Zk+9\r\nr2Yo8kEF7FWZ6l6FcL5ITbXsiu/rsyiZxB1EX6Vgn+FDS2XwGZ6zxCebvguk\r\n0+ciu9nT7Vt53sVRnER5np/a+e+QoDF5wJU=\r\n=+i0x\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.3.6_1673483246516_0.9145495194553548"},"_hasShrinkwrap":false},"0.4.0":{"name":"@sphereon/openid4vci-client","version":"0.4.0","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","main":"dist/main/index.js","types":"dist/main/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"scripts":{"build":"run-p build:*","build:main":"tsc -p tsconfig.build.json","clean":"rimraf dist coverage","watch":"tsc -w","fix":"run-s fix:*","fix:prettier":"prettier \"{lib,tests}/**/*.ts\" --write","fix:lint":"eslint . --ext .ts --fix","test":"run-s build test:*","test:lint":"eslint . --ext .ts","test:prettier":"prettier \"{lib,tests}/**/*.ts\" --list-different","test:cov":"jest --ci --coverage && codecov","uninstall":"rimraf dist coverage yarn.lock package-lock.json node_modules"},"engines":{"node":">=14"},"dependencies":{"@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^28.1.8","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","prettier":"^2.7.1","rimraf":"^3.0.2","ts-jest":"^29.0.3","ts-node":"^10.9.1","typescript":"4.6.4"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"licenseText":"                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [2022] [Sphereon B.V.]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n","_id":"@sphereon/openid4vci-client@0.4.0","dist":{"shasum":"f48c2bb42041b9eab13669de23ba917785c83b24","integrity":"sha512-N9ytyV3DHAjBjd67jMowmBMmD9/4Sxkehsrpd1I9Hxg5TO1K+puUPsPXj8Zh4heIWSzT5xBsGTSqXdF0LlrDwQ==","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.0.tgz","fileCount":51,"unpackedSize":206788,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDUhjD2+HnO9bk1pIDyVfjFLkd7IREWuAaZiYzOyZ52KQIgFO/Art+mkAcpGOF8ZQoPjqfofbWfaqlAGbuJDlQ6MHw="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkE7Y6ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoeGw//a98LL5ZsbPPqjnl3pDtxJyxvukUivUzcpRAaxbfwTPx2n7bK\r\nMZL6CleL9sl9pvI810tf76VztXR4cEpy7JpF0WCkQ/xFEuab7Zz6LkPCdnw0\r\nO7VyxImKUsg06hlObyN5cDX5NJ+kPh/2NnItkK3aNoarvqUroN2cLOg05lIW\r\niGD2krUVUhQ0TDMXT68Tm9fK5dSJd0+XGq/pBLvDqKmpt6vY8SDWFaSm+jo7\r\nMjAojtlcraJrEA+wjZ6GsQBJQYijb7A40xptwUQcKlENAd7VNEQHStn2i1ZJ\r\n38yp0q/u1djf8P+s74GHyxAKJbv7FUix/kQcVeohxXr1gHKCY0lnU30kGcJN\r\nfgomoLUDOj+JAVGLanTaETHAsNbjh+U37bnWR7KQBHGDvd00382JKQUJIZDf\r\ndo7wABUXTDiufbBBYPUtVCF8XPWpM1Jfezf2I3oRlgh/wo/2uFkoOWNmlINg\r\ngyIx/5G7mFsbQuQT6wuma9wuHHS7ZFTXPJ8IXPF5/2ShKuMQvM7Qicv7znqQ\r\nj6PKJvaPtB+don+3ZpyN/+K7QXABuxYdDN7WQvbcAXDF6z3/c0ZFbvO9IZMI\r\nmrE3l5VG9XPpFV0oGFeFCXVHt4EcVc1nXgzX1GpbwaRGZkX9kDrLouz/we7v\r\nMPuljwylm9arVUAsOOltL6IcFQmsdooKDnA=\r\n=KxJk\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.0_1679013434307_0.6387555106060319"},"_hasShrinkwrap":false},"0.4.1-unstable.30":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.30","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.30+7732fad","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"7732fadbf92da906887a0c3f53d082a1f2c894a7","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.30","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.5.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-/PAEEkMSxqZowokUwCgifCTmtgzIZY0K952yLbrBuNwHR4NpHNbe/rJf3Uk2q+RcJ4BMz7vbu1j32R24hQulmA==","shasum":"775e82eea65c4ba8ddd1e9af0393419517b05047","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.30.tgz","fileCount":75,"unpackedSize":275519,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC3vgh4q0/VHHYo2G0zhkBxD92roeNJebEHVPoxRSLVKgIgBTnnBif0E95NbSmQ4PtR01uUmBXqmg3ryF5lHakO7Lk="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkFjnjACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqdLg/8DrbcjnqTsDa0CftLLh6gjkP2Kj6xSZWKAQ/462mykj7XeSG/\r\nGT7sJIbVS28eR8pQhqSblNVeV+DK1Lliqv+g2o4ykHDyvY3hroXmDWDz5k+M\r\ne9vDGp2AL5w9W+wvkE9KXgVvUy86mtS45kBCUPaW/XYvzoBweKVtAszvLHaS\r\n9yP5nM8h9q4A5bXAqUtIUJuBAmg3esgozyKhbAkbrL5SMzUz/n8cSMkVLpys\r\nvfA9lV00tDH/+PolwFgDRm2xLJlsL1v/imbE0PIDgdL5aYdLicgk2ThjdZ1g\r\nfwGPwETPeqjuW4Ixxp0wxj3rXA6x463/v9H5gINWIZg0WHFTPkWKMW7D7iOF\r\nkzmxIKlP5yN2LnvDTwqa7nXg8tfIJm7AK7xVrTjfT5vdAyE3iEzfQg8gy27H\r\nFyfLjzkbtCQ9OdY1HRPwhgXp5WwuuYpFqukwSeta4u+/qW1aRKv5iJO39wWr\r\n/qXRb7WIiVIQXXQb8M3/5MMlYCbj/f/raghkklwxki+YvH/fPAi9YlRl77ag\r\ngONuSUSwhaCqHUTNiSNx5aEByCeXAm9ehcKG5vriu19Axb4P9To10+jfXuO6\r\n/h/NRtOuhCfEUmhQ0hgRR739KBa3GGwSK05e0Q1lL3y1C4bBQxCgsymtWCnj\r\n0lSLDHgv5MX8iYSzZFgvrEiHUyxzNu1ZaSU=\r\n=Bx6F\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.30_1679178211439_0.15456975028218678"},"_hasShrinkwrap":false},"0.4.1-next.31":{"name":"@sphereon/openid4vci-client","version":"0.4.1-next.31","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-next.31+500c7f0","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"500c7f04851c2567821d4189c8aebcde5bb6077f","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-next.31","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.5.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-wApWdyevlDt1qOURWIWTNgPbQEZNiuGDuc06vweSM3zgAIZfeZrAKrLYAq++SMZnt+x34bbhwzhcqjLe9WjJyw==","shasum":"f9c84252b36d8babf4ed780f0a60dbaad6b56822","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-next.31.tgz","fileCount":75,"unpackedSize":275511,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBvU4kJDRQreF8/iIBYcAXJq8ox8PAlIoRusbW4xsJO3AiABqPLhVsO7w2cBMA0QP/jfYXDWD3ikFGdBnXwhwzXuwg=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkFjxvACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmomDRAAhgBNy3dNZOhyUNvRaKW6urKIgKkQi0E4aw7U0sRg0Kp2f+rx\r\nDtYF4y8RaLSTcU8kmPK2+JwWhpOu98bNdp0zWo4boAHvV0rvarM3jSs3vv/7\r\nJGJADjDNLo0+bdUrRzzucrQ9OEyBz1BAVkXI6IPGgSW7QN13yaPtz1OKBqNe\r\nNxINAo9DG32ygdolybGaiRoLtfsfYsuQyV6FpgCq+jbI1qwje2JENoAwM6uF\r\nmVfYik93QCE+y+tonraMzugHhz2NmLTlf64D8jrVyDh9oAPPKzrHXsi06BBr\r\nYxyeNMVZrEJ0r4+8vccg/6wzccWWSdd4a42pSoWTcDUQF8+V89XrWhwA3zJZ\r\naqBZC4raXw/buy+eCtZxKg8sZT22sPYyYItK45vSedzt3QAglcI2C9dKgkSG\r\nziiTkH9yUt/L8W6X3gzTyI3sV+cll9xSRJ8FYI/S6v7ho788RMFlf9APt5gT\r\neLS06FczvrnyuQs31g9dfDeBkDFKPXpsYu1mT8A/46s2PwuH3YKEZJlLw6hN\r\nW7v/rrAWY9GWLWDQBi18kmUbQjylugZySI1UYu+ItsMZqJ0UOUUSwz9/A/4y\r\nJlb6zK5kSWIxbmY5G76MqVXo6/dbLcxZRQDkutkUdK49q51Dq3/q2/tSFo3Q\r\nowMHO+t5mjZ5HlR98j+4alt5NuJ9dGDoOUQ=\r\n=K23E\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-next.31_1679178863294_0.6448937352279562"},"_hasShrinkwrap":false},"0.4.1-unstable.50":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.50","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.50+f6be2e6","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=14"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"f6be2e6fdb43e4107f11d75f597588547fc188c1","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.50","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.5.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-PIY8CVxbH/f/IODkuOjV28HFhOqveOOca55xHM91tFmn/LArCIsEV3Ryxk6QVhhdkTaSoUtMGp3RfPKCSkC9nw==","shasum":"0987e2ea7bbaee2fa00a54a43404ab64031a1f3e","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.50.tgz","fileCount":75,"unpackedSize":275347,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCH0cTlcjAgbKKMs0j0DEY6ug0F/rzJMkgtYyx12n0atQIhAIuiMUnr8XpxzpaFxdpPSGml2u2t5Snpaa3NPzlBOte/"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkFkTzACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoQnw//VNKP22P1ZtCJD9LfqgMKPk/4jiMdDhWxHfav6cWAG6UIUo+n\r\nNmMDw0eDGtduYZPUXzw/whGROQpVYxVdh7Kh1VJITSPDHjobZ3DNjBC0l35m\r\nZXUGUIDZB6JKXWqgn80NdETENtu8S9WpTOL2Fd4FgvEWxuu20MwZxEBxMZOR\r\nMXse0IUMwXZW9sM3aU8n9Njq+1w4gr15XFchqMLA5fME6rXp4pWwmijcvnPM\r\nDNzebUnmHZOmCMzaD1JBBIdJx5dtBzpERuA9lfuzOfjrYLkrpque9CNIzf+1\r\n8tFZP+IzlGR4Jda06+WzGZoIhUBLVokpn140nqShHVKgB7S4uL4mrmlmH7n4\r\nn21zhTiFy+BkgU5CROHMMB/UZKywFLI3e6L3YA2UelmsbvCtP96fE48+XVaU\r\nh8lQFU2w87jSPsGQThuI12ux2PzBhyusB8ljTWYUZU+zYm4iLScZFR2gHpGu\r\nqpCO3BhAj9YTwJkqpZYzHcepIILI1Rioib76XGwN+TBGPJi+NbGNONoAHZlG\r\nN0qLxjmAyTfH5G8weeeiBY8jRXjbp25c2OSzpBTXOeFnvz3TKdPVII1orduv\r\n6I664b9mAqRpXsUn2ylZp+fDh3grYUvoZqD+YVVug9Kctzbyw+tQD7PW3Wek\r\n5uuNafuy5deirrSSmRCtfC2J+EAjbPHf6uc=\r\n=XyCM\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.50_1679181043662_0.7797796141280191"},"_hasShrinkwrap":false},"0.4.1-unstable.51":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.51","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.51+53990ed","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=14"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"53990ed8ba9a173482e8829b56dec26557d75beb","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.51","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.5.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-q6tN5it8f1r79BGmaFzCTODfGVlSAeLSvD0u71a6UbB4mvvctt9Au0Rnt9Imi/GbSA+IeXPhGW1fFphQFFZeoQ==","shasum":"37cd3f53bae963bf33e5c40f77538de67573933b","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.51.tgz","fileCount":75,"unpackedSize":275347,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCitrmHAcoqjd78PhSs2DT0JhuS1PuwnyBQGq4bHf7pWQIgVAWeDDN2ajLEJhjtj8muU9VO0fO7I57dZftEcKSKXdM="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkGBxMACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpMTRAAk2JVthzW5bel43XB6VqJIfKdZTokfM3by+v8X9CFCxkXEVfx\r\nr7LpnODE4rGCeMEc9M7NJGjz/JmEjVObMWS5YTli0XYvLINWh/PNilTnVc/a\r\n2JUxPrGpSJHriA8itZDCyp7jmc5Vhkuoyq2HmX4xsJmZlFc+7uvO585QJwnd\r\n+zsTz7+NbdmwPywJmnDfp2a76MToFDLCJcysO+AANn7BtbUBOVqDd7o6xFqI\r\nGkWOYEmA0jfgzPAhlvXDPmoCir12dayF9ER/mBgUytHffRxbEaqvrhWI9qjr\r\n7LcSu+fnwv3CSb313+egAHk3Lr2QKye06UL4Z2KBGPqYZGcEeKAxzRTshP1h\r\nEdFNo8NfGnP4EroWylGPabuD35YQIvQHkrNaNof5/B5m8WR45lUpcwXhqw7A\r\nHaO+QFhXA8pABaaPbVBTf5HIH9Af9UE/2euvRwyPjXnqnmTjJX34EulhR9Cv\r\nkNA4rMIK8vN2tyOmFeujGE9G08U6HfDG0SB1BngeSxizY5wJWcbwPCjbITcq\r\nY4nuxvUNd5LKA6GhTRGOPj1KbyWblT7BwUP9Dx9jcqEte6l9wAGk5Mo/aUoL\r\nyn+CpDAMtqBlV3v+iNuj2rwk7LYV53kArooQl3/GaTKoaNYivPpq9O9lNyf5\r\nVFHU1xi8m/W3xJoOh5if+9WO4sdwFDLn9dg=\r\n=8gpx\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.51_1679301708664_0.6281079738975861"},"_hasShrinkwrap":false},"0.4.1-unstable.54":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.54","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.54+98ceb32","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=14"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"98ceb325ccd7df623cbb4f84b47adfd3d0473d27","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.54","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.5.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-fEf6rfYYj0tTBZrH0PCmuOxFq1utrclx2zIayKsm/3MNaSlkbb/tRAxuJkpBSnzM5U3o+meNRzJXjFZTx0GCXA==","shasum":"41efaf0f3c87dd673d90f98142680dbb622c8f1c","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.54.tgz","fileCount":75,"unpackedSize":275347,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCMFNKoII/+6Px4iN8y70jjiMJJPI3/2Qey0i4bgsbm0gIgK/KDLd1zjYkWRwBIZmWVZNAmEp68Tnx8mCCXRCS9XUQ="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkGC5hACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqUVA//S5x0/I8ZFzcD5zVMfiDNqJMpWsC7gP4Ltz0m1+XhtTsfXosk\r\n6apVK9OAtK3dEDQHxkMkn+O4JH1p9dUSMCxYXgRIBab+rEE1MifW2j3nvU9v\r\nLtApwgLDlte959uR4pfLs4prrNefJ8XwsqPiniOOnFDFtheGunsF0ELznpF1\r\n98WI/KG1/10D3iFfVdUYSBhc+xSF8whPErnQDY0T7B310nd8KuEj96hPIwVN\r\nRS/NmqtzekqwUdBeMo7PFp8xYV4avsY2Q4pP4AO4c/yT55w1oZ9KP0vQmVwx\r\nzJzh9BZYC7vw1RcdeKoRBBNVjZKuPe5+lzVbXgdzDU/GmCgPvHDAX4ntpLnA\r\nhAHT0kFJgtdQankFhtK8tVk19Vu6csiGtGaCmcWA7o3I0GSH2ZdIn7nLA2O9\r\nlkONSd4IwDZKtwYHc6bJsfFeyvL2TMqR6nIung71uyJ/g4TRU4vYa9sXx69y\r\n3z/gKhnc6nGqm0hr8mlZiBoTKd8Q494jvlD/eqayQXyZWG4PGmIh9L2seK1b\r\naEdhcsWiVZaIAGh7wKwESKpNL++diZjiIowytz8fHi3yCiB4AE9svZlluLYi\r\nx/YFdfaekOOpUGzYVjK/mRgvvxkJm0Uu1WinxqaBV7JEr/zRu50gZQHKfN0R\r\ncZjscJZwxF8MSlTYVecehIrVUIzhC2sjsYU=\r\n=1GqO\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.54_1679306337277_0.07752099195961937"},"_hasShrinkwrap":false},"0.4.1-unstable.55":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.55","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.55+d240ef0","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=14"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"d240ef01fbc8d2383966cd9881180854c9c29741","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.55","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.5.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-BPu7HVZkbNHxvIqZrpWsp1XEsXGOjkRN6SZP/vzhXMTSQoy8h19Q+ymwngBwDebHP3QmNXgtF3l2ZGZiOfdA6A==","shasum":"d018b80c005f7c2d1c77096a33330bbacea26a28","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.55.tgz","fileCount":75,"unpackedSize":275367,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCXeU/1zLWSVH98yiTGWIJYC5uvFHbDZcnLXZbAfPw+tQIgPFZoRtNapqBIc9l8R0OgooH1fB1q8Mq71F8jUCnzV48="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkGGSlACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqvVBAAgA6XAWbo7KdULJESIpFwm0jE+TRwDAXjBzf539Zn8/8HCGIg\r\nHsqHF8hPsjBrtFFCnV7/lk+7qBlRWmNHhRVcYNxgsgsExtIEZw6Zyp1XGWOL\r\ngQRhHb4N6BDOVHp6QI+I0NZb3rSBjYQhvPx4ZBec/45tJulYSx8IquO2U5Jo\r\nPOw/9NwPNU4h3FqhgvS3q+zR/NtbqHxNaYMl2xoO9OdM0KlJ26QgCruM4fBC\r\n/aN+Q4aHYv6irgYLOmXGGfh6g+SboPQgzuUtu/OYvXes8asGUo2o3Je7M10H\r\nzj5npEoHTJzCeJTE16EgvNrhSXyoiHbgMqgCqYZM2a6dsEZRlLt2PRsFNDip\r\nPr14L9Ivfua/qPJayAtJr6QgyOnCsoQq4cbvas89yoBn+CBwtP8g3pPXOwhk\r\nwKjyv93shBnjO/1r81/v1ecQg6XNOtEi9c88gcoiejDvAn8ITT90TLQYkFG6\r\nOJUpaZJP7xujamRcjqI1u3vZHPcgd2MKpbmgSE8Dvvi9vy2o+LP0qg49QAfG\r\n3XxGWUja/BCaOQ0FzcezjDzWJFncKi59EmD6ORdIZv8U+G2KLk/Y6Q2PvWu5\r\n+W5Nd3aX/Ho5HsAIetGiR1CDOEPKZK4GsUCVIW9ZRmFCpQ0YGtYU9JzkChbC\r\nLQZyiqfjowMK19tgH7D5JT/RufHAQxAncx4=\r\n=Oh3S\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.55_1679320229584_0.2986516355109068"},"_hasShrinkwrap":false},"0.4.1-unstable.32":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.32","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.32+0543afa","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"0543afa8a0977bb54cf2c42f9e79b61cf307d2b0","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.32","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.5.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-KX2mJEe1caYU4BEMcuQhpsFfP/gBU+QUGjfIyn8VlLa++A186YY50z0caZXO1NsQCtxEdJYRH9pOQOPFXasIgw==","shasum":"d90248d333f4b629a79edf4bf80dcf1738bb2162","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.32.tgz","fileCount":75,"unpackedSize":283262,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFSLLd+tNafTmiHVNQ6fs4mIsv+NBOE3YgF4ahp3h6X2AiEAzcCmQFoBKcuBfvMCdGuVle9jSvS6ug6KtAg7CCbXlJs="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkGtlBACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmrdaw//eB6HxJahkZOmvPb25gMkNxIlTcx3QVsMfe/P56Lq8OrnF+AF\r\nlf6FTA4qw/vf+hh58NK3eNEfD+ldNxw+6cRsaIds5Y4Wf3x4lvtVrKFbgeUZ\r\ntXsR5Ajv74IZ/vQ+xktEnKLC/U3j4/Q5+D4IHjgJ72O/HdWq5R3IeKx+T4PE\r\n4rSuOO1xSWdVO169OeT7ObS+PmVePRLG3M84IibNKsY4rHk6ZaKgLf2usdoX\r\neiMAPoNDpYGQEl9vCOY2IKBn7UgaetEBNVGBUJ9adkwYelnhY70JuE45b8t0\r\nLGbAkwiXLSjtpZJ4yCuQzCIkmhCWVMWyIjRIFMJuHI3b2BaBGPkuR4q6pS0U\r\nCGAjauDmfIy29HsmGGxXi2byGi/fQ9aF7c/9gIBQ1R1qrVRkCoQ8SQH0HaYy\r\nYBoo2B7/q9a+wHlGia2YkXCwG/2BjcQxmwQpIaudClR6mHBEAjknc+M6mEug\r\nnuwC6vo1dexSuZhVkjYsyaqnlyXEmvwAyeQdbm5CzmPL2gbhJrjyTFgTN+hg\r\nFi2QN2rnu3dEteghYROC1qKqGcemAE80WnbwUTem4mPadYDLwSCTIdqlAXjw\r\nPalbv+tGEJBJibNc4MYyJMoE7bduR0qvpD/zmuI9eNg3roEFIFI8w9AnZmLz\r\nM0lI2KTIDO0RYxksYE8NDbZUqjeyfP29BLk=\r\n=SSEu\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.32_1679481153269_0.7542341789989031"},"_hasShrinkwrap":false},"0.4.1-unstable.58":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.58","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.58+380ae5f","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"380ae5f56264fd608eed16b39afccfbe8c6070bb","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.58","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.5.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-0cfpNQ8mijFK+YuV5rJ3flg7u0WKgB4LEus416vKM9w3KAv3bFlNOgMDcBOEtYIkMOLOgsC+Vu71HITeypm3Bw==","shasum":"216268895233dadb8712b785831fa3f22de3e135","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.58.tgz","fileCount":75,"unpackedSize":275367,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICupapWFwIfytuNhBs/VFie9HuMVjbVAgAbomlgrDPoPAiBMceN3fMXK1xKHbEdUKGubCJhjBJOZZXT1HeWlA8Tw1A=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkGvUZACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqTTw/7Bm4IAiqo3EnfeH5PUqjXk2vIUcSVvEtzhs2qGYmNnkBP2xYD\r\nCYtyhDtQZKe2IFYfONXLaRrXg3KZ3xpccXp3ssznVpb0XgeCcsDITEKrVOsq\r\njOEVAdg02F1UbB8tqG2eR5BxthjSmINHUReVVG5zHI4qYL/7vKLUiyjUjGM+\r\npkVvOwq5/ilow/iK+BIBrtLA5qfTbwxAWRQaQSpMNafc7SLDf38r4DRtEomg\r\neKoW2mlDUJ8ZR49G573IkuasywwzEwBH6dOgjJxirInPcXGxcd6R62d75I1l\r\nXctEXngKdau/bLD1dKYjA0CX7qzeJ+BWuxasJfFmCcgBSMoxk1v7HnBF+jdy\r\nMIqWHkuI7uH2LiAQ6OMo4r6si58V96vi7yg2J6G1zuAS87+pFDj7YIcTktqn\r\nBxyonrdyQXZPU2Cw9oKYPHCVchsrYK0mb6HwOKJvGDoN9LYEYHwqa86RzlSL\r\nx7LfTCmhOmJtrL6SF0uRXDyeYJtj68vtypmCsBDrLp/V2xNoNMksJ+YbAbn8\r\nhdEc4FBy4gRpGFrQxXnGvGxFRPg7RAuHBFpuYdVdmS6mVTYYYi4AmNPJtJ0E\r\nsKIuGXHaNPuqEFijEoHj+tPUd+prIVXVVpjh9Vl4v543xhP4rDXNsjCwd5xp\r\nPvstcndDd+ZvAZRKskGdfRweY97+AMGs25A=\r\n=LBVM\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.58_1679488280829_0.8143661807001297"},"_hasShrinkwrap":false},"0.4.1-unstable.59":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.59","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.59+063584c","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"063584c5508cab8681be374bfbdddda0bbf82464","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.59","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.5.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-0IhC5WM3lyc2SubvBHkwqiY2bSlJWpY1zJCVuaOvPiVEVTAOmPlMPee3ZHr69uDQwU/4S1OSx7Y6nZQisHw9YQ==","shasum":"fda67a1f1ec1c6fa1d898161573a81d3108342c7","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.59.tgz","fileCount":75,"unpackedSize":275367,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHml1BSLeJr+45t0/gCxMq/5J3jZTgsNa1lBI5I5YXYOAiAa0BggRaS8xPhMGQ9DfmTVZ+qdjILeOyEK+jeo2LB2zQ=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkGvVZACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoGBQ/8CXiq/ikq3bGRD8wnBaD9ceUBmG54LYtgJcIsHYndfGu9oSrC\r\nt33s65iJeDBTSDjreCO9PJ0d+4LSrcEr3xBgzOuRw+we2U/ghQui5Ip1+udV\r\nRZkt1b9FZJbP0iBDDdfQ++XNpClk+7gEuUhbQxXyyhHCggvPt5vnpYZ0bBXP\r\nDgyMrejYf5+QlBMlOy85PfkF3NkKnXuQXX7TrnsWhx8pUFvkuUz9Z4Klojkp\r\nxU7LgdJbwv0bjNGG4MfiETQD+hBfYOYmcMpKDhBcqcfTmlhWYp8EXqQRGZn6\r\nifbFa668g6u7gPpHnEtgPps818hduInn6nwyxsg5wCbFJkOj/8KU8SOXb2p/\r\nCHIhz6My8xwhCHzYtPIqfPcXhbjhCvW2svx2Vm5wwx24EHRVI0nfOjbvvZgd\r\n6hBr0YZncS3g5KSmULlYfjpgwPB9l5DL4qhWeV70LfytO6MxZr4r96tqFS0W\r\nDEbpHYKrztFTr7/6r45W8VrKfuWC9gcd5vzjnP+mjvclvB6Y8k38lgNb2BGE\r\nveh0lfiNCFYZSZJYGc6jlr1rvGb3JAftHnmluuT6f5Uy2UL7nFgvae1/qMxX\r\nD33RNlIGFLO3c/xCXYDgBdwKEqXbasPDIkCnUCVDaXVFhPsMjLzOvT7SRH+w\r\nP9lV2Y0nThgs6Ropl7FdonYpJ0IbOktoVWQ=\r\n=19Pc\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.59_1679488345655_0.8266555393416022"},"_hasShrinkwrap":false},"0.4.1-unstable.61":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.61","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.61+27e1854","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=14"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"27e1854687456c1b50bc4709d35f60b63f26eb34","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.61","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.5.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-iABEPMNZtOTIHC6gi6Ua8tbHIiYbtIHN9fkWHgmxC/GcngP/7xxOHPs+gN9jKxy0ckMCkJwTZfhaBtFH+KPLUg==","shasum":"08e890217e2205a88bd3183602509443ed1a571c","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.61.tgz","fileCount":95,"unpackedSize":293705,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDnq37vE1sCeJ+Fc6VLntThEYVRLFleF9xxJHE4i0+kkwIgXF5/pjn6feTomJOYLKUoOMscpduOdeonJ30FSWsrxwE="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkGvtYACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoOoA//SJkO1WYzdo1ndvqce2ytaPGkgIQYZKvjH44tvq6vU6ekVIw1\r\n5xZf8MC8qQDncJ+0k0Tik2loUdrvOgUMTEDwJP2UkLFWjFRwPW2T3AdS/HTL\r\nwiJAFQykjd19RW7xA4TxUTVqIXBpPDwXEeiUDeShiCjlZU48743FGc1ve3IM\r\nXcDhcNPMPPcLmnaV7lg5LSLncP1sYRUNtWa/nlDIM7T8+4fxXJgBhLrfy1oM\r\nBCcaArod8jHMFniM6F5BnTG/0SE9HBjy21qgWI6vbY2t3KYuGnOo1zdhRlcc\r\n97bej5Wsik6gSVGPfyDzml+NfSwFvvo9bZbhyyit/3CiKbSrrr4oHaNF6DlY\r\n9Dj5Pv9wrvhWloY4W/jR7yWlpY4EwEm4HEYM1qgAr+QMAfqhuRS+JD1c6w7b\r\nvgWFMjoU6vEVJ7mhfFBHo5HN+chd2WiHxCMrTzAo/aWKekGSK//nuqCfBlLg\r\nYso879iHc/ojNKo2621JPYejiJw29Dq0ubJievvLCFRg+QgCaY+U9Qf71Ib/\r\nixPvoYsZ9tfcrzc/EC3w1kk11CaoDhRn7O8EobV6w0LjwWhaMqh7ymzghg10\r\nISHn8JuaE9oRhW/XxkDLlk/uEAioW9QsMyz3OqcDCUdKuF59R+xwaD/+ddCE\r\nw03/PGG2gziOIvyhj05GD7tBo71t5kYfMzU=\r\n=/6H0\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.61_1679489879909_0.6349316461138537"},"_hasShrinkwrap":false},"0.4.1-unstable.33":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.33","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.33+5b65fc3","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"5b65fc34c74f4800f4ee7a52c01b53c048bc55ca","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.33","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.5.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-mh9FTRdiXfJN3q2e41pQyltudHrLh83d53524mA3X6deNm7AK9UU0+TPFZGh1ZSW73wUv3Vb6tjQC8pNiCahbA==","shasum":"88f353f4743be36165d16a0e6443bf193f9dc0bb","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.33.tgz","fileCount":81,"unpackedSize":289680,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHvV344ZLZB0N6BNpntZpDUGC93LG+0JbWBdMviRB1JEAiEAuCKYCL44QeSodfQqPjR3BIubVjsb/WWW7F+FtZKgXNs="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkGxg3ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrBtg/9G0PIP7Sl4jZ2hJ1rzAgMCuxT9/g9P+LtSPQptp3pQCl+3hxw\r\nNCVblj2Ru9KrmAx8dL45YkrCgl+A3mZ5xNxof7PzUhWn9pi5EusfVWI7M5XZ\r\nhuldH4GPdJUKDvxZA4WnQqHCNNo5wNuiNBiiONEVGLfIAvM+3uvxgwnLEAAS\r\nPqJwlm69q7VewQbrUa8kslxo8cBSs16inHy2eqgt+ktG1qoq3rKyPLKcV8Co\r\nPYxeI2wO5r5vqbISRt9LlyJGAncTnurhh0kKPVLGYDYpG2bJpKh1v8IWqoqN\r\n0gxRVxxM/osC5dV3tr5Tt06Ec3+7wRL8G82UMI9dVRC+R44rJdjOVloWvIB7\r\n9Vl9O5psSoHqxNsb2VxhdroplSLVZHpH/VkmArA8PaK+xPnpvwt6Nwl9Pj/8\r\n6CSxwUp6UDD0cb2K4wqhZEasa9ISfubvYDWbZRYPkCztan89dUBLuxmO+bsf\r\n7hNiHPtDfHBkgd0bBtljUjtG5yuk++52hlLmEsnX0cXCyiyX4nmeogu+MtRa\r\ndhf26ZqR7AD0bRunRZ6LHt59lxlnr1WuB0hKGHH2WXjz/8VrK1QlikgGdWf3\r\n+Y/Z8+AFBRLd6HEMANdilufTwyCDtu2BmdZHQq0p+0cj9Us8L7QNvBJGN4Xm\r\nYhvwtnchXIan1jaOYzBzRkxe+bvv8KbGWNA=\r\n=9mR3\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.33_1679497271312_0.18540971356013092"},"_hasShrinkwrap":false},"0.4.1-unstable.36":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.36","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.36+04907c1","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"04907c195213cf6816abb066cdb6b9540c59401c","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.36","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.5.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-ChrXygOrRGKmLoLA5R9Sh8uB+cXPco2DRBcD8rSzrn83QMo+Z96wcbfLdjtWlk2mAiBNOv/QVtFdEa4gZSF3cw==","shasum":"7034f483a76a8e9cf40853249406e03199239a5b","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.36.tgz","fileCount":81,"unpackedSize":291701,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC/Ahf3FjktbkKCfhXbsUL432TqqHfdt7HhmZr/26FGQwIhAJaCrqiSkLsDnyiLIzQHo+4/mTxJQss4ilTamSSpWJoL"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkHDPjACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqhEg/+M9GVhhSeYItlDNiejS5mB47tyLkJxE9MAS6uW/MZLVULBOP/\r\nAkOpJ9vYkppW6y0IgcyzkEsMZVrBfn/kbwGI9+04HmvfbAORXupgVFvLmKLx\r\nhCgF9wjlFNnTDzhpz4TRzKbEe8Jp5OpdIs7YFBHWBCgmQd17ixAOLXOJu5H6\r\nVKTNgr9+WEfxLIwcKWpr0afPat84p2yjmG+b4qDWA+li3KQLxgC27uySvHVj\r\nTp6q+AXLAB0Sd3QrfF0i8qcNeks4AzF5wRPGsz8NDsnQpxwkyb6KZYrC4p+7\r\nclr32gMfMJXfMGHApvQSup8GLsOlOip2GHAKn7GfezgbZWuz3HsOZSebARW9\r\ntST7mdNkCL0TzN03wb1T0CLLI0GN371cVxAB81/T6aVs0Tgrp7JFTeGFOoHq\r\nL5FYBQNnjuYKTVixmCtai1yhCQSI6ixChLu55+arMLM0Qqush7/Nxv4ump68\r\nQo2u0wkEeG6u/TTLQd2gd6/koT+aUJiETAmsdkNY+Yh/gEQsCHj/PIfk5LsZ\r\nzGc7dAEtID4H2ol64K3289uwPwPYc7wZ/lt+XjNCadfiHroIdqcmf3k6Q8/H\r\n45kd/ZEwaEOlY8hX9Qf2w8Na/NQPYPNW1WKw1jjqZz1Y9HPOrvBTb/ZsddCX\r\nSrnkBxjDE8pzEG/C/I0H8mnmwjp/8v5/PCg=\r\n=c9S8\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.36_1679569891432_0.5913364385316864"},"_hasShrinkwrap":false},"0.4.1-unstable.64":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.64","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.64+a84a329","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=14"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"a84a32962de8dca94627924bf9062893fd048fda","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiationClient.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiationClient } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiationClient.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.64","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.5.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-rMK9izFDpKELu3A5vlGPufGX970XFsAVUKJV+2AVAZRJsShJhCpgTpV8HEjebCYBO/GXBVx4/cq7o9EZr00D9w==","shasum":"a48b05284df14341a9fe1f87d48b7f7ae1a4b5d7","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.64.tgz","fileCount":90,"unpackedSize":300338,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDmRyCScIK6HZ8zE9TsAgYKwKkTH8Qk6OrZz7DmdPPpfgIhALDpRjf2EHnQw+enpp7057kYRh/HQ87mPcSRnX/w1o9g"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkHDUSACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmpa2RAAkT2jrKDDy/cHBeBEml+9HsshkLeLJmZwWGFFLNgO4jw8Omnm\r\nrHt/hJeRYjLkyEkRWL4teYK4sqeY8/XhMOZWG8/KbTBMySZSL3L45yjwFBvu\r\nE7VuBBapCzZITPFVWqUfeKVPTBeIWevPqo54vjS+QIjgCSVy1+HINNf8VWCl\r\nqni7/Bxp5Iz8XRUcsi0WE7ersxAAIG3wL54oPX9yM8wICZh5PlVUb7hRyONQ\r\nYCz4Vr3FC5YrzUYi01dd51SXyddAYeh4pr0AH9HYurtR7Is0FORkYTWNb616\r\nOM4Zrtvb/MmpUCqcDKEk8inwpbzfSP5ckt9HSOU+0KzyHAubp2/3d5akW12B\r\nqqGIJFTdL3zOIVumzff6UYIWI6mp6iiOcuyhF0+20i78uBIcXf75UhSJIYBd\r\nwiZbr5sDYLSOtYizDZKF6rT3he2ZqhbuRdDBKrvopYWF/cXqVDj5sPZy5Jxd\r\nL1kXQooxmQ+ZhqszBT3aQ3xUEio/9PKT79Ap2FiCTOtvi1JQj1o5JhqLJLPV\r\nTeCa/jVuJNevxnUvhsqU03XJ4EkdWek3coEQ2fvu3EZtyaKkMqt+DOZh5HuX\r\n7ixXE0/605jSH2SfPD6fHLeeIn8fIl2CgfWkuKC2DVA8FUczEBXA2zZCkEjj\r\nT6LckE+GgyMDrZB7pVQjbnai6zLhU/4ZiCo=\r\n=x0kv\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.64_1679570194340_0.12525631473641718"},"_hasShrinkwrap":false},"0.4.1-unstable.62":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.62","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.62+af01fe2","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"af01fe2350ab709d7a716ddb5666b4c1ba53a05c","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.62","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.5.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-u3aHneIAC4PGf408S5VnO3vDpL/kvTGIU4LEwWna9Nxe8swZ1rActzgDLTRAlq92+uZVysjEgihc0//Rz61qjQ==","shasum":"3260cddc3f4769d532a4822fbd2b0e89ee2d9165","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.62.tgz","fileCount":75,"unpackedSize":275367,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAn3PTqyctaXz/mpKVB/po1QFFUgns3QG05KgB3gO39JAiAD3iBgHpA2eD1sFBNwAe1U4vdcrHpI6yjtDt/WCqGkKg=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkHE3jACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmreCg/8Dnm2FNpcgF8UIuuijHoml0bhbmC0dTIWnHlMBbvzbmsmkdoT\r\ntZuFeSKVoTzKn2zs7xD4C96D+nTG15ueBnHxnb+Cxmh/6NagwBYvRIlVmopJ\r\nyyZt3AtqLrs6yrV2akc6vRKZkgu5NrJ1Ua5rWkmw8Q04pYqjy4qJnlN36JF8\r\nkigK2fct3FaG1G7/b7o0siBBa/kofUY3GTv1wipjETSrRW8NMN3b+JsZGKeu\r\nHJeCwChuoS1xFVgq5/gQ/pKbn1GrvZ7YIgVX07sy3Jqo1LDCkBahf1WUTHoS\r\nZH66Buu0ZdtUCutn7GbzwD/TayWBggrowa4b3c7tG83tfqlkz6MlGXyFSUHp\r\nnm47wx4keifjaV1OkeTiI9aWy2M9HgjWjWccqVL31burrlvcdT5Ni2vHNnOa\r\npQv6aJH22zKJBzX6BMxeywv/3ReUng947ru7VEeI+bsCAe5xU/noqnCqa0CV\r\nZcb2WalO5yfDtpKK9GpaNXoxwP4i/NYpuuEv895EzB1Pfzo55ItHhiVkvk/q\r\nFsLv2Tvskq0JlzlVet6Sh+MRDJzDEpJup1xDyhCluEU5Xvyt4dE2Wn07hzcF\r\nSIPMCu4q8KSh+yHQ/ILIiXNj060H7DJ8VF1DJDeeVkr/gVMWFFh3rIVlssZB\r\nK6TgunvpGlwZUnjSXDqCZZ26K6xj4GEBMdM=\r\n=EYwT\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.62_1679576546875_0.6005738294350753"},"_hasShrinkwrap":false},"0.4.1-unstable.63":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.63","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.63+256bb2c","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"256bb2cb65c55b6e03598bda745765858f26c5e7","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.63","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.5.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-oaMp6r3sgo3z94SIgAuMOHVsbnC6pvqLEjbvtjcLmVNQigH+qYOiGoALGG3uFmL7DSQEH8boBxunHtfBdAITqw==","shasum":"28a8f365d392bdacd932feab019b5d4d23866c26","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.63.tgz","fileCount":75,"unpackedSize":275367,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEJ1wa4sxcWR/3Rt7P+whz7hI8nm3lTb7i+zAczOW7T4AiEA/6AoybtbqWFKinNEdxW+oqjYwaqnrZWNtIQLmauD+tc="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkHE6NACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmo4rQ//dMmrnW/LniB6eomjatU/8hSdd6A+qSiwNHKqsaHMAsgbQEVT\r\nr1tLFejuQmUpTKdrc29ugxaMMxjQDC2xAInGXhr/KNruDSMSHNuT4IEiUpL6\r\nUEN/OsB8+uO0Q24La5gi2IrqKz9enjzu8xhgfeNyIil0P2xjIBDfmo5J9KK0\r\n3Pbznc1WWAbxdnB1FM5hoOxqvjT1VZG5verW/MvH7cDUhWVOhD4NOeKnJGow\r\n0weGlYDwkYhVkC7KI51rjYDPMUkK0aTT+ODX8UF0hxey90YLEt9qFs77Vu//\r\nqNQ97iLn9BvgW0cMw/+lmLYePffV728KjOIHyCuqSdC1MFU24uzLTYJQPpBF\r\nijbeTsjKETOEgSTKXNqbrpUQWVLUuHyZBCf25PTI5LcQ/gHCGQWhIowAae8V\r\ne9zFZNR/sQpxug5euj55ii4slN4AUUCwXmZjF9A4F1OXUxXLe4gMK38SG9dU\r\n3ddD6+SjYUvrZZxOpFzX2QXOpLPs9g0oFVqVtZj8zo/NqYFQ6uNkrDI8+9t+\r\noBCCidEAnXYdLxxK/gaaXzond8XkHdKBr+rI89Rb9PXoVQiMg81F1O9vdevH\r\n89fr65lJpVXmYvblNNjIle5WYEI85CWoc0/iOwPEUQNPdnNqDi/DgbuOY1yg\r\n8TE9ZLgMQSefLT/cIHidjoAs81oLUEuauWY=\r\n=F5eF\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.63_1679576717513_0.5008227318037985"},"_hasShrinkwrap":false},"0.4.1-unstable.67":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.67","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.67+15b9f10","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=14"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"15b9f100482d76953ef20846689db02ae44a6693","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiationClient.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiationClient } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiationClient.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.67","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.5.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-kkWzeK90qZxwtxHab0XXv9SX6JA8NNEJ/UFdrxJqixohQh48L6gW4rd1xUsEsLeb0/FgdmcvS5BFkM/wx3WMpw==","shasum":"cf85f6f3a27342824c0b492bc27843b85bda1d48","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.67.tgz","fileCount":96,"unpackedSize":309407,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDqajQrDQZoIfkDTzJkJaG/XCld86EWUpU+67dHzAT83AIgKDHCxjpWKNi+5A2N1SczxFYYvhNH4A/FMI3XotFCitI="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkHFsrACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrR4A/7BxYM3shUY9c+fPgMstc3+6UA1PbEVXr989KAyHo9hYjNARzU\r\nXVLRD3lJFeEfr92cwfOeS26utuyXoEjlIYRGa4zGdl490WdmxsHX61oMx80X\r\nBZ/w4pIGvhcPn+ShSHPq09mmfG1B0wcfWh7V8W2+AIC8yNGTSlyJh6DSbtG4\r\nrK31RP2M2Qx/xY84b/NrzTTUqFAoaqVnJvh0606SY6aMxVuOiiJi17+dB/gd\r\ng1TGRFSFF21K81sq5cX8AS6JE9rYIWn7PxrzCZijfnN1YOLu2uwW+Q2qaiy7\r\nEY+lnRyMRCaFlEPFIwYmqvnVyobf+e07MMR9JxAWKqmC/Zy/IyZeftP8asmO\r\nXDOri/a6UFnzDnGMQj7+aT8JY/m/ZfXZh4/GvH7mylT7RaD0Y3kyMQIhnGp3\r\nM40uq6kMKZ/8iU68z2HqD09Ks7jF81qcikElEaTVgsncFl/FlGmjAOTTeHEy\r\nsSWIwX7unuNCYeCpPzVdnrbvkYwoAbmay/1CIUbqeUKYAjH2jlYtALzTbSKW\r\n1d8Ah4PFfRhcDWQ/CnlYF23vz8TsjNfz4C6U3PLUoksm0suFchU624rdS8er\r\ntYWy7+zCPzA7OnLGFZBWsCZxBsSk1PlSnkfG+jntqs2aKt3V9045YucIEQ9p\r\nR5TMaWgtsXV1J4eFnd5C9UNO0HBddDGhbY8=\r\n=KbSj\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.67_1679579946854_0.8314287747011191"},"_hasShrinkwrap":false},"0.4.1-unstable.68":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.68","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.68+42e4b13","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=14"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"42e4b13ea09c20c5383844f760bd49be617efb77","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.68","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.5.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-/s49N0Gg6bqmnI1g9PYdBkgcHF4BtlK5OlGwr5lJmw4uwBKasGjwFw58UY79cXgjmdfE0Ox7xGriScXp7+H3Cg==","shasum":"08f4ad4d01da2a1cfd238a43a993ae1dad63393d","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.68.tgz","fileCount":96,"unpackedSize":309389,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDhsjQ5Wx7SoWDFCGPtDGDAexN4P3XR1a8GYVrmh82U+AIgeZVqdQZV4JDHt9IqxhhYdn3RTgEZhOy45R9RQSzhj08="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkHFuMACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmqr5g/+Onht9NXj909iaCohN8vr9vciBO8nXVTliGIbvBQBtPe8ezxX\r\nxsZhBKtLHFy2xHzl9Tmtt+rmugau4VLg4dRhIclILkSaqQKBNwaNoRkXjFAs\r\nT5fEbhFHnbEPjzYcn3E/kaG9aRMa5isTS8hzd52WWhLV0QWSgV54rbHxwhwH\r\nN7Ni53z5ZLX4AjR7hAuj+pKDTDS/S5oGJa5U5AzqWj8IrSKs8yaX4+BZL2tF\r\nqfNI92HRVaTLkTfgZ2vHQo6A4L4ELS4gPaei9WEtK1JAApOoTY5KrrcpkykV\r\nWQXjLF7xyQ5nhNmL4YAs3DgElHBiBMCIaLJo2BEXFXa6XvUYDCCANSMTfiqc\r\nFAhIBuoHP5p1w6ExlB6spm+/P26P+ofbA95WZNuRp+u3SifQtpz3mNviwqwC\r\nNQlRCZnEfMtyHc8RhBU4ViqC4LaRqlnYpxpNoUPNMRxSy4s8OkToBarNJCY4\r\nV4D8tLvdvnkhKLdR8DjCdjMR2qdOFIKflVucvjBf1HWc9CEGQymWgBvVftJj\r\na8tA+LD4YaOgMUFbWt3JXbVeqRsEL27OzQC4KdUC2mo2cZ3sAAIoC9nHt3i5\r\nwDg5dbxPIznpKkgrg8374LbSvFV+uKEsRR6e4s0jLQVDl+gHz04EqyqPp8Cb\r\na5Ka6iOxaW0XZJItmWMwcBp4p0uA1afCY7w=\r\n=vgfp\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.68_1679580044167_0.5239435224667104"},"_hasShrinkwrap":false},"0.4.1-unstable.69":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.69","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.69+7fbc8ac","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=14"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"7fbc8ac53aba6d69b890ff13a0c51e0cda1fb214","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.69","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.5.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-IxInfqY0UwmEGxTjrd7GLsJudIKti/fYlsOwr63EMvCS7TJ7L7rUk7B+jN5caDif0SOAKQh6TMoe+g1TPz9c3g==","shasum":"bfae81d617eb571726650e9adb682a2f4a378916","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.69.tgz","fileCount":96,"unpackedSize":309394,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIA9FD9/ry39sKKPmowEFyXsrLaXmhAD21Qa9G/effA9bAiEAqmeN+B0pCZeBcmWou9sPgOTcuEpQVpanBMfBBViwcl4="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkHFylACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrLIg/+J+VCkCXw3UqDdzytfpBYXyqBFVk1F0QTOXANL0Z1w2UCFORj\r\nb8zj68GciIwRYZnsE56IxCQj5RbHWQQznQ8zdOaAeH4GDGLKZt1bhZoLq5Yj\r\nLQhFuyKS96MoHocOU2inDCBSxmn8HZIb1dtFdykErUXB+Pgxu62gUQpBxukd\r\nQPoYfEZGV95LqZ+81qWf075HyYYBsBEyWLfXmAMW4SWTkeXgx9nvEpHPA94N\r\nuadNCOPwvfnc7ELO4FSYNBzYBCAxdJGW3R/Mc1ZWKH69/oKU7oV6JaUNGPOH\r\nV+lH3vRqCpEMMStM5Y+G5+KeF/Sr6u/ezNdg+oBXaFiWXTgJIk1jcRNo2tjP\r\nT40Q80si0nmXywI7WGPyxt2wO+Rq4Lv+NbhXlUpRXxQJ24haeN7vG16F/0PE\r\nwKAFvDew00DLP14HazovRLn0IGBhT2FhKcHtlrVYF80p7Gyf63PYyCPU1WZp\r\ncJfNYVIviWEH+YzhPYX3KWOXoFKATnM2d4T3WA2AUDlNDKtumQNMF6y5DRoJ\r\nKr+fGFdEDl5U54eAmHspQt5q8tdSD5upoUl8AN0VhPXr5qiqxmB0mE+a5kY4\r\nqg8pRjKvZrZgeo1QWeqDMtt8TbFVG1xn2qHcoOWNFfRTPzylehFLk5UpZApe\r\n5KLJ3AUDOeq/P+DMhwzm9rj61yeqLX4KPJQ=\r\n=K8PT\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.69_1679580325762_0.24538610229770041"},"_hasShrinkwrap":false},"0.4.1-unstable.37":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.37","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.37+076d6f3","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"076d6f34be0cf17d3970140f8d11d0058d0d2a51","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.37","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.5.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-d5lbguS7K1R5yj6WuleWunzmr8gIcyaTxmHCVDrZGl7Orbwq9G3J3oEH7GluRawyjaZ/4Ihwt69IpyxreZ08Tg==","shasum":"9e7ab0d13aedad4002d078b098d858de5c65ab06","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.37.tgz","fileCount":81,"unpackedSize":292568,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCqHnAM1Jdu9vpdumubk8Wazld791HLtF7XeB2+evt57QIhAKyzvj0xLRHqPW9RSZ+/djSJLMkpPEBwcTMuJsePWKSx"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkHHRkACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmoq9Q//eTBObWLzVIqlfnWRPoiaaA0Kl2jQ5PawKRmddPhQSmrcj8Rx\r\n9uLuzcO2zBFf6WICX/7rGkkgpcj1XzjEKUHgH2sXlKdQJNaxHkiITklI1Xho\r\noeIztXd//HpmnDT9l+fgDu6H7Z85ioqYPBZ+/KbWgY2FM6UI9Sof+yFz4kBl\r\nFF6CgDWfPaMzhXVXGPHpbuv7Qi7jhbcKyaIUhjgjQt7/o53b/rmfuI4Kihao\r\ncWtumRPzmmcnnA+BbyhTqsvj5uWvSaK4M9T5Yz+NaWbQ5xNiDges+eDH+VUy\r\nJBF46dXO7fvocFZD6xz4xJSgdCAWl6CbxkSwhMLcWzLcIKJTeablVSxHhU3N\r\nnOlW0zGvuvDYgcURJCd0sstMSzlAGT16vqY6hWXgXVsb6rhkbqixpfXFkeTW\r\n8nCCllueNfjghghsMGNpDjzKrrNUdvX0cPBE3hLlLh+8I17Ql8Xs+sKoRYz7\r\nGMt1u+ZKTWajBTOplNUnNQd3pH0HN+quI8cFlq8FkqaYTON7jj2+kU+CTJGV\r\nyiJi/yafu66w5BkH98VOccpWIZ2OLNnZLY+51FN0uSDnc1gPq1wFgGm7Nzs7\r\nGdSYHAaHUF7Fgp5apmIU4fFMzpP+JQ3s+lRaVzT6a9Vq8W8ZjS0HCKhpbCG9\r\nAehi8RFj+iA1WBIv37UBG8NzoQ55UssWKko=\r\n=NMY/\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.37_1679586404142_0.8787583659218359"},"_hasShrinkwrap":false},"0.4.1-unstable.41":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.41","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.41+7fdad92","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"7fdad928e82ac7182affb6e50910da7054f8094f","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.41","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.5.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-5DsBEDtlLM+XHGcJXYauwB3an5ZHHS/Y/Wrb+WRqHuCXImgMGIjt4rJTncAALWs3ZxhaTW9pN22RPZvffJ9O4Q==","shasum":"1df9abbaadf231461a41c34482e3ab1da31efa18","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.41.tgz","fileCount":81,"unpackedSize":293080,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCuEQkdbL14Sl2chyNAP37YPdM6gUPOash/1D15w0delQIhAKIXjovwpVzUY8NcQ+gQL8ui7wi/Hi4HptvVB5JZs5ym"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkIdARACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoJEQ/+MvbD+orfxFvUMH6IKR/UIg4tZF3hiGnPgYU2RNUv1wKBJCh3\r\ndxWgRfe1T8Wo71sflgaLSaLdabCJMH9/iAWItqB5KHqeZVIN0LVgrA/iwwGo\r\nZXV5gjfX5Yvn9fe6XUK4/Xc2fuuogKlR4zilRXoNgxjDUkOB0UmAS2rZdhHj\r\nBNFs+Zwi4Oj07BJggBSmL7lQ/geN9Yof/+ukVLJWj39c8dV58S+KCO/iah8k\r\nXTjNreiDKhEovbE7TRckxubRVnZIAHxkiXMJBlrkt3zCTNb35WRy3AoSjLee\r\nXbOy4dxB/zCzrhI8DXcKhPU6gLx6qwSibvxAO78u4wg0zi9pkcB3t99HdZLa\r\nCmdQMLhQ+rYy/OPVg17zdKicpMCGaLlbFoP4vORGiA0ROfn6IpoosIegcsq5\r\nyFQmQutVJrRUDjOK0iaAS+BLT105lgOEe1RvB61aW1+sDH4YGBw5VpwvTaiC\r\neeDsHvYbt1kZ0qcciJbVLPE6b1xxVIy9ybtspV3T9jhSv7QcgJIKsy6uQj5R\r\nP8tzIwCLTCf4ZrdNZihAlJZBK5rosdwGmTNizGdAS8BQ7x7byUIJmWSiiS/m\r\nqn5PwHF4MgTN2p96VWXEbXCxuJJ4GUxoul0/vsBhtkcr9wW+d88Pr/VyYIcH\r\nCTANznjK6ZxuGxUWmuhccOmpIwjuoWoG1lM=\r\n=ShUg\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.41_1679937552840_0.2281564695151057"},"_hasShrinkwrap":false},"0.4.1-unstable.70":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.70","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.70+ee990a0","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=14"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"ee990a06868695815a7ccfdbbe9a9d26f289637b","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.70","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.5.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-Re+oZdffpNEEYtZzAkDfS26ifmvnDU5A7QzRzys4pHYcV9XhfqZ32nOu6vPspZSe4s9jFwfr7KrxyX7FoQdcwA==","shasum":"18787a200d9d33c60c81ed1af36b9c3a7c791936","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.70.tgz","fileCount":96,"unpackedSize":309904,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHRUEASgbT9X2MtMnopq5E05p2FTJ5SlGW18pUPSS6CzAiBp8OEG4C9hyZu/ba2fDnxYvpvZau8UeuM7A4c+u8QHyQ=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkIqqFACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp+PQ//VDorgOFr6Bpa7FcIKRMEk0mWy19iNXzz0tC3NdUoMzWC5GLV\r\nVhK6z50tCenOLpIPaqqN7+f/1lSb7ZeLcizVxeG4XJqua//x5qb6jJpZLEa9\r\nJlNZLXf3coQJIPVRV8S9+LKFq0uvWyHIg2SzKQdHAxjPUGD36IPAPP3EAaCX\r\nlB/I3pSvKITRwSHAo5BBrA8CO1r0LLosUlDGNLEmTrATbpispmN5hUn4OAAe\r\nC/xAYnr5Bp5AthhWsLs9ZYbZDak6+9RQs3Itya+uP1OdP8XV9G6NeJE/n5rv\r\nU1rGdGnuKfzEYw2yuZUm7UqW4iNjZscphAUQVMuLGygJ8Zle3+v+UveTFwQk\r\ncspZkMhPgkXL/84HPtfSqcYH2vC1cEAmCaCVlqx6xmnrb9O+VKjJliZPt+4B\r\nl37ov/AVTEayQsXOwrJcdClFJT3CmJxpCLRwx4EPqhgrpp+Wcwa4ra7HtL+Q\r\nnyCa7mnPjUcchB44PI5pFdeQgN4DR3RWyrOErw+sHh67skvVY6ws4/5s97gC\r\nkeeVjNlMNYKu1scXkCU7rKfPM9L4Lq8sUrZqLe6ATdOeoJ+DS4CG0pwCV7hh\r\nti583v7NeldrOJ9kydNrSgCYP+YtikNOGfedn61vM4wyir6QRDjw8eEdsLmj\r\nmF8d9GWQfCLsz6SvYQWwvJJheT1ITd2GmIo=\r\n=OfC+\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.70_1679993477090_0.7035839583395025"},"_hasShrinkwrap":false},"0.4.1-unstable.71":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.71","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.71+4de8334","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=14"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"4de83349b60b49a04b5d1510d5925c82e36ccf99","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.71","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.5.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-mA7x6oKFQn5tXFNBUhd3hJE/YRBV5T37sd5s4FaYhrxRPMDDXeOd/ftoiH22aoLW7WnLSRputs88lyuYbypFUg==","shasum":"1f1fb3250dbd214914469db99dcf039f445d6ba8","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.71.tgz","fileCount":96,"unpackedSize":306842,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCsI0McugCROwRbHEzsEccbI8PXbAmbgooME62WdPuTggIhAL4rGUoZQE63XibgmaZuUFhW3glnlMlLcRe1OJqVghO2"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkIqrMACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpK0g/6AiEADu5dsfYhfe/HoaCzbUHM9RBIv8jEMa3V54HzBDo0Zv/0\r\n6dcc9pEi40AWLkW1Z2BYL2zD33k620EmWfW/QLGj9fFt4rXmGdG8P7vAeZxy\r\nZXhzxlUcljr65NefY8RgnyTsNKHHCh4ZegVf14ItNWxnrRfB9zW0ov7bRBCv\r\nL+f55rWv5E4+p90eKVh1S3b73ICZrE9g5hh0lFQ6b0W9W0V50Tha1nSee48O\r\n78H59AT8M6+895rkjBoWHave1Qw2cAAwkuPKJKFSo2ZRrYAYMRT/zfGBVBQN\r\nU+1K8+WRzQcx97+/ORuhIsN6SgvXyaf6/pWz6QO3VtpsM0a4v6lAca6qndnH\r\nTE1KmqIx02a9bguXNylEdwUAdYPk4GGdO/97D14X4lYjLu36NLKpcZMAzk5R\r\narHGDjkvJ4yiFSmUfW7S6neEc1Fd0NhlFqZRpwCq9adIn7HqyKSRONfaTnCL\r\nUcBerVRuNgV3qzggz119M+rBgVk1rqv7/xsnH811F6bhU1uVwCtP+fuoKCL+\r\ni+yi4MCGe1BOOy2KiYBqL/NNdu3AB/RMCHMkfk3up8az3IkLCq3dkY5tNWGy\r\nhlq30IrDQ4HEOFPNGuRsIUygOuWfrOtbHvMSknyUm+iLH96Y1qxZnYhilDJu\r\nZnhz2hR2wr9rDymvC4EXkv+Nd4PFQKUPH6I=\r\n=q3lt\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.71_1679993548459_0.6708763385550691"},"_hasShrinkwrap":false},"0.4.1-next.42":{"name":"@sphereon/openid4vci-client","version":"0.4.1-next.42","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-next.42+28d031f","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"28d031f6de4caf2e2abf04cd69fc04fa816bf06f","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-next.42","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.5.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-by2E4znUfjWTlXX2boh8ZT4Aa79PFv2T6lJvArrWKvLRzDmNvmk8IsYSCZvcRR+p4yvYx2RRgP0hJowRmQrzeg==","shasum":"dcf3f03c9877c7c2da01e9bc5a4dc25a70435e83","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-next.42.tgz","fileCount":81,"unpackedSize":293072,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCy2GCPD+rQBCYTeOI6atXGoMF+KIqocJLY1FRIcnx1+QIhAMoybEDKrKPzCrbm8knsZO+EtbC+Wj9+PWAHqISJuTD5"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkI3f3ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpgsRAAk33qb7pBHog1Ieu8As5Df/tl8Vkj6UM/88IOVirMNmhjm613\r\nzMuKKQiEjIFbADKlq3jTBDiaCjpiwZHgYEWv3bMS5KTphWjoxQ3z2i6dRg2n\r\n9XfMF18OQ47piDaXhvxL6wVa1ltZt9WSiHdEN8FK7lIsOW8DMPkAdc8HSGkC\r\nbil31I7ijiNnn3szy1GSWjWb3fXmxPIwlGj3GSiDWPcd/EkD63ZbpNx430Be\r\n45UMEKwrCKHdchRmcqMklrxaEowoXrMp4x72D9Y1Ynv8shA0EYwQkUSgxCsD\r\nc3UEti20djsRTUyXifmgav58fz5jsC+oK8Xkz8qBmoxpd+C0gj2kA5jPZvvt\r\nhZmvqfKNGIQb/mpZYb1ZVNP3EIcuow0wA1mFVZTFaOVY3TDlRUiLC0S/7eQ5\r\nzIbRzSIwgbV1yNc4YatGICldG1XgDTZp6Yl3rcM5LG29l/6MCrxTYEumgZc5\r\nOnQbYZZxStsCTy9MWXfxZARU8AsnPOUEC54gIasTBK2VLXvMZ4Ro4AOroK1V\r\nZWTD270tsJWL+WdykGHFz1YqGIbhtQWPB05/M8pgzJhmcRHym4JYc9ip30ex\r\nXJtmuTjZBfCdGKjZKxHmwGkoroZ5b9LXE45Wuz3AfuHw1FG4jrnzKlY6aa9h\r\nsxAKuapPR8IkkefN1ozDRWgSeKHzVqudPKU=\r\n=Hy29\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-next.42_1680046071189_0.18805097325172349"},"_hasShrinkwrap":false},"0.4.1-unstable.45":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.45","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.45+3f441bf","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"3f441bf187188169388506c69754ca94ac013078","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.45","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-fV/7ZucJrJnqsFaIeEgOnkTpB2mSgXiEAyG9SljxVtjFd0xI/684A0ClKdj40Yff6WgMsr18qvEBz97reCyMOg==","shasum":"0aa12ef5c8f827429da4168be7b0ee13bd6f3fb6","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.45.tgz","fileCount":146,"unpackedSize":352662,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCGL4bWsjuhcHvdXRaWbZmDQLlAjPYBjmkrYR5MQYVwzAIgcegIINeexE9hwknxpWaZyuerarXv+Te4tojBxWJQuY4="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkI/jKACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmpldw//cjWy4RHpNEpm+YzLd+494bA5pSKXcM0XHcCgJA2Zt5mr/KnQ\r\n39TeOXWWxUOW8vg6adtnF6DqjBAluchX799ewh5iLfp8tpbinVaBwWg6FYPl\r\nnPa44mAe6rr9c15by8wYQSPlxUCfR9d3MlrLYuoioGwDzARHFTau1hYKTh2C\r\nwckvMxI8x3/9FU7R4ME9PKXfFH3WNf7Zfnpm/sAiWw0023jijKlbhTL1gCwx\r\nH9Vi8zZkc191BSFIfOYFwB9442bortUWpM211MEyDmYb33hppXrEselkobBV\r\n6zYcLq9+am0OaC0h6qDNazACqS3VQi9c6haCoPbR/s+e9HwR3qekPwcROwNg\r\nxHqTuuMmbdBBne1Fd8hkNVDUOqOTubIJ579Kji10PgeAXl06E0ZxNytw5YlV\r\nWNf3eqK1m/d8xTCjC69NIKEyshwuNd7qrBs9ZS6SR0PS4ecX1vegEyKF7CoU\r\nLMSAq1PyfZjabmatgCmJDCsWZ8jztujzcCxlewRv0IofxmGkCzV17ykyoYOj\r\neinVGQIb2JGCCKEh+DesLX0cfiXdQNdRXVmJ3G+gGxg80Ns5NACb2yqT1hyb\r\n6HStVFCGNNF/mT8w3jpnKjjDV/MPJsH6uZKUvMyGuUIlSVtY070CO2XSEUXH\r\ndsv5PVCUEeAZK8FadOuflJrTpNwzd6aUyv4=\r\n=gYQ9\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.45_1680079050700_0.8716836809494133"},"_hasShrinkwrap":false},"0.4.1-unstable.46":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.46","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.46+199a69b","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"199a69b28ca572e20ed61e8f318472a663315026","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.46","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-EpVeJ5tGMP7Xa3k8LAClAXOrtQG+nIGxRb0mxJo977RNLQeI9u88egFKsJi1dzWsddpkQjQTKW5VaB5GJEfh1Q==","shasum":"1e2263b2e6d057fb69390662f36dbd58ee1f645d","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.46.tgz","fileCount":126,"unpackedSize":336745,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCzB/YNTS3IuRBwNyeF1siRpmNmoKADAYKYDz0XfQj2TgIgLR2F7kcB7Rea5YxN+b0cFb5QdnZCoQ4vUGigFev2aUk="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkJCFGACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmombw/+OlNBCHy40J0woroOY9BmxJG5luTsvvXvOtqOxQqRWpp9TjIO\r\nakUHy0Hd/RK+9bpb47x6VfXrPVsQT5ESZaxrAN9ERJYMAtWaCWqnLq0kP047\r\nUQ66WiD7mA2W3XdiGk7A/4nlZP8B3sLkLjwWC0GqMPWY5TIOzBUu6tHK22nS\r\nGViFUTHpKKuLd3NpEGPl7q3Y1iemR2k08oIqfuzKDl+4VwCETHEpmQp3wdCr\r\nHce8zdOl/19Qbg45Tj4dMTR20Fp8Qc7WFsF7YzRBwlA6wH1yHrUQ3A2tK9EP\r\n5bzjBZJVW6lwNgbcfpVztSzYExwD7jgr4E32i8+JhmwE5mG8gqDZXsT9EiP3\r\nth5KPygDjOsV3jOBpN9UK9PZCTfXfDTnFXaXDNROXQGtiZ/KgUQkGeZkfuIh\r\nQJDPp54O3w9j/RcoYisXk/LF5xg9dSX737/F7DzYiSCo5OslzFZLh0wUPoz7\r\njZ/fhb5VvPkvWu0Aqw4FT9YvwhnSXGr+0WUIKxr0g360afO1ZQRbIRQ5/SOO\r\nzdTI2JnVz/5L2R5zR0g34paOd+Z2VZ6qLXJNYfQaDM9Nz2g3hUlwGM7HUOdK\r\nqS71gmIuK0pOovpDAt3ZjXsYx5Wl0pQRbtwT42oxH+u6cwGdd7DKTnaCG5Rh\r\nfnh0RzB/dcy96zf9vKTked+vt6/Se8PhT98=\r\n=wWn0\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.46_1680089413878_0.32519531188421635"},"_hasShrinkwrap":false},"0.4.1-unstable.47":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.47","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.47+0235614","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"023561430093beae09dd162ac782b2b76a4d3cc9","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.47","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-U/c90kEcUAICd+6p5UpLYdptZiCGhgBVfW+PEE+5mFyfG5T7vDiTY+PCanUnxrWJfEyZcRwFg5B3oOMz4/0teg==","shasum":"4a68ba388e9af9a09647c28327cabadaf4deba26","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.47.tgz","fileCount":126,"unpackedSize":336736,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCgI4tVaoed6ZlDEX9i/+ShbioVtnfEPRwCs2/qsNBlOwIgE42aBmzlSCDvyPkFfd4pOmHOdTqAtjONbOuxGThiqT4="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkJCHOACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqSTA//YLzpsDiZIdapdK++c18uPmifzsOkckpfMyQbEH87LZp/QMps\r\nWRgeJ5vHOKO+DHnlNRZJ6V7Ge+0Bk04biDPgrPGNndgl59PqEfFSiC2mVEq/\r\n8012XQyLTIjjaGwGVTJZqrlq8XpEDmaJhsyV8TA7jA8KZ96bgDbUJqgqsJvN\r\nyMUM6DORdWvtm8nMjKGWLWjq5ChnSVM9jq0oLc6AjEcwzpN5uN71tGrFYrqg\r\nxQ0pmN/bHkDq2QtLNRIQIV6A1aVxpe4SNxmfd8mslFcIGShgkQZzHW8o3qSJ\r\n0R7WM+X/XKj2RRhpNaMLmZcTopg8ir0ZCgr65xaPttcvq9vzFLqSuGRvCASA\r\nsUZFQB4Nkf987s2w4ZqHxLAlKnQ22yiXLDVNOlbWfkL7K0CYQGwjZXQbb7e0\r\nA0vzsXpEc2ODFnmEs02LzVrxc3Z3faIHnM8cDAct0SgwcqwRnovx40h5j8a7\r\nX5JvV17JOvGtJAPfBTSncXIArC/ELN9JV2c30ya4opNHKLrFdTqOVqWRBNoo\r\ngz4yGmycYW5SUWBC/S5bGe+peR6Mt7JjIjs/m8LqVSGGt1IaNtTTxpqGUgDp\r\nsPamClnoS/Z8NJxjA3mALb4jl9f4/ihWAw6Z2x9/olVep4r5drNiMHCN5iVy\r\n71B2dexARbeLwZSXTiVG86tfJQZT8GJSG3g=\r\n=DOHC\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.47_1680089549900_0.25490597713393837"},"_hasShrinkwrap":false},"0.4.1-unstable.48":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.48","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.48+d6a6789","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"d6a6789ecc9b034e59cd981000b03fc248845487","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.48","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-n5DgIMbloMN6uty93tNtShWt27ldCwfpS/DVKLaQgpKhxqawg4IdB5wkXX6wM5biUdV1xLIsunhtpdsmjGUdWg==","shasum":"4394190f8ac79cea3a72eae33b328fcee55becc6","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.48.tgz","fileCount":132,"unpackedSize":343688,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCrWY9hpYWQ5pM76xqViQv12graD+avJ6xWyXHCFtL+vQIgRpzIDB9JibjG4eE6C+d0yky9qd/Fn5WtzyilpxflNm0="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkJCgHACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrAVQ//WdiXQjSH3GS+McTESHOssjjDbQ4HWeSWF/Kv5aDtSquBnPLd\r\nhA3zfERvAStYWneJY8ec3k31y4KfzUoK2lFVLEh5poExbuluHXC7hc1ZBHVq\r\noRX43lsMNiL8kKIO6wxFvmGojj+cfEOLCW6mXPJwZUyzi0EYUf24EO7sR+c6\r\nFwt1LTmw/8jODn/ofjOePdqJefLjM6fvYusg9QhjoTcCUEMSglbJGMkRYyI6\r\nGcdKYfUeFuiIOdjkljdupT455qjfm+ktL5d5yPxKBKn7NQwtNxcZdKyIomYc\r\nfnz15aOHPqtnjhgzLK4qOW2LaQ0hW4vYlEJVPH1j7d8pi/Uxqji1MP8KAqcU\r\nrtCtU3zZwQeSv6rHoDC+XHljtc74unCED7rnSipZh7dieQzbnwJ58u27uX5k\r\nSiyWhPojSlah4IWwHDnQT9N9G1CgNc4C3EnVNQY0KvE5pSqK76EHJGiJ9w8v\r\nXnspHALeZc7ZjcsHo/ogHDiLnsBrL5hqvonxRbrR7FjbQoQU8p/pHJa/f8zQ\r\ngmLExrstikWyP5CPVoy3OLXGdmJy5QCrua2jovF6+8xb0TI7KWx1Jm3Ff5D9\r\naTYIBb6EwO4uQuCBVJzfvB2eNngrEpPVTZs/gjw3TbdTp8gBjhLP/qdlJ0gr\r\n2nfZaTStrskQka/k05XUTKNbMKxQdS72AWo=\r\n=CVfY\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.48_1680091143075_0.8275452516647794"},"_hasShrinkwrap":false},"0.4.1-unstable.49":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.49","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.49+259ebd1","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"259ebd1ba8d582658ba913b5a4097799f3f0a78e","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.49","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-kNoVuMIAA8Z8QI2EdVHxmurcusqfWXEmFYYkzyHREqFZ6lAevs7p3GQhqvVPLdZAE/n1XvyfomMH2KmBlSn1RQ==","shasum":"e900a263f0fe80ea4781b20e80693ffc6d5b04d5","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.49.tgz","fileCount":117,"unpackedSize":335542,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIH6sgY0ywB3VmwwnwiKQIG73+JsRorhwrtqeuCf8jxAFAiEAxHu7NACefTD10dhkbtSNTEv1M0efGwmDlHZtgkwAF0Q="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkJEEbACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmqzhw//dWapeOzysUjZ7wpf56KJmLDrGV3qOIVRSY62dgVJ0/zaqYdr\r\n5WPpBHR0h7wZq9QYKgyOLCwX0tVMYUGrPJyE0KIQ1fJ64zunm0Z75hSpwW69\r\nXUsNPGQX1XwKLkRBY6yeUM2Xgp/YlNkB0wLkUoyq74KhYfRR895ocnAE5fRa\r\nUZ6QzNHgdXCxMsnyH6V2uHOQi2J4rB6puyoxVZ3BAO1Ykl2ShVoo5g9w+auw\r\nvPyfA8ixHfrHhaOb/rfJsWnpGSwxTSzKGzLumwtjR0wQfxMZvRYMY/oLXGZq\r\nyFVP53/TjIzUNYjJZkbawVasWce19AMk9dLG8s+w+HX1tyEPQXvcVLUxtPKg\r\nZknaSYaymayIxFrRzTcPZl0pJwF8aihS/nPICzG7yBYcLQU5nBlKNSJ3aur3\r\nVappypUDl07UBYxlMQ38etgAv5CcYzf20DN9kBnzFIMc+hSP+9+HkMv+33Kl\r\nyq7+S5nCMkc8iY8M48bO/fvTORSPa9Ry6MXKPH9ze0hO5I5E11B6qHpgFGDu\r\nne1hPHSOTExxyudVIiR5J0KmAmP9WRJ+deSKI5mNF2sLw9P/4ElGgyrVKDCJ\r\nhmGUYi822ooE6LM6HXsSgZfSDbEmtFbls8AMZ6pi1VzM2qmX3Z1wcGcM9vPT\r\nIikKFlKZlTiefZRmIOJH/EaKIVALEEVWtxE=\r\n=tQAW\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.49_1680097563754_0.9766349098655598"},"_hasShrinkwrap":false},"0.4.1-unstable.43":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.43","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.43+a2bfa5d","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"a2bfa5dc4be183112d7ec4597a03d0b02adee7fd","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingCredentialOffer({\n  credentialOffer: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOffer(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.43","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.5.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-eWSAi0+TzVg4fyJwIu6JRklc10iy59JCpS6yCYbApED0JnGxAyJuYn1z1RlOQ3iIg4QlW9HfPkS69dnlXqT6YQ==","shasum":"d14863b15cd0e93501117bc5421a538d591b88eb","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.43.tgz","fileCount":81,"unpackedSize":293747,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCHl6tFe7NzIWlhib5yMhDPdBMgA9x3qbXNNqcbRNwCLgIhALxwHLPXdSFjBCi4/eyyFrxzcmGGt0fTc+zGqFQfnhXX"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkJLGxACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrheQ//b3L8AUnDa6HxjmQLUtEHRPg/2x8Uoxso4cuUH+eJeFKxFvwu\r\nhc8+rKBf0rWRC9tX3VK6KIOJmgGkthqgQDiOmvKIbmUHO54ZIDOMrJqhABzq\r\nsvtvBwMjbe0Vq9CvVUMA2XTeQq6AZuq0lOhMFEHFSEfPcjm5zAIc0F7GH1Af\r\nKVNHNs2nR/hb98Fm6L9Tvq0LUP0TDRNA/9jpWNanyRVla1ArwVYj/6B+ULZe\r\nX+MACZD1zog23zG6YDHNVpNA1X+fIiL01iiL2YHdgFrXsVnhxPcx8gyRDGRr\r\nvKnqZFxPMVSe6Ha2+yoHBUVMCJpt449BGarqPgSZkkW/dWa6VGI9eaGOllpx\r\nPPi9aAgJCMBDp6Vj2dHYV+ZnJvD7Fy/wQdF4I/Yx6OhehJ+7r6QDr+ekhTvS\r\nPiMwEHnyg1P55xC//4I7EvSBwe1lDXj165I51DC/c3QASQPxY1wJMMKu3DO8\r\n2AI2c5eL2DrF6zZ7aA3s/VFlNj+eq6Xi+mmPn50lvkDs/0zBdF7ZfK86lmNN\r\nVDvIU6HMpUcKKDEbICAIKwmXpNe+I9nmXbGcsOINevVfSUoxP8cc/1isK1YM\r\nCx9mHpWmxJs8CMbd3ss8w5mHHFCQ/dJg9WBW65SuqpGLA4ceeEcok+JwyzeM\r\nQBOaY+Eb5Rs1UMfgKsQHCkbD29Tdsij54Zs=\r\n=lo6u\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.43_1680126384870_0.6523225181715593"},"_hasShrinkwrap":false},"0.4.1-unstable.44":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.44","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.44+7d11810","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"7d11810015e9b02eeaffd19c6d7fea2b81db67ed","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingCredentialOffer({\n  credentialOffer: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOffer(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.44","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.5.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-2RYfeSK+TqPLO+zHn/jFEIbjcUpI22P82mrE1TttqmYSpMVmOJXgQmA0vNoFqYqk5i6jzGf1Hh2M1fgeK412+g==","shasum":"035f65e80c4be18f89eaa668dbaf9d3c4b1566cc","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.44.tgz","fileCount":81,"unpackedSize":293782,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIA/WbaIFRUtfAMKdhdQA/1GAOo8yFK+ZOvVK7LMNVk0FAiAuUqvE7G7X5ykZKeDM8wGcPHN1umoLgTk9SGHWP18aPw=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkJLrJACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpAkA//S+nJARxEO1C9mmQlN3/aBc1/K0pNrb3CRe+h+7lCPpzeg5wC\r\ne4GYSE3sKoGgPBYMeEWw/WK5Ojjdgf6G+DO8V1qcpJkUS2Zfwp7KkBzEa0uC\r\nPETZe3O3YMJSrI2FZraJ+mDAtJ+A1BOolRgJZzR8le2rqN3R9Pr4t3Id0WRY\r\nFTloyxpX4VsmUnWK63V5X88mXVWODCWxSHNOAVfWzLHybOFwELr63rS3lZUy\r\nDgsaNACLIGAGBpZsBuPYdfQegdBo79ys2OPBoymi7JtvPvB5z1BS/QRt+kdq\r\nLI8BrI9LGVkJ9H5kRgWovhnTSZtmw/mu+kpnnW1H4qfCVsp2bXBUiDeWwh8O\r\no09oMizr6H0+C64E2YqYT/U/Bt39VAkFPDDWcV6QyQCFKN9xF51jnqXF6IKX\r\nF6lYI1SymOdMiMmA0SnttA5WzA653dRMf2471+kc5STkJqOOFoIuT983NWnL\r\nDi++0AU5a4z2LzbOlPeMLmLiNwOUdF7YDY1m/lTP/4HEKw4avHzrHPDhk4hL\r\nFa5Qh4HmXoOYnDXeB8XStXzbpLdFt1d+JKijUiTorbfRU+eyJMgT2CjL5EOr\r\nRIxbLXiMd+WP/pv0hMcKq968ZqzcboA21TaWiVj+wUt5c8OdjSjT1ObogDJ8\r\n/OLRxHzLXXRFqxTgTOwJUbo+K2ipXlsdqkM=\r\n=OiBG\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.44_1680128713606_0.5476641907362572"},"_hasShrinkwrap":false},"0.4.1-unstable.52":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.52","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.52+d9d3ccd","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"d9d3ccd26c2f627818b09b0628e0f5d5c817bb1b","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out of bound mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library. Also This library doesn't involve any functionalities of a VC Issuer\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.initiateFromURI({\n  issuanceInitiationURI:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `IssuanceInitiation.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `IssuanceInitiationRequest` JSON object\n\n```typescript\nimport { IssuanceInitiation } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = IssuanceInitiation.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"issuanceInitiationRequest\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    }\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromInitiation(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequest` payload.\nFor now you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingIssuanceInitiation({\n  issuanceInitiation: initiationRequestWithUrl,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromIssuanceInitiation(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.52","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-w1c8EZc8WXbha3ttl6f4/suAIgbBdqoa4FUYAMIV7f0GXh42DG3R7i9V5jJB8cdC0nPnAODWLWQwy1xlKJbifQ==","shasum":"69a9d52bc21a66dd988ed1ef05a02e054943eeae","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.52.tgz","fileCount":81,"unpackedSize":294499,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEDuZSbhWLudWewTWitx98fAU1LHRmPnOtNA0hFyelJHAiB/bXG4IaxWN0PkNr0QKjHNemKIaW4JDbUJ56HuZXGQJA=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkJWRtACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpMzQ//UB4ZHdRLSxhqWInnKDUXfbgMcPRZlx75MirjcMNv6lOObFpe\r\noT3Wrm/MDO3tBtz2N4fnHL35xn8b8vX7Hz6QGT4jw1AGqA/wouN8qw39/zIh\r\n9DkJsDA1jYMWiqN9vSP9ul7OM7rxzy/l9ezIXWNzKL3Dm7lI9DQZe1G12UHV\r\n/+T1Gxt/p2TYJJM3PZTmaISA3xf6KVJflGcUvBDSfmflg5vnl/X+eX2LZ+Hj\r\nI4AH/inKaDPd5YnZifegR+AWABnqIzofqr6EDHoJ/RZYC9LnaxpmeMC+/apR\r\nIQP0gj94GAVzoyEowTIuIzEpW5kI2tyNlgg/J3HIZWZCFPk022zNTau0Ml6S\r\ngYXn0Wl/2YWUNatZ3JRZCuAYZKtwwKBixgqf4Xo7Y31VYWpTo/f/6AOXuyU8\r\n0vqnqbLRHtdBioJ5S/kyvCHEXzxnO9z3rHSx4PMe5FNalUxGYKNN/5+4f+EL\r\nQlCkkYoeP2lrJci44hnQqFN3mMDV734u7rHW5WmwbbPOBlZabCzJaPl7xEiJ\r\nWOUBatEMbONfq6QWru03sarKP8lgqPm3mfbS5+ovFbmx8jYbWULR2C1gd4qh\r\n6cODrqc7zmsDCfXwtPUf0tATY5hBwKmMQHwMsboSk4+xARnbGUCd+aJucuvc\r\nIpSpsFZ8Ho14HZlVNxKFuPgzvuNGIUul1VU=\r\n=HkVV\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.52_1680172140883_0.8714143418663258"},"_hasShrinkwrap":false},"0.4.1-unstable.53":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.53","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.53+d8bf272","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"d8bf272568954391ab9555c12fd924aff0c40c58","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n  \nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion \n\n\n```typescript\nconst CREDENTIAL_OFFER_QR =\n    'openid-credential-offer://?' +\n    'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nlet openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_QR);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.53","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-gi+FSkTntZzF2815lC5C+HB/l2on6V8H3jtfwpWVODfyLaNPqcFFIWsiXXEcYT7r7uNrpZCJiO81vLHhAo/MTA==","shasum":"1b4436706a9ee6be616b07cc7dd35e94c695f042","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.53.tgz","fileCount":81,"unpackedSize":294747,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGjyF2q/TQ6ROP5bv1Exa5wpGRHyX50j+uxANFwjwPFCAiEA6dBa4Nuq3TPSM+5waTu1jHmSZxaQIYLH14clFeaqPAE="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkJXNSACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrHcRAApSMBFauCIaKw3jQIL0RYDqmIfYYCCoxkCxdgA7mpw/t5XJeK\r\n1e6n/tySNwy8elm5sLeE/ruseewazIfuKsqrIFLx+WCyf7FgLfpXGXwfA8iH\r\n7IVLYk+vBu4BinNJM8lqZ1203fKGEAg2NG4wfOMtOibnzpTMbpwGwqx6qnB6\r\no7grBDLeOm3IDIHDFG5afjvpyBWPGIXRQX5zVftgW8hQs5Xfww9pBJ4lnFm/\r\nMLmnfGBL8Vb42nqW4/GboFjVLjSIc8lNsiaPFgjCqak6mEpOt9tsfk2XThZ4\r\n0ocMpKWoynHBq9BDvMh9HwI4s12c6wZUyNjZh9L+CxPrHukH2m0afn0bsTEJ\r\n3hvEhQaheV9UsNcKJSqJPxl3OV3y9nyO9SA6bunjGQqmMwxVxULpiW/JlgH+\r\nFgs7AEtVC4jt1ajO1udgyd7jrt4qtpSLoB2wiqNxMTRwukxTO3vcYld47fi7\r\ngLZnfo0SsHZDApoyIvRiVMgi9hZfb1tk2sSwurZgn7InE1Z13ubD2C9jMLP+\r\n22SvidbfSK/XIKR1c5gch7hl3bFLaUaCB+rzUtZdV5X9eCivi1AP6iV0vQkE\r\n5Yya3jCYts0bF3otUpu3Fcy8bp5Jb609/pOGHsREiBhZ5/Oh7zeOsquuiE9t\r\nVLGpTWChhfZQ3IZmLIdW/xo/tbdBpy2Ba3g=\r\n=I825\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.53_1680175954152_0.7413533909374794"},"_hasShrinkwrap":false},"0.4.1-unstable.56":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.56","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.56+7b1dfe2","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"7b1dfe23b9baa00f41ffd6bcbcff568b7f5790cd","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n  \nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion \n\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n    'openid-credential-offer://?' +\n    'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.56","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-6fqcDND4nTKCzZVg7M74wk8+tz1UwpWDYJnQamtWMoztKv+taoSNjyateZS8fHmP8oB+rldFufMH3y8dV7e0kQ==","shasum":"e75211e078761695b736cd109176e61603106db1","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.56.tgz","fileCount":81,"unpackedSize":294751,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIC8MJhZQOg56dqeptbfDJHhJLM2sgeDb5JawbrS71fVJAiBrXAeH0+L1htPMPZci54JGWynF2dnLM63bJAc4Lg/YQA=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkJYUYACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoKsA//SJEXxYr1zKeEgh/8vi7mPIr2vOgQtpJpzqhhPvzCX3o/0L0b\r\nLY5+No8TH0RR4KCuOScxjNUoDgfL6UUVEO9afuvFq4wwlOAMEC61RpL8G1bf\r\ntKNURTAQndszLkFgDS99hf+UosCwgYJ1rA3c+2S5HkmR7J/J4dQh3PSpc7by\r\nBCX7PZjZv3YjswYpceR74xTYKfZK5CYs6b47+Y2YMa9NByZbvON4sWNfemxe\r\nETNqLNhtQiQL2gUxNSmhAVOi0SUjrSrBhggDvKW+MRdX56KcYPSNlEddwnze\r\nA2ECInMSJVy8hAWFu9KTuZKo8dQZN1D4sqU902uyaC+07U8ChuqhE11zh6Uo\r\nGzPXLMn1PWxXCeqBwVrsY8G/QqsDQHDJrtfkjmvCByiMTbZQilPP415dj1bJ\r\n8QckdbI54i8btUV9WoE8UXoc81ElbYrT+5mXd1KYGsCRNWWH4igSj6iZta3h\r\n91ivzfrtW3A0FieZ+1+iP09ArNbOe+PAoNthB6t3QUSqi3y+R2Y0UGsm8lL4\r\npJ8EBIj+ms5wyoCyChXwy1WLtWP7LL/UV0BLvMtDR/bGMoLvyNHs5SYH60O7\r\nwXpdmU9BQEScpTfPowtFU7EiXo/H3/isskFO/V3BJRKnu5Vs5aVncS4rSP73\r\ndz52kaN5zSdx6PV0dYjrkQZHeV1xU+ZDSd8=\r\n=AEyW\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.56_1680180503791_0.6420362962600095"},"_hasShrinkwrap":false},"0.4.1-unstable.57":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.57","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.57+6e9ca4d","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"6e9ca4d6a83b7b914f3e97ba40456ae0e44252c6","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n  \nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion \n\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n    'openid-credential-offer://?' +\n    'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.57","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-MW427HyJ0xAKe4hElyyWyqx7JvjDRBjNPeFpkMI6bGGa62HKPowwg5IDZFFFeF4UC1GZi4ZLet+bj89DeYlW0Q==","shasum":"f7ed528410165eada1e9657494d95b723827ff8a","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.57.tgz","fileCount":81,"unpackedSize":294584,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIC/hgRmGD9oQp1LFS7Yrnakz3dmOHHVWucqlCTStgMJ3AiBElZvo8+1FTZYSYqhZHA+9RQKryPbTP1Uj0pwv30YxRw=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkJYZNACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp6Yg/+OHB/Q7vpREApg/Wh6m7sZqJW62qD9zHckkT/LF+c/j3DHhoh\r\nTEhFHxV+ntYFR/a1qUEiuT/j1fmuR5EsZjQiHDkhU3hx4YqBt3HNo3ejinj4\r\nuLhQahEyM9eG9lxIjWorEF5NlM8FkOfq+G891Nk3L8V8v9nrpQarXIciI4og\r\nCb9A0ZDlhLFD6q21GQ06XU7UuoARy0YotD1T2KE8nLHoDjJw1htdMTnqCden\r\nIwAB8Vv0FxHzI6tC0ma5tIkf6VLvFyI9OTLwtYBNgjcXckKo1m0Kq8wgbqU9\r\nWSh7eEKQhv9EgigpX6kf7YoktspYU7XxdV1GVagERKXib7Tpm4O/ak86cL7P\r\nM38sfWcfmimlmIU0WmkV2OXMJ0ZFTAckoQDsji0QIhZjv57OZuHY76RWbsGX\r\nYUBWPj9NLNvb8f0HyPCX8D2NjOwbwO2UGYYfAj1Epob1VlOa+B7XNezsuLcc\r\nuY/mvA2ZdA2OO4zyOMC7JpsbTgP82UpSJnrMeIZvqmYhhUlCK88o/Rofawm9\r\nDXW6KbUKBhpDo2meZ5iRG10YtPmLUUOw9FDdt05pTUFVdx1JQo2Drlk7hI2F\r\njsXxhkEDW3pwz32E3kpah4BlP7qGFYpG8M6Pq1vtC6ig9DpUkhKamb5MQ4b7\r\nvrCWsxnvqUjD8CpI2nZYHgBlBy2+CTvEEiQ=\r\n=1LTr\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.57_1680180813169_0.43093482213752266"},"_hasShrinkwrap":false},"0.4.1-next.59":{"name":"@sphereon/openid4vci-client","version":"0.4.1-next.59","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-next.59+25d483f","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"25d483f2610cc99e12739692c4023dcfda2af9c8","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n  \nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion \n\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n    'openid-credential-offer://?' +\n    'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-next.59","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-3zOtH9YRNqLvEX4ycCytu/9ewcbCPSazny7NVSH44NcMgOyZxI9TrQtjdbM8dNDutDQan88XXsC9wDT520viDA==","shasum":"d1e951e7d9f9063f6b64b673c4d921f114ac1ffd","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-next.59.tgz","fileCount":81,"unpackedSize":294569,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICONJE9qxzqw6tdBH+VlS4dmC0UqqpaAzSl4Lq2PomAKAiEAw0Tc4xqgV/ARet9+2UDbtxYaRijiU17uTDU23qIieyg="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkJoe+ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq6HBAAnKnG76vxPEZjeN0MdglPJ3WoGwReQl3pFU84nPpUWa2ofAUO\r\nAHm75+sPxEH2NpMhsoUsVY2JQUONhypXCasGM5aBYOVKp0zAonjyTIVl6EqX\r\nRhC2JqOwHBzzvNIqhy4ShZDC9bjzEzzXUFBmqjPLWSKNrPFtref9eXQfiZMF\r\nWkgO/+kbhcjP20z/XVeIHyDXBKpiDrczQDZDe5e0aj+Veh0+LkxEoKeD3dpa\r\nzj4G/wZNt4ZD3lWZu9PUWPso5gv7dRuIzINjhuvlx4XNRfFpcjgcCnFhB5h4\r\nJCSqvtBS93Fvw7P5fSm9ZCXKOiaRafkBnL+y3304x7RbEINZIrCOFvoKtKui\r\n8NzZv/3wP2VhmyimsDw4BwZ7stkbX+XDFF9NG5eh3cPz+Qk3tm4FrLBoBPPp\r\nZ/Fetl785WJhwq+ULYBh9GDqtqRltFGzeYoHvX4vwVRwCdAbgTQXbcZbCklI\r\nN7mhisr74LDZuNwv4mIKYX5Q+zXjU7UA947hghI4jt+HdROC1k/xTwCYel04\r\nGW8YP5mSnMxkq8KKkNVtlF6rMYd07dEIlqmYJivrZ0QHCTaryJFgh+DXXW8s\r\nvsC5R1qJ/jJ122u+OYrpwHr40Q5xT5XSo0isf4pUYn60Z0JO1gxunSSl0gBC\r\n0hXePNEsJJY/JwtI0Oxp2aY7Yyp4YBPnkVE=\r\n=C3/f\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-next.59_1680246718267_0.2795070200690304"},"_hasShrinkwrap":false},"0.4.1-next.71":{"name":"@sphereon/openid4vci-client","version":"0.4.1-next.71","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-next.71+76536ac","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"76536ac0be73408fd85ef812e6576f4667cdade1","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n  \nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion \n\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n    'openid-credential-offer://?' +\n    'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-next.71","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-exXiLxos/LieL1PCz1pusF6CNuYthahlh0VIY701g4fFbE3bWuCE1CUGensSsIbLTEcKjjjo0+0icJ08ZOXL5w==","shasum":"fc1719bbdaad1743f9c853581d09710e5912f351","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-next.71.tgz","fileCount":81,"unpackedSize":294581,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDCfMOyF3Hy7SdE8dlMhP/Vb30obpZe4jWqeI3uQqjyZQIgbARCXkLsvKlhzFWnZ8HDYR0Rj6NvhkuInuCAOmDF/vc="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkJqmlACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqpXw/9EG+OJiC8UzYZFUtdmhMK0Rdf87sx0LuwhuDBKwsym3Ul88dp\r\nfM70jJjU9SCC6F8YriNKSxVV+5kfDVrh47dthsLpVPekqdRPOwCkMGMv3tN4\r\ngzrXyKiJBFTGffO9xecGkUIkD0DrFBM+o5KbuadSk4JDSvB50HfnNNxg6ug4\r\n4N3YdCa6+7jivkV/Lp9R56Dn7dkjCPvtoydPlaZTok1qKAo3ajfacfgebkUo\r\nUVvrgZXNbCC9c3ffBe+WinmwCqYcIgbzyGzJz7lofQRDGW3OeWc1ys45zvxl\r\nCXRuRrBjbxI9N2DShy+ZANapyU789gmSWrs0bnHUr+yhky4wCqas83FjzYaN\r\nTFh3S39RaJ1EkarE3vibGCPBfgVluLxV8raN1BlcRqeEPRyAO3YSgymxIvuV\r\nRvcwPi0NVHNchF46J1qWJER1lepyBMj3qRvmPiwQ2ZjornxImZtmsH3q0UqY\r\ni8XAyKp0OR7ZtNR9w6apIbfKFOXGR4L8jxg4ZL5L/5n4xKchKOt8V5VeowLD\r\nZyrrwGmcLvVXoN9l1jn3GtYDj6c9U95YOPuYbtPf6tdvfFziJMoRIK/nVsrF\r\n6QrOVksLnP4ggyZktMrmPwEVIyX9gdilZJ6QxPstoAhNztQViG5P2MPoVstd\r\nwlL/JZOSErANJ7kkRJdvFnZm5VairD+1iAk=\r\n=6JsO\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-next.71_1680255397603_0.14932214134603128"},"_hasShrinkwrap":false},"0.4.1-unstable.73":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.73","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.73+d0b2ff5","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"d0b2ff53cd36149416c8c41bb3d75552b7631184","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.73","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-So2MzzjHQwlzCa4O5cqnb7s6fnYT0zpRc3oJkCx1PGyuGIzp3VnfOH7nDsfUSlio3C4aYHye3FugKb4nCe78gQ==","shasum":"e74506af9a750648baf2cc616c9dc8d8d6ab4684","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.73.tgz","fileCount":81,"unpackedSize":294508,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDwp3LGYX3Fjj23O+d68ci1GTozspLCLKBQXFwVl8zxcAIhAL9vTIfjtkSlY5+YXZZNfvOjDlyaG4Ooz+6mOENaaF0d"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkJvirACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqzBQ//TWdCl0vmyXBUxUZxSovvpSiAJSxHMjxVm/B6coKqbVmtg+jE\r\nMzOKMQREvVB3mpD0I2xCNEMBbmZTpM/vxxBwzZWDrgaxz24kZR1GHnyL4ewX\r\nJW8l7fDSIlZ/xYtSUZVGFIrY6yYfOVGid9zeYpXxnMxiIAJZzS4yto+tqXH2\r\nq9Nz9jxZk9JFPtrz5KJp681mHLulj1rFpP3pxjjjNfkPlWdJIHTgHMli8AJj\r\ngMeEjzdrtYlBTN2dVU1WEnpbX9dnbxbNudcaGht2vLt54zqs0eL+imAASrhw\r\nWhpMz+yEoYzE59qKr45214HlD84q91U24Kuf8SK8qwFbVB0/JCTlRluXKBE6\r\nTTJ9uBxieb+qXQACKenIpsE4g0XDGhvkHdmD7QdNDbMranLDFoMxshD0b0eN\r\nzdRMZ4/C4Gwmb2QhOSeBJRqxUN36yRKE2X3n7XzHuebbNAnhTY+Mqiyx02k1\r\n7mXoVSSK0inmr0YeKEaK3YDqi1Gw/UQHVQgsNDZ6y11xKjRSyJqOdKuxysCl\r\n+6JxczeSowcwt2x2qfgRBzQmM6HWDgNSlLpW3asOuTbabNQkeifVnL1/clln\r\nE7vYzZDmeMYXOeI/wg8Ej4qT0L+rT35qoLmIDlEvFjKuWr0Ap3ShpN5v1UwN\r\n1XPtgzlw1v/rHI/QqQD7RM9PoBI3gk82xnA=\r\n=tF10\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.73_1680275627148_0.6877495369746298"},"_hasShrinkwrap":false},"0.4.1-unstable.74":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.74","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.74+add6ed4","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"add6ed4a5252ac8a5b7f292e15161694be5997e2","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.74","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-VbcGUmUnY5wOX1R6OvK9aP08eaV5/0ylTw1T2bZeJ/ITVAAqHwvsSUWJHzYZHrR6xXJRQ3TSbaHpiCiCBhvR8w==","shasum":"96a8f7a4e4c6d019291b1e2e104ce72e1b7210c6","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.74.tgz","fileCount":81,"unpackedSize":294508,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCu2ExcfjdnKrHcGKXfr3R2vOWle2FXSGzJXF88e2GKoQIgDiSmdKfaxGxQwh/gqz3S+KZhlDcfyejNW/QTnYS1lLs="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkKp3RACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpNuQ//fEwSI4uMA3LIuZE/lO1aJyRInBxksNt/xtHzlIeIz6juE1ed\r\nVfIAMtzNKa6wZ0QF7dL7QZs0xrYNr04IaQJRtCVFlOmM8gZsMlmsBS2c8PYm\r\nevu6JWVqQw849uEcu/YmCiRaZ6/qerHRaBSlGKwDHVobGdglcdPTNMkP6EAT\r\nVZrlgMA7yp3yBZrSnyUiSRWm4gKZdnQsn2ErCeGRViS0yorysXD8CQWoz8sD\r\nj8PkbZT4t7cfMQQt7izpXKB8iiaNtcdtl3RcOFvS5mT+1p8+5iXowo46JLkw\r\nwpi7TYfAGAmf4XJNrAc3DnTZ9JgacED7Sm28/SXCTlTn7oKuEIWZnl5B9seT\r\nr9vERdKa4Ycrm3tEexYyNvO2t3yWaO7nP6SQV/z6dSFCT/ZZ57ms51+8QJbN\r\nkYB2SQyizYlh+6ToJTDcfh07rAE41htKn1U6D8UL41Xa7Wj9//yPTUKH9ush\r\nNzeYzFM7BxuENjc58m7dcmnB/S7TbaWJTaPa/5ESdPdIQOcZvKzt+oiKlGKY\r\njnTNSY3daCRMYeYwrb0tM0BhzkFCUTEaKy5EiMI98LFDzo99WrXiZB2LwFaj\r\nDwi6jdpMKsOttMX4IZGPWBiIo9RLi3OnhVq1kneQSayHIqwkzUapaDrHhykH\r\nFLjXiCdAhxzYtW4dG4WhYg2nbTooL3/C9lA=\r\n=lCr1\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.74_1680514513479_0.6018894511341055"},"_hasShrinkwrap":false},"0.4.1-unstable.84":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.84","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.84+bd11cf8","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"bd11cf8abc2f064ab2c1f74dc56f3dad4ee4f7bf","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.84","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-1UwKyuKrW/j8v6m/PmgnLS8rglx7tTiSChDAajy3vI+D5EaLa6cr5+8+kobONvSFPRET70NHzWMkIik9vWFThg==","shasum":"5ab7edb7b7c42cffd4ee8d9f50a90a04da6ae974","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.84.tgz","fileCount":82,"unpackedSize":304251,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDtqCPIuN6Q7vXp4J9u6iAT9iabxOjXSkc1CZmYyVtAygIgLpHv5DBtxMZp41N79hUvcK9wEiYSOFUd/GYNXE6tAgY="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkKrZxACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmr8oRAAhpsvckPRfiwc8zFG3CscSXVBy/EWXcT7V0YQOKrC+ACSJb+9\r\nr/ryG/IxzYPy1WBzaJUkAJ5zHWoX+9AXEsodNxRR/2J8wHiLdqWj3uWkM3l7\r\nyb5z/BdVB7DDQvh7G8/FoTVzY8kKt/DsqNS9E806F4tP/uyI7lwPrv3FFIwC\r\npUXB4jRA6/aMHwItnrmUJtaOkAULJOwm55zi91OjWhvM7ri1Pkw3+Tyrn5T2\r\nWU7Yi0JybQcYuuMlNDNdVxwcMybQ8j9PEb1SOgKsIhkz5qutkA//x1XVGY6Q\r\nf7kc8HI/b8tlt5f7GZ/i11C5v/0Ulc+G2MMmCgRR1PdTCOka4e4lAxY7CsjM\r\nz+bBtzjDwSYJDEqg6JNiLwAjDucodC5jNdL9nc+cfcCW2xv/G35aGP1pUpV6\r\n13seeOzA7U2Rl7OB1Utyf6pB+TJ9+CbDCMb0j/bJyyASeQtxKNtXhIAIe9NA\r\n4uidQsTwgFWZ01deoHi2pe+aYk2oAc9K0cCudlgmgwKiMkyzpmig2uCyxZti\r\nwJBrv3U5KJSXSCc703zN0zNkZgIYj7nxQHNDguwluZNQPTqtb3E0sos02qaW\r\n2TaCaoj3UJ72Kko+InaMqKIQOK3j2LPI0500awXHRMlTmcy5qb/PNTZdFAjK\r\nIlEqkCFo2V75ssusIqPQJen9NXxXPGicgrs=\r\n=uiwp\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.84_1680520817273_0.7182822265034292"},"_hasShrinkwrap":false},"0.4.1-unstable.72":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.72","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.72+c2592a8","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"c2592a8846061c5791050a76e522f50e21f617de","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n  \nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion \n\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n    'openid-credential-offer://?' +\n    'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.72","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-2zkgCjfJnHhWikxYWDFx5LXHitKk4UMe79jViwwOFVGdx8NrLZwgZMnp+ZP843HH4rV2NN1w+huaToYp0fnovQ==","shasum":"f49737cf5ead092fa7820c68059df4ca55c4d42d","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.72.tgz","fileCount":81,"unpackedSize":294611,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBS5imxFz46Ekhr13OJqasL5uBFUHYQVZ/MyusKhE9D+AiEA0LAYmw8MBAuzoqtwZF2x21N0JCt2ozq3kVKF8BPFVIY="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkKrebACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoGsg//TDr2MsIkBi55SdqENCq4h1RmsoUOKCy/IG6lvuq7SJQmXfop\r\nPxMFkd18t06iO93H4Y+LJRyoSfIHIEZd10btaoNXtDTmxemg2mpr10UdBzOy\r\nWcNrHb0tmDV/NHPKcIzZMK2E8qszXMqzknwFWXSX6YexLPdiYcVoSJMB1LdF\r\nGTIiDvqTuWcxbJtwnMBppwmZZGKWgocjyXy1sXsFyug1C2qtrQsJqQ2VVLRj\r\nTSQRDhxsG7wCwgpGVnQyUSIqCPSdVyUU5YbZzDvrizI/qed80gKHianPGmxd\r\nShMqtkN0MQJVPV3BfHqkc4i99Ty/XsWwp9y3+Z1P7jeWx0bRTRxuNsWIbUZO\r\nhB18tIklGh+BFTzqcIRiuwR6/yjgDjWrIwR31D/tweYOj3qwUpULRadNOQMa\r\nI7x0kCq9HrcMg/AhIKBtaP4bzVIA7rkgdpiafhr5rMxDr6qLXcz5nxPpHq1f\r\nXRo9uib8gBvPdDXcdFR9THfoNyk2TEzKztJUjufmZhcN/rRBqC0xISlJwx+8\r\ngzxTcccttPfTMB8IGh1oWFzvGKlbr05msv76AQzpMdg0sej8dIlvoES3iZXi\r\n8pjuppmVMO06muyAQEUEI7gyR55VWXlVlkZcEzp+GKGhdX3FCJLCEl3ggaYW\r\na+PCbVYyaM4OrazdTiS1/FZlIQPhdAHV9kQ=\r\n=Flp/\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.72_1680521115556_0.6206312441844148"},"_hasShrinkwrap":false},"0.4.1-unstable.75":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.75","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.75+06cfc22","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"06cfc2295566b40806f0f496e16c1dcd9d02da10","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.75","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-0QfF8YavfVG5s6rG0RZ0bjuL3dhPmmRU4WGy+xhtNLmqkWNet5R6kWmyL4KPapeLPqvLvfUynEJ1JIu0IbbVLw==","shasum":"066b4c07778be85e3fcb8711d527c230b4715174","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.75.tgz","fileCount":81,"unpackedSize":294809,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCrImbCSBhvlq4cJ37K/poN0vswi00j5pecdNesy8XJzgIgXYD52CBEvugnS6vw0kzOIvTaUm/dA2xrFXs7dRnL1jQ="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkKsgcACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoLtA//VEEyBN0seii/hSWLDPFfbfS6dkkCsb2IlVoI/k8HstGej0Gq\r\n3OPVuRFNLjWAgfbFdMPkaox8Fj2iM1Wpd0owm/LRn6NUYvkh1OWhyQcTN+f+\r\nbirODt0HeUOB3e15Hcb0G8Fpu1wTAq3nqXbONQJKccG6GGwoPTUJudot+/Zi\r\nNeQMICPxZg4H4gM+8TI1ZnbZzMVUVZLBxnnDC3TAN4+gFIZfDrsV5PApcDw7\r\nRr3Q73RxOOnt7C3TU+bSIqTm0+84di3ZelxBTAoK+WXPw6zCSXPd5qSKZuTb\r\n7PTMPYVpRALBHzT61WSeSL7+zq3n42slSr+sdMsrEXhK3oygGQeJ65fjS7gs\r\nn+kU0XMT+wbuG48Im37Q0r879uCwgX35qSf4bQp+/HhAQCHCGPY22e/ntPeE\r\nId+/M+ABDv2AJReHqRswgcH4mRHqsvapA5hjTT4qSJr2ucZHmvjZRMXyx9Oi\r\nJO+7Hzg4g+MHzsrRFubxNvn1NHZ8cZ2Un8gFZzUL8SZNhceSc/jpJMEQifVL\r\nivZ7n2hDVvR9CwwnrcSj++squNrWWOBpQdHnClCnBXphF7L+zWjeZgVmlCno\r\n8KcPcSxgz8UNBlVC4CC7LAMzOkXLfbrmeB2YdSGcNYzxSo2x4knt+O1ClfXj\r\nXmXO0CpERvThbXF+ndStwyrLikdmBJ6MfPE=\r\n=yxH2\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.75_1680525340343_0.4732600616411786"},"_hasShrinkwrap":false},"0.4.1-unstable.76":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.76","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.76+6bda4f6","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"6bda4f6fd49b550d6b59da2b93daf3a0cee9a26d","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.76","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-SLJvBVuC3APbKbr8dHwF/0menKiOttlohlSPpdi7EbPzH2LWHIfr3huxNe5N7UnO6C5YS66vCT9NrEDGGIyEnQ==","shasum":"31f97a89eb54c4b6e43fb2582a55205209f2f888","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.76.tgz","fileCount":81,"unpackedSize":294765,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCUYmoCIdGp24Lw27uVNyHBr7wA0qCke97yvZ2ovcEKHAIhAOa73LoV/dj1yT4A/23MMSTr6BhDop3bZvtSgo7IevLJ"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkKtgMACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrhVQ/+OCxt+HYx7pIZ6R26Cbg7shh4FgObMGYyVmru5Y8u1sXHnUhR\r\njrbGQ2b9m1Y2rV/Vw87YEDhdlFkzvGdACIjuMMTbVhGrEtU1BFDH+gj2VZ8H\r\nQn1PXkOJ5NEtRh+bkLRsZ+PlKfRG17XNaSVene7IyOyxRlh9KGw+VaumBPM/\r\nQFjyG1zup7JVKHIaFIVJoCnn+skbLzVw2B992ZKuwUdsbH5DuxZ7lTv3ob0j\r\n52yOkXPoj14ItMVjrwHTMfI6PMH3deenduZTdVq7X6RAYqAk7I0lBtagrKUc\r\ntDEhAwgVmVTZo444ypQPLZycxhj/uZotg18X7VJer3aWzxpz1gT/RPfJliVc\r\n92nAsQUGHaYc/VUdDZAuN2cBBHBTA/y26Yhmd5Hcp6yArO3Fh4Pwg92tk9TN\r\nZ5KsE+thaPMzpv92soLZ3q/akd4AGLatWfITnXtLKtoVzOnQZgu/j4BUm1+G\r\nPwarIqmzakgxua+7lmGNuHru0DCM4i2AFzY2NLebTsl8mfUbFLKA4mHV00/G\r\n6syGmz7ykfPHfq8OD4xe6ddc0ykbqZ5iYRDwhOeq257Bkcpy0PenEjJu1CL4\r\nmwx49YVij2tmspQCy43TAYxvF9EwBYCr3W25dbfr6IdRucZpoK4aD8QfzH2f\r\nFzKMPtutBuJFWPQqi2UMYAykKdo7VHbFsig=\r\n=aTya\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.76_1680529419865_0.7010028945851827"},"_hasShrinkwrap":false},"0.4.1-unstable.77":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.77","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.77+45fd8e2","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"45fd8e2d91a918dce61790ce0a54f85e63eae7cd","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.77","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-+98WCqASIyY7HTk+nAV2jqWIgzX6kNYQILzm5Bh0Ks+Iw1J39z3YIDQCB6gPtk299HA+lXyj5r/ipNOYGMoIbw==","shasum":"a8e4f86db2a368ed69d97d56428c2b8b6d2a65df","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.77.tgz","fileCount":81,"unpackedSize":294765,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDFHaiPkMQUWxmXEbxQiTC4tVlsZQ2GSO7lJPRRabt0lwIhAOPGkETCJFUkoDW8cnpmD8g8yHHkh9oC5VCHIbB6rZxQ"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkKuTdACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqyWhAApMp24v0T6AZPhrUIIOw2XemhHHhQYOgAeAPviqGwy2Vi6kHb\r\nRcz3cu3efUzqgP8s4cG8c8pSPeqaoHRw/tSdooBtGuSJAQe/QfHL5CMsSCOe\r\nVtXzajtVywsF3nQGtmbHHgkySg45ECMZ6MeM+sv4SZuirmgFpVPQXemQaNzd\r\n6RNgWQKQEdN99m1laTNduuaaJDP9dF8MUqPZI+6YTf+N0l0xGD5tm+8fA0tb\r\neLXD/mzB2a8erjDVoh7tQoq0dNlwL/AKsY5F7aEw8cYSRFyrEbR4phfs3JJv\r\nT9Fg0oabc4JWFqBqU6BuhTbw/ZbVaIUlmvrrkwZF6VUCQEvppFG9qDLbtgoW\r\nt1PYWy8oU61HB3NobuIhWdzT9BEb0lcuy0iveisdMgtVUN3GcLSomiT/JsNf\r\nurdcsgD0J6T/14vsU4thrDtljC0AgiDAmzABoMeSHLoolvMYmoklHFwd+jVd\r\nzzva5FRS+lMsT3JcKb+4kqbR+L/FdY+yR6yi+8s2W89gXduqyBvDfAsNUlou\r\nh6fqKsQ0cW/okHn3sHRGKDTv50htxb/RIa9NRsa/MW6osCA04ziI0OB4qCe1\r\nLiRZvKe3OzrwYNqmNnxlnS8/dHk5zGmLeRolTucgbZjUlrT95QsPvvzLs6gx\r\n+AgyOkWZpOgOmRIJkTeC8wk3lJbG72uRkkc=\r\n=eHrn\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.77_1680532701178_0.04221401431853833"},"_hasShrinkwrap":false},"0.4.1-unstable.78":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.78","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.78+0e1dc2f","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"0e1dc2f89b42da63ebbfbef0f5722668f77a2148","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.78","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-EkkFp596ZlatjlQq7LeXIN5G+2k0feTc9EzTWLP/pEvTMXtaQvbez98LIoaozUdF36C/2PV8/I9Z7s2mp2513A==","shasum":"e93e9cf317ee1ddf16db4f9d60ceefdcc57dd936","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.78.tgz","fileCount":81,"unpackedSize":294809,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDeuRAdUlInwHtG/NpZt2o6Fv8uDlbSP3u1HV/xZX0U5AiA1q9Q9kX4EdAoWHQ/WKPzy3bRazKeIFWYOM6nV0WPx1Q=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkK9CKACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrxjA//Quww75IeRZQQEWgm5mw00/YGBpg7wPaEgcR0lkpXW3u2lnev\r\nKdU4qryyJb6cUL+elhll1CFph8OWE7e1NwhQFFH+dhR1/lXeL62hJ+xZXeCU\r\nr0RUSs25hnTgSU2tmtJ3mcOdaVypYrVLa2Q7kVEwY/jhSmG0tnzZgU1EskWR\r\ninvZyDikrdt+XgOC3y0x+8rh5lIkMH/OWflFQd2VSuTKtngC+bRXQNu490m/\r\nfmv9tPe3UGWNWeLUUSf5MOyzbB74dYMPTHp4nvylf5EiK7nOcAb81K1SRIrS\r\nQbZQdM3MCABdxdI8otUDfQh43/7eZPyzb2kDBPC47b1BYb/GqPJB6WVAiuZj\r\nPujPvHD9ChBSEdK7f/MFDeua+WU+iuMWLyMlJsSF4IxklCw3OxczdSxqjwUU\r\nG/ILw/W+p8GPMqT1DLDT3IhuigX5OVHH148y/OtpuvzNpa838/XB46QgokwE\r\nZzu1+RcfswySFD+q3pkHbyz5ZWG4EZsb7QkxYVzYK/Oo0tYTLJoXqN0dJ8OY\r\nTO3Nd8dSNEOmd0Z1cSU11Kh7f4ZD7a/VBoCFrKfk9Z1CpZxsrJYqJrPsJadg\r\nFWL+h4wem0q8zCOOmsU8UTZdAN3x+TgeTvvOF4lp/RYBXnPLyGfRGOMChnr9\r\nKT+shFGfkV7w0Go1ozjrIsmQ+OkMESkxQC8=\r\n=5vH+\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.78_1680593034424_0.7099224213266349"},"_hasShrinkwrap":false},"0.4.1-unstable.85":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.85","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.85+89f264f","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"89f264f7b5fa61d0c4fe5f2378323e7807bd3a8c","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.85","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-K47HOaZsywZ64ggddYvC+x7iA6jBOX3eCVDoFmaLSz7rAK/BC1O1xAVrkqprns4Ymhb4fMDR9CKOG72CRqiuKw==","shasum":"2cfec20a456c9ee0cc6f75f32244197140c6a920","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.85.tgz","fileCount":82,"unpackedSize":304508,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEnRK5JEV2t0sWDdof4RnP08MGEPurq2iAXEA8mulGuOAiArjafSLa1+OhUwj3VxacmSVLNEXhE3kQxmsQuIjttskQ=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkLASQACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmolpg/9GQEUyj+SV66g2jVRiQ7Qbm+NXW1DBUXpm81JeiKs6MiauIw7\r\nQcDMLm5uI5/b92HV7IAyE5+EuKt/EICStZ5lNFW7/2g/Gn7hGXTZpXI30+AJ\r\nGyfJQonb5viy1QNFSN1VxB0Ne1lBGzgIuaq8DZ/Cgzszr2iqi3ACOlt73kEP\r\nD/FBVgUZJTF40rEk53RwOVd4ZkjN72f8ZUvrUkU3cW1LWyltX8ZdhPgni6TG\r\nVo4S26ZEPLXuKot34KjFp4xIfn2pIOcGawfvqqA74wQ+izwOl6+5nJuu3iHA\r\nyHZsg2RMoePRka1i2sWQA5lPh3g9Ico/V3/9iCfW+SZRBi93J0vBD4QXYrhM\r\nmPeMGaGueAZ5sh4X//za/Y4YapvWOpHsy4WIQlnAoG8+gfESXsaOnd9I0n+S\r\nRWiQt+NsFDCernncSju75T9PO/HKP94Zt985H5cywiKTUO8Uutw3jNMY3eTz\r\nxilRsbs90lU2VVlJUQ6jGLGFBKlYPcfa6MLQC8+ekDaisYTIVEaxaeSmItMJ\r\n+eXRXHSqG2IyQpWW7+j4Ri5TYLt2G7MEjMtWPQfP8pxiRVm97T7i9tuHi4e4\r\nq5bdFzpVogfvfS51PvP7yBZZ5zlftEAWQlTpVU1cE7JGc2Ad6ua9eC4kF3ts\r\nQpBSS/00a/qe0rhPRLIJu8I6mRf3sT/Tcfs=\r\n=tozg\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.85_1680606351987_0.03350892200324784"},"_hasShrinkwrap":false},"0.4.1-unstable.80":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.80","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.80+a3f0e2d","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"a3f0e2dfa9831d886c8fafe564fb16d55c33e72f","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.80","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-wkAzKJD1Gtqvhj5G70/PPjvUxsCKxpB2vMjGNNJAWmDCIv096EEMjPhTrcWyQuu233EwU9VUNUrRj3J0rzH5EQ==","shasum":"fa4cf7e844102747fa486178857f9a7a7763c24a","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.80.tgz","fileCount":81,"unpackedSize":294872,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC+5SxJN7tXSzv5fFaTdKMk3hNFbbTCFiN45Ym88N7UGQIgKL+bYHaa1sQ7JTAeDOX336Nyk1toap97/xt8nm66l3c="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkLBA2ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoJ+RAAgKDnV53VFQsOGYdtdcH6DpiRzS4o/e/Lb79zBhP9eehIakg+\r\nFwgRJs6LfIqe0v5XhWWGzpQv0HZ+lg9BdP2T4H+3QUu6OPAccH3RfVTYROcV\r\nCfdLqOZWmHFbPWdUKqtO80djCieyklhEYjHadexAn8V5Lr0Zx26kurrWPrxS\r\nenlu4wCuv7LiFP053XQyuaJr/IZFWzEovjKMzKZBvgF9gfsmJUeW/ogSLnKG\r\ncF6OLxf9tcEUHhJO2rCjN0B5cGWTfOWKJxkA/or2PUzZ7GqMPo0RtazgdBT9\r\nVvIJBSyAUIUUA1RYtlRyVwcPlGkLTkwh04iNz3xOyG6hzrb5AZtW00YWSi3e\r\n3yF5OuF0ysLroJHO9LE4zT9GItBE5xtVZw7cvP2Fg2yFX6qOCy0YK2l8wsgj\r\n2yKc0Blwzmy66Ox2mPf+NQP71cK22ty+dCpkBE95pZVtM0yWz6NtFeQaxbrr\r\nob635GtjzQlLqJ68bG5IMRWoFXI4z+sf0OGkRybuSq5BHHwdFgDW39b9mgaP\r\nrnJrvCBaDP1XfXCl85ZUHcRpY/raT6Tj9ob99h8jZgmiAedNcqUJ86yZYiwO\r\nYf7RWTLujbapmP8qj1lMjeHyOCU0vhh1Ox/RFQtedHyQUoMjGA3uHjxpzfdh\r\n7TxaZcQMgq6jcVQV2Gxq9tswGQbm8u8Yejs=\r\n=u+B1\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.80_1680609333787_0.2871580119508197"},"_hasShrinkwrap":false},"0.4.1-unstable.87":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.87","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.87+cd1f67e","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"cd1f67e7f16338b4ab5bfb76feb0fe26d3652918","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.87","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-3JJWRyuir6jp/cUR1969BZL7KUC36TkVXV24TzJgYMvs9Z0xR0BPY8mXKA5z/tJjE4nI/yO+mugOMmprfef4uw==","shasum":"d8230d2644dd78a9ca75d6d65e35375057be3721","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.87.tgz","fileCount":82,"unpackedSize":304508,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC0sa2ge9+yt+DqJzyPDnDwy1NUlhpXOzfYaoEE1AqoUwIhAOLAk69jOzLSlUTO/h/un495j1oeuR+/zej/Y6oTZVyE"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkLCIQACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmorJQ/+NduxHVGoFPsqgzqgDm2S+jBRfjVnlCS9f5SvZtriD4j9qE9w\r\n6gaBCzOszVHp5bjM7BknoMszm1MRumrJ8e5nvU9rzEcDDpT4XsvXK8qk7S54\r\nmhDQCV61T5gGLqM3CtJdGdZAQjUT2SGQmgCF5LvSm5vq/bvXw+nBr/vVi6VJ\r\nhys5JIZRGA3rP7SHDDbzjXesua29lSMQyYFYkCd8/SB08uazsKsMWuhgXHC6\r\nN/icSPAwf1I+W87P2LMWF4Xo8AwlZQDkbFga5WP+V8tCi9gLYd0ksWDryb0A\r\nbsO8aFHw2rgrult4NexIvXT63TNTZqHB1RGmaPfZShse2QTwcuFQ+RiN1qYo\r\nptIIZwPqt0hzMoVwHrg8wncKfRirvvCAHiOYjjN7sg7JML74D2qLHwU7thng\r\njZ4aJedS4fPlb+PrEuCb59bA/UYFvQTQ+K0QZHUY5MuRcNDrHCE1J8Ap54qq\r\n6rP6SYRn0mgSW9egeitez04ud2of9jhLPmJ9N871aPDIjMcUV8wJOyhHdLun\r\nk1kVT4BPAZIOp4EfJSuMRzEuZOA8j9eBzSoAD1xT7PwCPVm9wr5vryrZIryC\r\nNGX7XVd9SDswgHtNH23mkui5mgVA93tl067lBHp/pYtqC/r8gguEAmy354pX\r\nUu4SzT0xhHQp6RQCYfHb0beZbf/09kf2TYs=\r\n=DZi8\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.87_1680613903815_0.8601877081872695"},"_hasShrinkwrap":false},"0.4.1-unstable.89":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.89","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.89+b542908","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"b542908ffbbf14914f9e71df377d1e77405b55d3","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.89","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-J7SRySPbaE9n9Y62cL91Iadp2jX1gZ+HswL3R8bhQ+RPQ7GH+t5zv0xeq7yF9PhqOdyhGRyfWhNFi+d4v4cVew==","shasum":"2a8ac25873c34f64d32f63522d2fdaa8c39254cf","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.89.tgz","fileCount":82,"unpackedSize":304613,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDWqr/fEFfVt9jWdJAz7ZewacJFUMDVxgyTaOkdHSPK0AiBE3l1ZT0T2+WiKgAdge1taSeJJRfGuj0xsTXHzZk/xRg=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkLDDTACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoREg/9F9fRft19PtY1WS4vTdYWZRfOkxDGKqGQCjwqlp+B4e+hbm4z\r\n/d2ZUKoxn8UhIRSJwyuL9NNvUK0uf2LNUO75bIzGXlyyRPYLnHzwwZenMEVs\r\nNgFi6C2xGQ5YPCTets7wRhv5FDo/Fujrh1pvQRAAhB4GI03F06JEroGGhs8B\r\nBptydgrISGffoMi4wHvzdjL6Jf3cvRWKnc9O4OsI0KXfnYyrB0ZdvKQeEPQH\r\nrk8kKXHN5PcRDji18V/G/o4iWLNaFXZjDDX4PXII9AHaYPtCdfuVuJEcO/PE\r\nm34SzOyoM32i5d9esBUcs9ulv7MYTWZ77bLtpmfkRnBDrLPaBuoZkZPWBDFi\r\npfb0yfDeSO1nmRG5rdG8BqsCcZ7c0ZXsR0QokabN+IhtV2E7iauWWXV0FAeV\r\nu++eUbXIvdIFWm2G3xzBGIPDAhvq5vSORF8lG3JU95GV7t+Rdnpc0bgz4CRC\r\nbibkXqvGzOwiUPLgwoX0AFNBjgdQ4G3K6/9umpLCwvSR2OBByw44ZUaIN6tI\r\nsHEWYDlXlx2+iaYJZA4qSQctRjisl7yGzxVnRCW3J66aR1randRMdWDoX3x8\r\n3oYTSGoOKcb0Ojd1+Y+mSBdQxwY0TXtWOnYME5Hbe4rSBeIOp2Z3/xzpP1Y4\r\nd8OCvUxmAe81hw90E3ta8Ci5U3M0gapLe9k=\r\n=ovVF\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.89_1680617683032_0.6402984715765268"},"_hasShrinkwrap":false},"0.4.1-unstable.100":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.100","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.100+f2783c9","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"f2783c93b648c62875e7f329d8e168185d851dc8","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.100","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-rVLoyN5jImiO1w7Azn6/+J/t6wIbX5jG0jWHA6Dm7VP+Wimzyl2RTwKI9sQO8wg59Mr1KbuAnrw3rSdplRa/NA==","shasum":"96af1500c7a7eb1a44393781fdcc5751c44c6e06","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.100.tgz","fileCount":82,"unpackedSize":304617,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQClCspSLFCMr+MvkL8+YexbDQxTAjin05oHR0obPIvPfgIhANMgn/K66K+T2oXNHLbNtBCvnJGWc7oQWjvMmZkMPYm0"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkLDsvACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpLkRAAhG6tI1iDZiXeDmqJRoiZbyo1QnMpYHusS4tT51efhHp2RROg\r\n41VxRYBVG0+xE+cXIzwnmyjkRcdmKl8VV3+arXVxCV1lWH94oClAlNX5/9Iz\r\nXGCeive2DwYFiaEeRCrgQQBhy623FflVFDM7MfdosXnFu3KV9NqGvGBKl8ra\r\nLDLZ/tPsggfmf6bh+yao0L2fQbeNafR9qHwUh9frW5Mzlx34XDu4Wjb7oeHV\r\noBVnLyaTfojmjLEiYedB7O1Vr+7heUMTCBn3TaDQB0WiRKSuW+RbOhuPpavO\r\nyodhpNko6TpB0xvaAlvJQ2Enm+JuockSBCCs76t1xUEGS7pMvJFFZ5tdL0qo\r\nq1fyx/Yzey6YUGwzADNzi/gViz5ZIXX49jg0Ejg9nPMIHgA9dS+Uw/P7YxGb\r\nwtTrzzeB255U+HYiFZy/gFPCHlhipTZZXMZFK8f5B1Wy84kmnBaPn6jzPj3K\r\n+O3qf4x2+RLN5BCXLyp9r/D11bpsrjycrahdm1UCymM7YmghFBi03EtCo/QD\r\nWRc9vSmxyVu5keME0bPdnVL73v4n4GeiKTi0E9WQgbKstHzycLpsjowVxbla\r\n1ga66eh5dlfCe8CdwVmSSL+Ngye35nkiOtB5DvwTJRNjNQq+9OfnJnJipmDh\r\nyPqmBHZbMlm/8PJQ7/NVesrgUQdJkFzRRWc=\r\n=Ja8v\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.100_1680620335225_0.4265979237674882"},"_hasShrinkwrap":false},"0.4.1-unstable.101":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.101","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.101+6c10909","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"6c10909743cf3c3fd945c7049dd991c074a6dc88","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.101","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-6+OLecrOcLr889du51zbjo2rQ9u6dqvgBk1mi33pSIGazFq6qDwL7AOqtpqWOZfvLUJ2vickVrdOr+sV1KYbTA==","shasum":"977e01611c1aac2fdfab66042a923e147b724543","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.101.tgz","fileCount":82,"unpackedSize":304835,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHZBcbJp2WqNpJiVexXb4vnAkKQqn5Vf2ADdnh+UQy5eAiASYIysGjXDQLw5rz80qneIxcej2mySYS+PZbRzRwoGVA=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkLDzdACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqERRAAh5wcmvD2F3HQQXqMmi18LL6mDb7eHUM36y7ubwy6WGvh+tmH\r\nhONiMyX88UJjtkh5NsXrO/BpKb+PFfGzYB+TzCE/eVHcBaNpxNrrZjcJNWXp\r\n0x3PpiUGAgZ5cnPhiqFYSU7VWFmeN9avq8+iRvLk+TIf7gMkkc08kIXuXokw\r\nZknZvTgRZgsV7/vQUIIpzed5CCuSORnkW6VxzZWaVc+MiSN7Snh9OYpVxiXI\r\nMj/UK1/tEBfTHkC0MgDg2eZ0BYwP4OOZHdxFlX0CDPXdxV2wcalIosHFeVcE\r\nQNwIGrToBM2GXQGhOlEo5QKeyputx4k/6TqyJtJAdbfyFDuXpOMVaXa5tlVf\r\n81+IiHxKuMYKGxhHsXt/UjRFfGqy3aQzC4ILBrtZ6o/4IDVmgBAbvU7GqfIN\r\nZEC0pXPO92/J+IHJnwAJQjzahiwxnKEII7Rl2mwKrKRD3lvISWaJ1xH4x2tA\r\nWCyidS/rvIFnQqmzucm6aQW0OCNnPHksmqliSlNoAhEZOd0CEnLToWtvJhz1\r\nbDfeUiOuFSrtNrHJfE0zLd0tM/SwMZdjL5AjP8tMktNRbGs3KbjzqUb0fkyN\r\nu3IRJ0SPwkX+R6yVKWLjNS2IyWE8qeI5gwQATvbdmrSWfWwh2C01EV8fhhAt\r\namy4fYH5jlS/9sVUlNX0a45PqW9Xwx1ridI=\r\n=tr3K\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.101_1680620765403_0.07271879374528623"},"_hasShrinkwrap":false},"0.4.1-unstable.88":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.88","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.88+162af38","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"162af3828b3dc826dc3cd5adffe3dab61925ad33","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.88","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-XAQMfaypogqaRcBE4GzsTpSpF9T3IqecakC4tGfJ45zvztzOeo6PAhdt8/nNDD8/A/XTUSAWnpYe17SwykHykw==","shasum":"68d211ae4c8d7f31063d9b38cc7f10aabc6f6930","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.88.tgz","fileCount":81,"unpackedSize":299644,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBlQpruqT0mNihFuA/9s8cAvDTl8anavSNp3zQyl31cxAiBVLmmd0ZU/95tyZsbKB5Dzkh4m3GTGMnSvAtQx+CKMzQ=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkLTFKACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoTwhAAjgRCaZb0XNcaLtwir0pTTd9aqKuzh4jf7eR7//iwhg0oa3bX\r\nGImpwlcEoS9Rlm6KVDLqQhpfKvWT2WqUmMAHOIsoBzjeIHlA0Iuaw7aH4/A4\r\ne+Z94mm0wrwMHYpi9fxbxiJLUqmgcBhia8GYUF9ULyQImW0PvvI4NoDI5EGj\r\n5k4J+uhIbIrPccklzqm7wLcZeQgiXoTQS/PBcJkFW7IVBENKudlbNECbsZuO\r\ntSvtlusT4PpUTKhokcAqVs/MSpSbVHDToVIvNLcJZ9Hk63IwNXBGR9bz8Vgq\r\nV5APW6+rFkPKGvoPygae4RaoFhhrMgvBNbe0s5zyWtzcgndMT+e0hQvp3ykd\r\n3kevPW2ha12LJZPPSLoeh/FdheErvIOmxg5agPQGhXNZ1POwv01YUKF3sgSl\r\nroN6/l4ncHut0VctD8nnF8cG94/D2YU50b9c+ZOTxC/D/7uS9EiesEaYrC1D\r\n5zTjVGC+yQ6arIpOMEM+UWEY3OwEAPWNgjUVQzbO1Eaui2rGUpFRKAvaNGh/\r\nY3VbMcpI+UUO4LU0fyFV2CGD+6POWp9cXWfLrkDYb6uVgg8uRUFw5Z4MiOaI\r\nmrfQTTXEHH6+W0zDbM3A/EWqmEW+xMfivuRdVH5bOkZlSieuCuIma9LrqPVR\r\nzzQY+vrIe/11vLZvNuNvG9zEPhdkgxwsdTw=\r\n=lZYA\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.88_1680683338060_0.2666524860415944"},"_hasShrinkwrap":false},"0.4.1-unstable.102":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.102","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.102+38d8f4f","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"38d8f4fc4680b4ef51497b0896e6c585216a5860","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.102","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-N0uPITErUd06BuQCgEVXWGCw9LoN2sIwTuBJllq6fa5x5otChuBbxrjTchZfD1w/6nJASaZ7yOO6lljXPzI4rA==","shasum":"9fdc4c585ac8dacf31afdb429fb61bda9aed6834","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.102.tgz","fileCount":81,"unpackedSize":299991,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDo6vk0wZmZUC1qCAzYlD/iefUXDxmE4n1cjkVG9pNyUAIhAK4HUbf6uL7TIPLM7VIihEUfaq3JayDVrdaKtkKwcOQ/"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkLTNvACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrA7Q/+Nw5BVO/XV6GQ6eqJr66fkPIAztfPKz5D3Ur5ultOkKZOwWmd\r\nbbMDObFgfXBTSVHMDvS0aVnEItR9zxM0DLAKTquo0XDDz16oxRJc1nC8TjtQ\r\nYDNRygy+sSGFSeNfFa+Fc4NbFBtwPgEWjDOCt4lAOT7tl17viBqurtfY77eV\r\nQ1J3c6feRXg2X5L0TFbFekeghnrTLgCQBxKohAyCU0BKUR+ZN5gah3kI6/j0\r\nsD1DV+ZX5aqqL446X8dd+FmfM1wYrAnNZkgFPRMWz6bN75HJHGEWzxLRO/Ri\r\nSrWfNNvP70IomVi3GRgSWnMYKI3qAysV2aermYGeqw1fvaXbIAtrIbaPPGF1\r\nGjGPzosVL+oQkWZa7fah9jeOfUy+vF0N+SMWKqwNJ3QKteK+hKgv/8kq0Aem\r\nk3JnZP67k32SJu3wOYXR2jP2mNOKSxcrstcBTPsYrbm86M+vGiC/LOBUVJgA\r\nxAVcKBK7iHdP1AurrqOX7cw/kPkssJkG+3kGQUHoYWn3kbrdLWJ2Ezj+8fMd\r\nUbtFMZDrzlzqwa5rakQFVQzfDkJjttuhku0UgAJ1cK0AQnThCkW0xPmU37cy\r\nGZi62sbq+vvn4W7WcEyCGLxQDCVG4xp4ev+P0lvpFGF0uchNAOJnKEfQdHmU\r\n1ne0E0jDXnvMcZymwUMJ+3zENf4YongG35E=\r\n=1YHF\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.102_1680683887172_0.7411539807981069"},"_hasShrinkwrap":false},"0.4.1-unstable.111":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.111","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.111+71c069b","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"71c069ba8c16ee2b8e338e77e8b4f2996bedfc57","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.111","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-TZiE4oA190e//LoYzyqxBmxUN4veJ7Of5AKBz0EkyTWeaZR3x0uB7XmeHEDfN2jGcAzmFjuq9AQbR6FarqwzBg==","shasum":"4b2b1d421e3409877f60beb1e3703e7b709b710a","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.111.tgz","fileCount":82,"unpackedSize":310046,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFBhlomOBH1rETtVBpxq8dNnJNTygju75gOsSEK8cMw2AiAbYy57PlZ+sNGTbH1Q/cHmW99GtzDC3QxZ9n+ARzxn9Q=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkLTilACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqXExAAi8JL50d64pJZc1K5tFOX50R9fOXYpVx2yXzbzW4Xu8I4BZlz\r\nKsBb93mMgxDYla2Q7Ax6FysG/1DUrwiKNdYf5xDQKk7rOvxMK5TFMvfKkm6w\r\nSpgYyYJx4KSq3H9YKP7J9z1aCdzN9F919xQInKx29MgNSkTFVAdW25z9RhmQ\r\ngD+FWNSwJgGr1OOLXo/YJ+LZ6FxUOrrWWZog9JtqInR5qK9DuacTYXTiexC+\r\nE3k+BYPebAi6vtvO421V+emJlWw4r54sxrG3XPHMVBqyCzn4kDjEVVfBQPco\r\nmJ0xHKRg8jZMFcQVBtnlnXXpHcNEejIHJOGpfG0fNjsIk7T91+HXsZKi9O5w\r\nAkS0qHaC89ojxFpBboSgBeZiPUCaea14ab6qIvL0jwAjyDWM1/ufHtYNKPgr\r\ndQtl6kKs3vEX7LeJvJbarXci3rsS/s1432ur0liZkhcmGXlwVS1q7WNUpUdl\r\n6cdjH4WVDUnYvrwERX5Wqo50xYn1HO6m+YIMvMMWGjGSNPsSdZp5XaozuCja\r\n+We717XgAMmbl3TpDRMmXY7FSE6WeOEuzVSU6jyQKqP0uiEbmmXzFICfW2Lo\r\n0x8736obYInlWfBJYeyrVnx67+DCY5j+6SFlosShj0n+0akDsCvVCVrw0YMR\r\n83bLw5d8rZKITJCDUpxVth99AXBjNHGE/ds=\r\n=fauF\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.111_1680685220704_0.08325334068090262"},"_hasShrinkwrap":false},"0.4.1-unstable.103":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.103","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.103+30eb5f5","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"30eb5f58e97851af36c7e77b08fd4d648d8ba902","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.103","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-rWzwBZ3Qla4Cx8DYLPCsY0RHbm6BvhD8XXgxHclVxmMR+IrvZA9c7Q/h+dtZ+LAzuzcUxfXTlK9ktRGEU1ULmQ==","shasum":"e4a8909a4ade029d8cb38e824f2ed0b1339b8bc8","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.103.tgz","fileCount":81,"unpackedSize":299991,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCtspYGtFAHbFPT/AzDcshBIFMaa97AH292Di9rCbgQIgIhAN+lwvUqkF4XUa8wmEgTFeosThFA/pVuLuEDsd0GXj6s"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkLVorACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoleA/+IXY/hzObl+DezPDIMSb45kqee8+bPj/25XOHGlJ+MjsiKGl6\r\n+LTZNrVPBMj7gdFjcNo/2Vhq4DgGh5J6/4/sinJEdj/3tM9/ABOe1OGOzyp0\r\nwZXwKMhC+gVB/Ju4I8ao2RRmr8+AihhFtfrStOujwPu62AQ6YU+/+RCoOBiy\r\nK7/IPWJy5CxiX5YWq9Kx5Y+Vd5iC2fnEQFhiKlKSxDiw1kRL2YKjRA6npv1p\r\nYdfctYV/NpCc3OI3PVwypVniZggodZlX+Xe1OO8msjo4rwfj0tnKhRDjrNrH\r\nrLHlPn4Ga+EyLKPTh7E640NaFywpPshSbuSXcet/b1G5W9SbZwxddDv8Lp3w\r\nEEchk+MUDwkZ1NdHK3ApkmyEZlgZAfsrWYwq9cOiJQnuBEpmzJbjrPCdeb8I\r\nqpuiLLX6P/s6sdLcN8JuVhi5/nhm+OgPBBdRltYRKP8yUIhH80aKWSeXQvWf\r\n/nzbwPSgsop8BqUdWJH1jddI3MrQ6M1Qjnike/+Vhdk+EmQsyKvjaBBzwPUY\r\n895LqbLuu3RyBCh4UsI73TGlg1a23oiY0z2x9EJTG6qvwcAyxbhkkNswsJl8\r\nNukSMxO3c1UfXY0W0Dl+XFFTdRZquopjZv8U/hWfw2zPCAinzUMFrwla3waf\r\nHTV3JPkMJE3wwE0puVbZV0Ydb7vEf7KCj94=\r\n=iK8L\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.103_1680693803655_0.4552423448669476"},"_hasShrinkwrap":false},"0.4.1-unstable.104":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.104","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.104+9321f55","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"9321f55c87c54d4c086781376473d69abb2bda82","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.104","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-iVqqHxmpVt+obIwdIx6ZXQEVT3VoLCfYS2UP9U44YxjyUmTFQQnZ5LKVmEOcSrgui86iiEpR017rFTYdNBcBQw==","shasum":"ec8e7b63558f4cbf3ddf2e5df0203259b2044a4a","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.104.tgz","fileCount":81,"unpackedSize":299991,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAYFO80xxiBomTeYJfHxpYcIRCgvIFassc3A0C82Cuj3AiEA6GrkoaGeY/OgoOAm/bLgnfYNfvxZzb9sqk8CVa5C9/M="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkLWHUACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq0XA/9GEg2BUHbFwpNOzfv9ysBE3Vr5wz5sVkZj0fVCeudRLTkSPKZ\r\nrgsWaOLQrfvhNJ43X8kYS9hw0X1lGY2PNe7TadMebQeqCffvWccEslJ1+sPp\r\nBU7PD5XZKWT4NpEi1l2xd11WTu+SeJMXA1xjXtlCcFArGRTHtuBjfnaRyAWm\r\ns6RLlIL4+jJYRWS8rONSmnzrMLFX8VfsUUGw5EDqoIawrmmwclQpX+qP9RGz\r\na7mIz3C0+Rhm8SL+H+P7iY2hADQTA+TMdsCniKuMq7uDoujKehjWlIcI0L+f\r\n+XFGDNV1iuTPf16Ll+7cKURGzqKVOG3WxLeaJ/Ig2UY6LD9q43sT62cwPNp6\r\nE/WzfOm6BxiJDXdiiweWFo2Gz99Biq+OK2KE8dwgycXWibLZcHq84UZpqvyn\r\nPRcx6ig7gn98Cz/hsOB59nFWkIJ+bxos47I0/jT1TMsqxFx854FG6WWPxV/W\r\nhqWpVm4Fp55V9sYyLODCrfzu6EBoxkOkTaPKMR3Nx3s4NRVJrEj2VSXBjJF2\r\nlycUKen7tBL2JIw5Yqm8REqmTpI9Gcm0E5MZD6EaTqi9UxVUX3COjsdRx6we\r\ns1kJNEMk0J3ThtZSOmV5Hy3GYaAEKIsYpwznrTh16+0Ht9zvnkeD7XEfI+MP\r\n5PnahIDjDUVHhPzGUq2JyY1JSTiv2As2/sI=\r\n=A3kr\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.104_1680695763933_0.7911945542785686"},"_hasShrinkwrap":false},"0.4.1-unstable.112":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.112","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.112+9a91959","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"9a91959371e5aa07d2eaf8c000826aa072492dfa","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.112","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-NjP7PGCIXnMmp8DEWWDojya6t7/1J1/barXvylvegFjBrOFxfRJZf9ZxSnvvz5FaxU7xm2ukMch+dY+Uf1JKRw==","shasum":"4d97eb11433d3f39390a4056d00336f9b1c03bc2","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.112.tgz","fileCount":82,"unpackedSize":310162,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDALBuJSsgXsgdAVSY/tIRFJKLlCeQst9I+CgUJ7N3TsAIgdmHXiaZUC8sxtj6MeiYDmMNSXbzGVhV6JqG+iOIwkac="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkLWpoACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrIYQ//S/OP9zCa0MS16wIFjNS0P4gldHSKVMyjV/vnQSd9MjHQfGn4\r\nAFK90NGyMKRS32XkZoy4WXSowdGvq0vlsmQCT9EdEQ6KPs6Jya4J26GgpFSh\r\n7DjK2XR6HRBcK/bu5n54vtVptW31oUBuux0TIwEtmK6vrrhvVXQ+tJ//v/aT\r\nX9D4efP6gpZQ+ub123pXTx9O4ygBS2bvrqVzVSspTqZpW+G53pHtqlFrfHOU\r\nIrO8RyR0o6JSC+Y7XwU+hmCo1UpfKxO3ajeWlWDUyyh7TMKVik2sNoz03f8Z\r\nDy2/Jalo/cfeyFuDnL+v0Vzoj3wp9GAVbqkgI1qSeTfPdYljTt7SZuLUWXEt\r\noXdPvQk0M6Ltp5FJ2GA7jgtOVNIxx9rY6QcYg4F3iexXR6pTfzOkLc8egFYZ\r\nJ3M1D+uaHz7BZ0aRKnSObmNYNArL1OXjrKwZHbawopylgqfPDWGo/CQMyCYI\r\nHNUGcKtXckvjgaOek34cKFivRBsSqVU6Ly75oWX7MepmM2amOcM0lYAkBXeU\r\n1Iyop5XqyAXv1fARrwWMHBT+nh4NvEm/wYBcsKNEAAKtMA5PI7PGnVnQCaVj\r\nFclPBAwWjYcX9qo93NYtIjziN8Tsk62ZhLXy9IezHvLVrsI8c15YG1WRC6Uo\r\nLuud1tfSI8L2A8Zw1eyuJXntXzfy9m8LwBw=\r\n=JLih\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.112_1680697960575_0.0824492804731971"},"_hasShrinkwrap":false},"0.4.1-unstable.90":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.90","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.90+71b53d8","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"71b53d887819a2bbc226388a88fecb9718101270","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.90","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-H7Uda2n6qA1WBhM6VgsiulQb4r7ChQct2/CGI/F+Ovt+v3AiCSINiR5H5Gb8odSCnoJIaf1SudDAmV6xJxtBMA==","shasum":"458004f45b07ad43d979ec06e10ba551210f6821","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.90.tgz","fileCount":81,"unpackedSize":299989,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDrKpTyjWXvodwMLD97/Ja9qV7kue/wdQOPyi8OqHqvgQIhALiY3VSF1t4mZbtxN0ewIMFVaLzAa+I6zk2wtGeJ0gcr"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkLXCNACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq1sw//Qec6w/zZpLO/htB2LD1lzcnMBsKuKlNH3yUrVYDHzaqi1/za\r\n+nj0vvAnXwa05MGX/p3Dm3hkGyc0A/Dg7SGe99EAZ9FEYI9tkjhgHHZ7FIRn\r\nSTRyMBmihxZPWBwEQ9UGyjmFLdc/T06XK0tjxeButNiSYwun0xOrahyYeeeM\r\nwnnJajAJ0XQybp6hcTN0cv3V1MOW2UXw0Z+Au5xIfYs5EeMLZl64axSrv2/q\r\ncd2tnYs0Ny4UD3GPjU83ShROZc791BNnFRfQfsikuTsJue9DVQEseAftoRst\r\nsIZraUlYRV8neIntTrBym6dlIECLX4QQEYWyPNkKuo5ZvIVQEQBbx7Da2JCu\r\n4d5Klts+p1OfIlEauXNC/Bu6GRcc306dAZLF0M2QbJy1fsResnGlXUvjf+P4\r\nxfageB8DXVJLlaDzm5atC3gYUFlM9RJ7Sp7Log8igzOdp/acbk7dUPuTGdSJ\r\nHMIb2PJSqDVFd5xkaHiisbJeO19q0vVTCBJifNn337DmoYp8BiDUFKUzx2nw\r\nv6akmtMfWZZ+Qq8rc4FOU7UsqxzvnrdtzeP2BJsot+U1A+4ly3j6sKKnGYlm\r\nHYJMoZ0HBPwLdryyqldSspyhFroltP/RdBozg9ZQTPyGjm/kKt3MUF4vdxjY\r\nO/x6VE0fz3qrqrNk6gql0Y8yXQjdUepFnZc=\r\n=uVmM\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.90_1680699533361_0.27946408658944244"},"_hasShrinkwrap":false},"0.4.1-unstable.91":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.91","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.91+53ac87b","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"53ac87b040b04ed57f5b47418b186917284cfc3e","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.91","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-prZ1WaPxdoc8XkCERr79QWYww8MbuY/3/r+TfFCw6Whp3YA9tCjXAC0GEAwb3zXiGaUZFA+nbkQVSk9V2EWEMA==","shasum":"9c066c6d45da5a0ea0e7ce28f25e052515cef1ce","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.91.tgz","fileCount":81,"unpackedSize":299989,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDJLKqzBsC2BUDn0HShbNNcc0ceRBzhEGeCw1gVnNQRCAiBVXNerQycBviQiI/gZucUds4QCvFBl7UDIT5kqR8In8g=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkLXSvACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmopfg//Uw93338UkO/aiRdIUIhSVwVSL4b5Cklbxy+dQC9GiTewM6uE\r\n+BJ51M1G891gWHMJLoAlS1hRnvtCj/AgnzYcfLUE/LOhr4zoF+S49i6hIqoE\r\nyI/7Z+y+JdZa1SNpWpiP769/Xj3PWnCPgtezMT9nAIx/mTavXX/S+oifcK79\r\nZ6aItUN87DWckXT/Wr5zE1B5CRaWUZDM8WrC3ILqHNwGPzX7prsLpBozBcm+\r\nQK0nvS2KCUK0BFKlovPWDxwYqbhpf+ozP4t9Gd4YuSJWeYsPYzjKk3kYMSDL\r\nRA971EIQp8wtzc/yTBhJCjTMaJkXVVioWa4GKSFKq2xSYRC99QfsTd0ncf7e\r\nGq3mbgxFxoYSYC0tF7BGup2bQ0Rtl4dLLtDAvHFx7G/UqcDy15K6qTVM3l0Q\r\nb5mCRShrX0ca6E1e1VgWTszpJQ87O3m0xb3GI+/yv5Naw5G2dfJjZUvF11cP\r\nXNALNQg5faTVr1Wvxl+9cXS9X0U5EEbNWJlYN3+OJQ8l1PHY4xvaEBf4QkN3\r\nldE+w1pqF9HgCTpYOa5FIOsdnRDZUJSNnRAbMEK/rtQozVfv19I1E6mg9I71\r\ncGPWJH/QT9i25U4zu+3Tu4Ak9UPRkujRK3s77vvNHcpYHpQ9vrjiqtCPs/eI\r\nKQrxnhtsHYqMlB7lx2Cxw3mzq77MupSCbx4=\r\n=sXeN\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.91_1680700591675_0.27841587629169307"},"_hasShrinkwrap":false},"0.4.1-unstable.92":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.92","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.92+a0253c2","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"a0253c2d2fcc7ee17bc64c55720adf0f07a7d973","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.92","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-6r2BudYpauyF+nD7jBE9v3rNVKOxTdArbGaLz06oaHZbB6fFEp7ru9E0SaLF4XCUAZ8th76Zdq5bijd8FQ+6RQ==","shasum":"86f42cb9791e467e40fdeabdcc8d13919f50a80d","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.92.tgz","fileCount":81,"unpackedSize":300116,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD2GVoo7oJ/SUDBLI2q7gEKW4u4QKqeUh0HtLUGu5jivgIhAN8BFQ4811OXnQiVLknlskYHTUFsAm6mXuJL2V5Netwg"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkLXcMACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrqDhAAgc+LyKhL4IxlttjNmzd/1KuXzOGs0f1KttZ27625WFF6MAUF\r\nScRbbljwVbqSqplb6yN3NhFO7AYtFCWBln8hfdli4yrhW9SxD5P6ac7yvNM8\r\nOTfcHvCyEdMzos85oWgmJkLQi7dgpBziOsA2t8aackdrU0MIvqOZPArjcsSG\r\nwHqkKMX1PULkudfRrhgrxZ8Kke3vmsBZsy8XGta/PwNqv2Wvlk/U+BWY9O30\r\ns04Say4K2X8gTGhKH4k7eZPIJJpz8hSuBT6l8cizuzT3H4JWZw3RDe2sHsAg\r\nEqp++1YUrlJCwHa0NWApuurIbCyfySWv+zcCRQ0qJxEZt9Qwzv5+5cLZSfZ3\r\n7WQjMonuqBVaTUxMfmco/VoTEQES3UDTw1AOND8cqtsDp95+sIMKoeH/cYt0\r\nPNx3zh7FqNuS88hpxZQfsMdrh/5OccJi6J94zfi+psBnyTO9/x/vocAtGWd1\r\nDAf57vwCNtLUu5U/+2Wn7NfWMzcRnq75F+5/9iUqSgBskIEQ+/f3EPiglPPy\r\nex8AmcxvvqAJcnnXi4bT3+JwxnL7ZTksBAOgC5aAPLM95KuSAl5221CV+OF/\r\nnw0SUmzX/aT0u1dywJmixUBa0/Tz09SvEL02QA4OL27woLLqXO0hlHiJjvrD\r\naK+Kmc8E9+zPlQXlp9+rjW6iIc7HxsPtTqA=\r\n=Z1j3\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.92_1680701196642_0.8440732621594398"},"_hasShrinkwrap":false},"0.4.1-unstable.93":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.93","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.93+60cd3d4","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"60cd3d4d3f00f0f316521ebbd109e4fd32debb5a","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.93","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-ctXycq0zAkyc6JRoAQ5yqbFBegjowzWm6bIfVK7poe6P8j3mIlL4ssLO+l2MaV2Y5zQZhui/chy118Ym+0W4Cw==","shasum":"eebd0303a85001f0e887fe80c3eed257c3989bce","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.93.tgz","fileCount":81,"unpackedSize":300116,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIB24wbR7cHPrIn6j4sLjjXXjYp8MlKToRfjZOyhYyrQ3AiEApQQ+cRR0fDkxUNkpCb+lGZJdRTZm0Nm3nqqJOcQVrsk="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkLngbACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmpupg/+IP5a0ChI6kFG/LGBpuHaGtflWT7WvNg9kQb5s/io1RcWqBRY\r\nmAv9GGGI7lIMc0B5pReTXT7Vg2fZ1yUsVL/ZV3TcdBUydHwMEj8f9C5OW1IW\r\nzHskdLWw7jV+U8QdDjxl6m56tkCTO9yj4XYGEKsNH3Gjf2aN96PEGYmpdy/8\r\n420QP0d6fvAOFR5gxplrXTc68F9541EXQqd/AmBHpA8hBL7RkTnX+dfiEbb5\r\nrRTnohrDY0UZJ8AVVDOU+2aE39BL/iqbJemEpzauTy+PlOVjXh/P7WGVUj+k\r\ni/4I78O8vjRsSl12KWUl9ZWqvuXPYjWATubcEEGKV1hxW/MZUY4vhvyugnJ3\r\nHRRontfH2Ph84UwqvY9c9RrpXhMoJvMrL4J5KrXtCUymdPgsMfyPxzG6fDhN\r\nSAXLu5msXKiSPmxzAB22MOPmqiUjOPvk/zyBBblYkfNxNkwy6PA7n+hXCjkf\r\nHrZwX/kAtzDeBGLg8L8EhPEGs4ksw0Ve0bICCObiQch9BAWj+kqWjw2p138f\r\nebzc9tKupikT4SLPGbbII9QOvsZyoJK8vp7eCXXTSafzD9AfsB6baFDFN52y\r\nNczREuyL81CO7ICG07qvC7LtwcgqKZPYqCU9+wkzvsFoRx+G+vOGINwLooV2\r\ncxKtUeQDOaYT8fH72SKspuMiSV23neCAJPM=\r\n=jFra\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.93_1680767003167_0.14975243230769508"},"_hasShrinkwrap":false},"0.4.1-unstable.94":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.94","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.94+cd55d8e","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"cd55d8ef08c3aed63b122daa3c5acc05819259f7","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.94","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-/+ZS2HHXcZTiJ40Ajj7+11W+IXhREEbd5eeQgUjr1m0mvOD/LJf+nmXGU075Qnsz9fTxv0qBJ/gtCJG50lYWTA==","shasum":"04c7e05e9d5cefb5a3e20eeec5bca0abea5e2498","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.94.tgz","fileCount":81,"unpackedSize":300116,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDoe9W/HzT3Y/5BM+XjdbC9d/h+XKWfNmSS3Jr3a32RdAiAT0q/JHfLGFXEs97gPwVgAHJq/wHj0bAnbh/00F9HsKA=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkLoZYACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqRBg//QIu1aJVC6MM2glFmOSUbKK1WtMkxIkyDfXZChfPsCEJn/z2K\r\nAWNhRhU75qBhHVv/6V0J+fVHVqvLLiEbjjUEILYpbHb+gHKFAclvD9LtwI2x\r\nTTJSltIBY4rTxF3KqDRelW6kq6H9p/w1dwS13Xa9sk59yaCeSx2T801cVb0m\r\nD3mLX8IeOxVwf8kQsP7N1iJsIa2/f7KdVbFIcLHyLPsdaFG7ODgqqDxdfJL5\r\nHah/yP0qD8imQtpH0nPeUzW58Y1Q+s+OdZw+O1O2xOsxZAzyRs6+Q2JCMZnE\r\nQx5XRQKxmMXQo6ZxR1cDhWffWSSQ1P2nffbpGzJZK7/7Cxfgi0NolocmkCd/\r\nq+N26F7+0plX7p9Njgr+mb8KKfh87jlKxAXB8vjnCzkMuYcn7vJ9wfpiHQ8I\r\nw98aJx/1BJNWvkIZgu2sq41WfgyLGVTCmelGLBLqSjgFqARbpIevmqoQyA5I\r\nC2PM27helTZtb6jyb4mW9Hu49bZjL+f+5doDDr/PghLGUxPbseDPjE4xahUp\r\nAjAfXu3+/EtdTNZnEVTTNCUyFNC+hC7QHd/KL58TkGYcMLJP8Ou8tXK63/9y\r\nPfZlS8F+xq5+5oCGRvTXAsijtVdZpKH8ownrXshgIkIKnIMppDpjyvTFTczH\r\nMxmv4ZgPZenim0dk2shs5G5Hz5z8Qef8U9E=\r\n=UQpn\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.94_1680770648374_0.8859671212518587"},"_hasShrinkwrap":false},"0.4.1-unstable.96":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.96","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.96+a7a9e4a","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"a7a9e4a99d41fa3647482372b36d23c1595ae80f","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.96","_nodeVersion":"16.19.1","_npmVersion":"lerna/6.6.1/node@v16.19.1+x64 (linux)","dist":{"integrity":"sha512-AB779P0ETW3WpZY2ydeTbJjvxy8mvOmEoSvFrCflmNQwVGuttVCa5xou7cY7jh8uT0WhP0+tkgvmApxnCxFxkA==","shasum":"79991e7b9d1b8130a7d5d81f578a655598cd029f","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.96.tgz","fileCount":81,"unpackedSize":300116,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDuU17RAwSj47c6awXWFdtUgfF1R0z7LbcTHnAEkAtXewIgAN3vYoBCGD3zhopbOdpstix/jskW7UWNqwo62fxHIjQ="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkLoqzACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrqNRAAnLSQlO2SniPZ3mUSw06uQlb4VIABFbr47IW0qyz0Unng48wv\r\nOBycOqVoqe16UwdYPeWh2Z9mWwk+oYSlr7xM51X1woE/QfT73L+FwFj29Yrq\r\nenz+elmZq6n4kLLVlqMJ5514GButHJGiW1uLHj522RrzxnHUJbtbYQh1zdNu\r\nxQIVGZ8H7O6XMQQRqWkCufksCUQ5dgt2sqni9d4O7oqPX4+qQ+ihmreQSmW/\r\nrbrmI/T7KWzqAPCq0CphERB0VDwFDdMMfnQyCiZwsFeKkVQn8o/W2WNNS9i7\r\npiV1IN3O3/GprcwAWFhmasA3d0o6kSNtZPk5yFkB69PZda69dBbQ0mXuAs5x\r\n7ZWzgztCkTXABWUObD4OzoiVxOokj5BTHgn3DI5IL3Omm9FYICpfiuxAjG4C\r\n9+MZAJALfPHAr563ZH+eMqqQfzY9/m1ZaW6+tFselKYjxniZvIHXAFYzkym5\r\nrcsEcfZ06tV1pvdgOLZ1565bZL8oD4x5h3Ot2s58IR8ogoaq1lj4qlDj69pf\r\n28dZkuSAEcZ4QdvhupCYjwNrO7n5PfcOR3ppxcSQ/Vm46xZdGXsaeSORPXl/\r\nCVXg8mFt8qS4jOQsqtg3zXfK+fuxRlPKQyakOGIDtaJq2tQ/0dTNO5d3N1XR\r\nQfMOtW/sqxlxVO0+vahapeNcEmFHUDSMA+8=\r\n=X3rG\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.96_1680771762955_0.45552893608942346"},"_hasShrinkwrap":false},"0.4.1-unstable.97":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.97","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.97+dc1defe","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"dc1defe9e90f34e6ade6d99ecfd21dc4d69d476a","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.97","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.6.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-7ClWJKJk+BPhJtUwAaqnSVaJqve7EYDJym1poAS0Otg7ch+hx8yQrQERSYDKX0IpM2bwqBUS1Xkum65V/RxJ1w==","shasum":"6c935b42d9ba14ffe257abb2ec8433cad1d4f0c9","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.97.tgz","fileCount":81,"unpackedSize":300116,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCe33y//sy1ahzXd5tvue46ubnT4qK+d7Gw0sy9Uhlk4gIgUt6IArv7j0zFmXbR6mq5vd1M6cadC6tw6hjmYdac2DE="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkLozxACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmpqag/9EoiKN6CxKsZr1z37SY4b26vBhkzcKafQE5H0ANU3WeJHf2YC\r\nNMohHT3NbLpJLaSKl2B66nI/7Au3fr9lOZxHJ3cWteKtsX+DIPUESzs0a3O5\r\nUgZsBREE0TTUpab1VkVTXmiwS7MDYLffCYKsIcNGnYdtk+BBWsXp9IdJeopm\r\nEIBzh8JIRI4Fu5JY2ePL4uhW+5YUAHpzn7q70/gFgpZUPix/KukpEuDePkK7\r\n2VXrDrfMoATBHPZNKfGVSup2Ve0PLA97Xyag6UUma+ZZ7RPFH2JrEKKhF9eo\r\n28D8X7iyxYGASrGjmzd8sKix4u9ij3Pweq5hw1KWv0OHDQUc4Zuo9+PorMHA\r\nIWUsrm/FfW8kyMVPdy+ivVtq52SoxxFWLSZts04dPEDvxd/+b9d8yCyAlzSS\r\n4wvwrIoyp3WIPQyDjKtDjMAMqjWIkfYfs9jNvFUJ+E//6djkTl16rzewkTOG\r\naQo47q/1fFq7cukdMkP3V5eLK496IGiOu0sFQVGXJI7hyV3h1gnfNyXA5SED\r\ndZB7uJgcWSe+8pH0IOn69Zn3IW/7S2Y/2fOjezpQKixntU9z2aFx8zF7tRxN\r\nvTzdDR4ZJaNu4qQ1Wl9Tgl13qcuuZK4vULqGJ/OrpfieCH9x1+tJl80qRk4T\r\nPR1OO/+k25eVs5w5z0GsQFWzc3Iqo5CqSeQ=\r\n=8rCD\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.97_1680772336916_0.9191454693153063"},"_hasShrinkwrap":false},"0.4.1-unstable.98":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.98","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.98+bd1569c","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"bd1569c8b8b1404d90db822ecc8925a2485e46ba","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.98","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.6.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-yVmGyUwBmGJSQtQN93NQRqeSthep9atf7YYIub6TwJKiNtf+4rXgLhuB6IGA3CT5Oxvxq/b3ET/dUiUwqHt8GQ==","shasum":"34abae03131eac8de562338cd82726b910e05a51","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.98.tgz","fileCount":81,"unpackedSize":300116,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHJ9rwVZzWZCXAGyEFOAWsEufQB+3o4R53zoQtkqu9unAiEAyaVQwIO2rbV3mjPeueK2ntjfLlfsvJfFIIh8yfgE1TE="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkLo46ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq+Xw//QbUkFq2x/cIFuoWyyriZ/ARSLpxF+5Zc1LWHO3HW5FSaIJKw\r\nZ0NOp4m13uTq+cvArA3/aPpieV8z6y6MBjfny7jo4/OrViC1Mg1OcZlDV5v8\r\nKfiGP19IxD3XHNvIKRAf7WqpFvztLXVXZz8VFD/0PP1ShGVPnxoJGkYpOVGf\r\nsBt1nnDWVpDuZC7I6SleIQhk+RYIpaoSppOQZmbDSwdEYS7fo45NC310kk+1\r\nOlUW5UrWPSkfTvYFMQvZoFvjvkVWf7XxCSmqF1gICGENBlocvOIcu/6EDFu2\r\naGMQNPo18U4vEBXwdsuktnswumMR8ZI147uTE41kyVGrUZCciKJQxVRBmICO\r\nzH3ReObQZA/fWinq4Je+qJCX/suheiyl5ekXDgFdT+/rdcXQjZR4g0P5cn01\r\naCiow4IWq5VcjdSFbW0PSTUaAoEbqhtRP6E9YBAW6B29mnylGablQB6XQ08H\r\nIqeefAcn+nCoyAilyuqx+fEBZ+dxFT/WeQtWASqbJ+yI1ReQXEJ58un/pDCJ\r\nn5jRjX0z/zymvjR0eme4rD+IU1QScJliFfXI4T8ZM1yKuk+ofJejcL6fw0VB\r\nzvNK3IrnPla4mPiFmu51HhmxtDXREbj6yoDRqAxl45TxmI2pvnIOEtphn/XC\r\nzvRSLM2XRoE1Hp6SRhWIC5uoECdJIy0wN6w=\r\n=NG4K\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.98_1680772666189_0.9721975524798723"},"_hasShrinkwrap":false},"0.4.1-next.72":{"name":"@sphereon/openid4vci-client","version":"0.4.1-next.72","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-next.72+eee9ef3","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"eee9ef38dc83b6437523d23cce929758accdb54c","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri:\n    'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n  \nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion \n\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n    'openid-credential-offer://?' +\n    'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-next.72","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.6.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-7Dq4atx8n5SOB21Ta1aCQjqYiEz96lB5e+shyN8IWhiWtIoXjS7w/7ot+CmXf/cAWnsnBFYSqEoj/WT9NU+tZA==","shasum":"cf59eae372834b2f23399dcf48ea4d1f44ea3af9","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-next.72.tgz","fileCount":81,"unpackedSize":294581,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICOQefCYVuKKHrH0tKcI2MeQdhNvEcR6URrMkw0S1f+vAiEA1YABK1EP6UIXAVSxfjLcJHNW7XDwtTEPrZjI2807ezI="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkLqqrACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpGXhAAoHXfxNS4ixCJ8XzyQw4Ky9BRf5aOdA4usveZdkydUpzPe+eI\r\nT5ra196gKRCO/wbekOEhIxEakCaHQ+RWgm2U1PNpPaebY3BWDMGKZG70kEJ1\r\ny1331dUrmx7T55qbmcaTNxDRB1tVOTWdv9H8cwu+aa1jNHjZKpCurN7BZgG8\r\n9MnG4YgsATdROTHARwVLzFVvMvoQ6wgbfP1kVgoqOojBQcD+xVpwQXffAVgG\r\n+5PM4VpCj/KaxgAWenz+yZhf1YJmQyPcrqEw7mozldNSRw7EQh4+z/jGZZ/S\r\nyLMbOT1molvp7rO+RWHWmWf/O7NtLjn0M1y6yFrJyn4SxD1zi33a/+JvfdYO\r\nwLvMYJt0cCcE0hI1rJbwuRf8vX6gXZtoU+FnN5t5xJA4YeglPRwmEl21MCMh\r\nwVogG0B0Qv2/iRHOF8hnc+TFj97lN2lgd0Gn9U8cV2jw1AVMqwRRA7aaySSk\r\nPdm5blHonvOsTkOOFx/46uMJoL7YTmwMh4thy6dGnacV9d7ez1H7qzw8b74B\r\nNTs4YpROlmPOdWpaUieoEhPzqGrN0UDCr7On97QFNq8YBQngrhR2wt8PiATq\r\n7qvEsr7A/6n+R7qOfwsg7/rKRbQjIgi2bq+D6hamIgGbL0FT7mXI3QV601kX\r\nqR4lXbegw+8F35c7yDl+MaEq95UhwEiiW88=\r\n=b1JH\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-next.72_1680779947291_0.7683321441768247"},"_hasShrinkwrap":false},"0.4.1-unstable.99":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.99","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.99+a87dcb1","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"a87dcb1ec10ea26a221d61ec0ffd4b4e098a594f","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.99","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.6.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-t8aCtdge7vmeYJ283bdXHWgu+eyJ2b1FL6xYrNGP8zRGA8ceU47SJ0MLh2XSPmAiAuCg0NjR8M6GkVHYY9W0xQ==","shasum":"70f65e750d2255bebb5fa5dd2ba4ba0f6b6f8513","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.99.tgz","fileCount":81,"unpackedSize":300116,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCtg6U6vHWygKCOKDktPsYBOATD3BGAb689G87+6/v82gIgZnHDQGMIVGki2pFy+Q355+o3obPW39XLf5VD9PM+/oY="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkLq1rACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqFNg/+PrOADAaPVY5FLvhRUVxClQRVWnItw6darmiiRYp/QG+iuMWz\r\njLYxbCmpFgWmHaWkFFi9y6H3E6Ss/2rLIvf8d3BHdZvYML0INFflEtjyIO6i\r\nSMzSiWLnNlemthlMj43vt+GvMH/mgAyKPa+sjJv+X64rm/44M4SoSoWCP6My\r\nFYRdMGjsXzcY4B45cxyXov6Gc2v3nKKyHvcoNoGbO4eOGMofPuEN5mZPCLvb\r\nhvT1VdD+d4B9IbrO3ivAxz1JJBFkiKsB2auslJb8R5mudwFeLTq8DSlRr+ey\r\n/kD9ym4bG1jYhRdibtwqPK5oDx7jNvgYzfvlE3QMJJ6dMEJBxF4aizz62/sN\r\nxnNu/O3HKs2LEcWfjVVdQNQNF9tmutCXG+AZ0fb4waMmuHysrSxTsId91Xc2\r\n04mW0VNlwzwp1SEBUqG8VWSe7AHZn0FiUmFMDF9uW/JxV8wWx/4I6J71quhI\r\n5VlB8E8EZM0k42Ag05KRFPGmZtPfaOJiUN0YRMQeLxtUfPcoTeEZP0BKxA24\r\nW2EzhJ/wX4KHpsuhR7a5W37NOdj9RN52Murz5sQ55TGTAygWKWRZOZlUHOj+\r\neE54KgxiHRIDgY5QWiy9rcvNB3KpisUnWd90eD/3PuERlq/vegAnBxkXINmG\r\ndtCp4DbpECHIaxuHN4LAtuio+ouctEPU6OM=\r\n=qP+6\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.99_1680780650984_0.5141712082483598"},"_hasShrinkwrap":false},"0.4.1-next.106":{"name":"@sphereon/openid4vci-client","version":"0.4.1-next.106","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-next.106+d6ae8f8","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"d6ae8f858a4b56b7c0ce813cdbf12d3925925971","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-next.106","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.6.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-B5CWix4cCVziaupViggb8uw4AzNi6LEdZpdhhzUcQ1mE7mRuUsQbNs4PBl7v5U8djFr990eS1wr/BGNoIUkhwg==","shasum":"2b63e27f1608eb3a70929391451fd3261961aaad","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-next.106.tgz","fileCount":81,"unpackedSize":306527,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGWVtBIAAYmkHWyed8VQ6wxguyT/iWQ+996VKWl+ElWDAiEA+GurmMz7K+yee/jNnTTg/DbBlgeEZxqJtbvlBGo+R2w="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkLz+6ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrKcQ//TdAcBJIFOkwAQJ1rJI0yb48e5lkliT94mwUG8HhM+Ua3lHFC\r\nKzCz/em6pdvc8OC/FC2A73bXjlfMQwf7ugxd7+EBgGFk6ZDa2xcdKv3ayc94\r\nP/xQoH86aPH17q4fLMAanTIFa0th0thyZ0FD9OO9tzYxHByBLw3kzQSivrjz\r\nTYWtXPwKuuhdfQqKA1WC2xsmG5ED+3c05P68dM8hKaqFCZyk08vwO0/tkNO4\r\nXBcAgPefwQttKg1aITtrVz9kEmCz628s0Zkn3DC5AzgL+aVWfcvKFiAlEWtN\r\nuve5VIN1Kln8cAtgNkKeuePxUGkaFewW9yBf4fpU+wmhk0Mfr7NgL5xshIs1\r\nWuiceLqHMy2I+V6bW6OZIxPaGZ40clVv2pMNqT0M06qlS8SgZ2KZBVcMfGj6\r\nwaLxHlFub5IbON8XVWpF2bWnRHEO+Q6yGI9zvcQ8YuaVe4P/Ahqc+s84SvhT\r\nB1JT4SEJ2Ve0GKVWBm2VSiNAipwMarP4DJgmjp6nDzrWvJn/pVsDruDZDxyE\r\nX/4X4t74ugKb0JRMK3x2Y/PSIc9fZjeI0d5eSXWcRjx3gBilcedfvC63NDvm\r\nuSZk6STzn1MDb2WZeu6ckywVrRPz6OPB6REop6vYMeS9bHcwQ6NMtsw+nAxE\r\nVv7BGKzfjFFB1Vvs66CiFfuf20CdcP4iyZk=\r\n=s7PY\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-next.106_1680818106346_0.05390416357764094"},"_hasShrinkwrap":false},"0.4.1-next.158":{"name":"@sphereon/openid4vci-client","version":"0.4.1-next.158","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-next.158+f39191a","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"f39191a94de4190262d1d64a5a08794858f64ae5","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-next.158","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.5.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-AbSoRlpJLI29nveG69/XPTicBPHXpdjy8ihA8hwOlM2oAH+Wgra1i85ifJ8VdSPsJIrNLpNCjZ5Umaz9sMNgTA==","shasum":"924260ca198ad9837c30cd2ce9011c97101458ab","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-next.158.tgz","fileCount":82,"unpackedSize":317145,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAVbLCORxpOzXh/62XN/otpQxOxmfF78yhDzIDGyx+eIAiEAoz6DNFSUScpCs0tx2DmN0uW4uWXFWYKqM5+seEg+2f4="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkL2g1ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmo3zw/+LUJqkhmd4sC9OagIRQX2fc3kCYDalySiaf41OR0BeCo8FQG/\r\ndSuP6cxorfMo0koy+wK1wtEEPXKz0/eGu5Fo3jfSiy4L4NLrysQnGTYVKsDM\r\nKHQp9o+Ii3zDI1fSxZkqc7yaxq/qO13G3N46ptFx4YXQLJ3397cCknbMt6Am\r\nL6DK7mPOu4+zOUNB1TLnOjFOFOtnjGHO676YgacHcJXjh/ozmFP3dduO8r2H\r\nXZoa4LUCHbfq00hcMQ7M0VNoQ0fBo4QKWSCsNY0KgNqgvl8rBxuORmmzX4Pf\r\nQnctM8ONR/r6sOrT51JtdN+Gnj/23JM6NTjhDoDFLqd3WnwqAB5Ca9ttUJQu\r\nt5QZoBj9ufJN/a5Kx86643s2vQxzHsBJkVc6CLicmyM7dPXbQAbHlqg5FtUP\r\n6JuptB0doLxFZJI1ZH2uCQwEmtfJekGKKH657mKpOe5k3ZxWzxkiiMf2WgXT\r\nKExOzj2GfzDeh1AxZ0UgWra+29kVyqzzioYWWNJcKltyxIPXhUWoE3rC0u3l\r\n4tCSgsqxJdUsUJmsU8jfE79eo0aniLiBqi5Rqs94ky25YV/Os+n0Re2UyBPf\r\nCsh+02tfSaRzcMKKOP4kfcrKtY33pT/KF8Mn9pNxppPn+a7SWk5M+r7Neps1\r\ndmt5msRiYpVTZZB1KspxEBPSkpb4E/A5rCo=\r\n=+wGs\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-next.158_1680828469419_0.34725394772880147"},"_hasShrinkwrap":false},"0.4.1-next.159":{"name":"@sphereon/openid4vci-client","version":"0.4.1-next.159","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-next.159+a8c3007","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"a8c30070a2095246dfc07a7e9d4838c30ad78442","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-next.159","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.5.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-ToAA5g2YsGF4C7LN8F0jrDlbxZT6a8sp0R2eMSAJ8pOZHKl6z/GlFXxQ2S2KApiDVaoeipRSPQepHUfYMzptQw==","shasum":"f47fd943d7a5cfda317ac703ba5e7462a0656979","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-next.159.tgz","fileCount":82,"unpackedSize":317145,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDzKDTcFLTQexHhFy42fC4+pkOA6NBese0ROzFAMtJiEAiBPZBkSMw5uRYj0Cxuo7GJEl73ggcmrJYuYqHP23THUvA=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkL2jvACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqpHA/9G0Toc1f0NLBIKuUULeq7V4f2paRB0U0CH3rSt3vsAV7gs0KD\r\nFghUS/Nw158MupNWUYUxIF2wTvgUcq+EZAk3XYh7JFHKQv2Xm55WLUw9B+l8\r\nL8MeGgWHeilaULreY4lLqD188/HB7LZNMYNkppRIQHk41khz+5Jt06fbbMxi\r\nqiXeAY17Q0wY+47+fXopaoWlbZMmsSau/FYtTdsP5kPlDbTo5/LUcRz5KdID\r\nDCMOpg7M9eSR0DhA5kIjrVpOe3g0JaTMijUWgLTEhZEDGxzcxs10kEw9bOzX\r\nNjrfDUukn6Rbh7DvqnnGWdZqeLA5rRbHCwOfZFwvU6OXt1/xb2S/mcjrT06f\r\n50r1FaPRyuVsm08kJy7mHOycXWqjxaCVWpqGenhz61CfTNdPtERRsXhh6zOG\r\nO6y/zmd+5Ff51J76iKvrOr8+VW7ljExRzu3a63rIazJzNz8rykqCHymo+1vy\r\niE5hsPJVBRzdsJsAV00WU8/IzUKQv7CG8h/imMfLfqiczzYfTPFWqu7yRa3g\r\nDY4fSRoAAlRudc/1BvD4h2nr+WrMECNg8DK7jkNLlUrz35tkgmXqGFaef/aK\r\nDPMzsJq0SFndkIwLr9/KSl0+589rWRbAMg9B7VBo0Kymc6cgnJCcLnRVT6Rx\r\nSRaoh9Vyxuu4GN6rX1adU1ltGrfeV14QpmI=\r\n=XU8z\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-next.159_1680828655568_0.47242905092816256"},"_hasShrinkwrap":false},"0.4.1-next.160":{"name":"@sphereon/openid4vci-client","version":"0.4.1-next.160","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-next.160+d1d0b47","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"d1d0b473b7bb0e08980b478c55d7992b3ec11dfa","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-next.160","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.5.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-9DlqWg7VB9YSqqr7H4Phhe9TjD3VP4M8MELNbY1V4jC11UJZvb8c15ABwIZGBIJdNIUKMTRu9zUfkvN7+S5g/g==","shasum":"bf34cf433cf61d7555c5849773b51dd861eb2bbb","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-next.160.tgz","fileCount":82,"unpackedSize":317145,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDjRi1CxxnEkBW1kNuPmoL8w8eitL+ekgiawQSe+rBnYAIgNxgeCnYS6SnycumdWTLVoZ8b5xJj0lGh9S9Cdv4D8YU="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkL2n6ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoeKw/+K2YslERsqi2AQLqT5UFgk2IqXLc1a5YQcrEzKgf6ucckVKw8\r\n1vquLp5L8YdMZz7rcYiarLId2yeKA6Pn1oqHmLL374NtHsOXeJgnQ4czulCz\r\nPlv4aPN7MxlTGN+K9kemotYvExI9CYqtX0LTVkQjskK+uaGjchqbJKhggRoD\r\nBMKfVc7hypjwgmosKoLCQOpk/EsyBxOcKYrYPScQIO2AuSC5YzC00DSo7TGk\r\nuyYRT1iKYZwJQGvOwvNKMBupXVQMcMrm61dXCRPcfyhVbEDY/UH2JRriNuHe\r\nTBSKayfIwIPwGt2Mxt8dCobe+cFDauQrJ2KwvqDbg8Hxs7N+Q4XjQmCdUg8d\r\nIAVmlm4OtkFlEdBxtAmLsD+HlRhPYI5sZawyASYsixb8PdXMaZJr8fe0h2z1\r\nt+tXcOmb3E62A59cz61cM8pjM1IpLPmTCmTBQIvvlM71GQ7apRAMZ40wkS59\r\nRhoU64UqrJh1v+NA6cIBMXlGIzxbe1s0gmlKkXtPGUSAZeef+qLhjOZ7ddjq\r\ngk6Ot9G3z6pnMzmv7792yrWALrDI46AI8U6ca4JCqzVIOtOOOG8HN/HepiEs\r\n0VB48bfZQ3q/if/Yro3QwTRW9jfj/62HBjrlplIgdcqILOas+DS9lZtnq32r\r\nHsjrXtVcmgTI1VOV0C1guJZET2/3NsKHAnc=\r\n=ihZT\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-next.160_1680828922355_0.7830577950774444"},"_hasShrinkwrap":false},"0.4.1-unstable.161":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.161","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.161+f1dd6b9","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"f1dd6b93a8f20be78e5d93f1a390413424d8317f","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.161","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.5.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-2mFmGOtUq9fEtN74s38aII3n7r5F8ZzkEuTZal4eDals36b44W/DiOOKaY1BlMxXUH72nps8KliFBWaT7l00uw==","shasum":"48da48a58bfa1fbfbfa25c135fd54080cfa0f071","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.161.tgz","fileCount":82,"unpackedSize":317268,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCTxWT7e/vquJfviLro9QaFZxDrrYKAkBxVW7PN2bRm3AIgc+9lrhtkOQtZgvO7xAg+HCqVhUgyoLM8Rn8JmfdWzr4="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkNXDRACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqzpA/+IHbo9zvKcb3AW3ueus4NY4Ok6MvfIBn5tFk5CpxrQ2lpkP9e\r\nA29w5Lbb9bk5Sex5NNUQHDmfXG9wTc9mmSnbUVltxSwBgQIbatns15FNx6KV\r\nlPIFDOvPHe4K5FUY7gMAkoE5E5gD5ZpLOBZZ2SFFxsvTgxSQqFSesnrz76ez\r\nY+HPCDpT9Qw1smo9nqTLsbc4gUp1+sbLNT+yi20Rf3wZdPLNxanTXa1sx77s\r\ndAIwgkGP02SbRyMGtA7lP5PMCACNt9oZ+3snkFq+flCNcuQiSEaKGBgqpTzD\r\neRlbmRE3857WuQzPl6jtMKo15mLAU/YR7pEpW6U6cbiPQiLb8NlcHeEzefGk\r\niS3mOp4lCMgVL5WTPZgLN+Ssl6sciKsWGXwLJItxV0wU0ObpFaoU0/FTRunG\r\nwCnF49MY7GkwI3dVXsxODaAxxQReqaeMyKwNW9Y0ApPiNU6Pbwk7ri0rBggG\r\nVVoR16T8b/P28e0hEO0EJQGqht1VvPE2zHLmJyU/SQR0AICUwzZbTBF2hns2\r\nUhJcr8ammbmzKRZOw1CfJ7NnIfeIVF9S3xHd8NoaaZf0BThPkb4T5IBq7oZ4\r\n1EHHp0m7PsESEIZfJ0bFbnmtpdV/AwGlghjzqgSokeTPK4NFp7VWzaUvAGv3\r\nwUCt9QYaJ64gFwCMnEa7vS7aZkeWeO0s6rE=\r\n=vPfA\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.161_1681223889403_0.544348949925225"},"_hasShrinkwrap":false},"0.4.1-unstable.170":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.170","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.170+3ad95a4","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"3ad95a44ea734f0b00dbe07aa11b35cbf1499f92","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.170","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.5.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-9PhwnqLvO6UlTNBQeFMQcLjoaFUp5TJDkPK8BENT8jxEw+s937JbTtu8+k5TB8AHJWmqTMIU7nErHg7aDhNSoA==","shasum":"279bc0cde0ccf10592de954e381f748e81cc5556","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.170.tgz","fileCount":82,"unpackedSize":318175,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDEoL8tPqJW94FlRA7Hqt74VKw2PBOWjk6syuIBZH4f3gIhAJMeSt7apYJlFtaff4SThvdoGwQF90DSpGyZJPSnF+tn"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkPUiwACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmqb2g//XUEg8d8HQFYG+qSBX0lrBYHRpN59IZNl08yM5b5p45XNVc/S\r\nLBVyln3bKhoQpnwj4b+Mt94EQywpoPaqcAK7U6xeswP9aoYI2b9K3j0SU38z\r\nQwkajSfVd/+XMs8M9WOvULzfRYg3kQwPlRNYHS+GKTQtcuyCsK6HQNSPRkao\r\n58C0zRale6frQAFgDjafbGFkxjX6Gf3gOvBkQbmixLWnOnhiodDvThucGy5z\r\nMKpJIHrOBnC9oY+X53oR+xU3ZsDv0nR0E/x57FV5VHCNG31h6jcmEx/6O+Ao\r\ns9kSRwZmiO3rL/uV5vf6LnNZF4Us+KkEOExo9jxZCeEZkpq7nWabBCnBLvpn\r\n8Hs0DyhHnASchMCiahOAp7anRr1AteF7VKgSFoq/9dedKXykTRTWDsvTkmI1\r\nr9L+IIJrJnZ+ZOVWlKXK9qH62gzsiw7QmbmFQikdutq6XKVb1J0Uj5P9zhHV\r\nK7HLnVcnfVbTaTU+Qh9pVZmNPrpfKZ6a+u/0shk5J0+KvG4xb9n4ECxkfzvC\r\nkyR/wq46bFw9ynbkGVHS/PELka0vpOD3Iz0OX7ZuxTvh0eJ8WfHzKHqeJn7i\r\n6i+RN2dfCQrQ6O7ayavhOxStitewZgN7NaXtrE0WjMkVmIKesK0qSzNYzFDm\r\n3Lhn7/0jf9eb1cA+UiVsONLpdD+tOF8Bjio=\r\n=nPnT\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.170_1681737904317_0.09979961423665507"},"_hasShrinkwrap":false},"0.4.1-unstable.171":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.171","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.171+e3a3c7e","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"e3a3c7e4ad803df67f8003f3cbff8286dedfe8e0","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.171","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.5.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-z8TJ4qQPN0YnXTD5uB6LHDqAUFYfQ+d1Aft/6i8NGRLksQGkqNjAIQql54Wu6WAtthXt9QpObTGDPQJK+ADf2Q==","shasum":"70ed78e8ec316ded9b27fa01d8f671d76d00118d","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.171.tgz","fileCount":82,"unpackedSize":318175,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHOazz+TeMIF5WLbOwF0PGRgvicfNL/+D92LTZiOEEsZAiBDLlhK+q0nKcM8M7Wml4O95+9RFLfa8gVZhXoEi9WBYA=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkP84RACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp/xQ/8DUt1O9bbkjKrwo6uTeTuHZ3M2cIk8IWuBjfSItQ9uWQb2pY+\r\n2zi0d6b6cZV1Zk2LlHXcQW/OtB5sKYgZkSyFGoh9WANv7GDamg3U7ZTaqeUZ\r\nQtc3zC7iG5n73xQsLA9t2khycw+ZLUY9OvTpXzEdPNji3ueTI2FTn8cPuyYu\r\nn5oumdHRPE4lhrjNSZ8pJbfj26pZpRpZK4ljVIenVsiaZEvhSF96LPJsEtpa\r\nnD30rBYaVEe/P7QlsjrdAT4RbBI6CE55rhJy5NaIAFBqKWbLN1dinuXn6nTx\r\nFgM/q5vYx/hDuSJ55EpCT28JjxMwnh1cHuky3m52nmh5dFlv42lfu8P7pU6K\r\niM0NgIa9CuctO08QvXJN0wVfQtobh/l/tHko7oM5RXArKyag+TUb2JHhbAEQ\r\neHR/dmf3/SBFkKQ86pq4dYztnY+x2RxlEN95hHzXg+bVUCGN5TXiB1dWponR\r\nR4b1teKbHVs2io1/XdcYJvlKareMtCQStI2gP9DdEFHw7Fb7go4uWWMuv1f+\r\nBXUjZ9VsQiOPYljmH+R0SkfXKo21RIsZMKwynV7mlOKwds54kyMdEUaDEX2i\r\nudVoZ9XaE/i0lBLpvaDcfdb6+llAf8MdiEfZcWjC7DRmtvHAMNsGKdqhOJEC\r\nEvfZN7Oi7F4IlTLk8AhID0xIA8hyEAuJsRI=\r\n=XH8w\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.171_1681903121192_0.2391179707832154"},"_hasShrinkwrap":false},"0.4.1-next.162":{"name":"@sphereon/openid4vci-client","version":"0.4.1-next.162","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-next.162+e807ab6","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"e807ab634f99e0ca729f6413c1062bb2fc9dce86","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-next.162","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.5.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-iCq3aEL3WaOz5kcSVkKYM4Rweu92WBOpoWGLLcZR2ryWJGZP/OQMvP9x5Utuw043uM7O37G65mZ2D3w2QfnL5g==","shasum":"f9d01ffec1f10071fc46b63a1f7afed1c173aad4","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-next.162.tgz","fileCount":82,"unpackedSize":317025,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCdjJMi75I+Ayw8c26+W0kql/rlzZKNYtXeXuScYvBgrwIhAON0fFh1Sz4HR1DH2FRHFn+rhcZJwAT6L78/kQq7IEzD"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkQONBACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpGLg/8CCnLeRqV3+IB2Tc0VzdT4jR1u5OroJYt/qnkrlijqhKGwug/\r\nknRGOkmrH70J/beNhCBiN/fPM/TVt0UmY3Ahds1jWNmXztYFIKWMg6bZ6Qk0\r\nELc+ojqOKKenDWAgjPCiys8LFCVhwZKT73w3BZxECZiYgL86tsKb1quBsOzz\r\npTM336wCCO/l9dVWD8Bk/+vXaYd6/QfeYR7fZeB6WZrR9SQNBQ6LLu6J54Yx\r\n9UqRcyHQQNK7LimH7VKubUtZ0yyqmMuES61yRknbhDDrIGIKlT4RNgQdJ1qN\r\ng2vfNiEDUOGgvGj9vUUJQVxNO+3XqFjJUbBgBgP88qjU213A93eWYasea+un\r\n0hYP13m01e6fwgjArqrZu5K1OnhtOfaImE9tt8OK++6rzu5qTlOsl2fXO5bl\r\nhfcn3cSt9gSpK+I3esPR9sa0/xlfy0vzuCAifnVpMj+sMYhw3N2hbB/6bPus\r\nJKMtmB/vRW1FcAgy5+wRZ110JceCPPzGiV/i8enCDT3s3rc3VuFiL4XLWhsI\r\n5zjb69FSQ506pfcf9fsRqcA0l5CaXzTYxhj0d2XRrDY3K8RtiEDla1hGJUsa\r\na7IClIgH6x/MZiKuVMBDeORBLo71J0haZBvXwMeijPfvslior9yYlPhkgcHO\r\neTaPwWGxdFUAZZPUtNpUi2czdo0lhgxpJtE=\r\n=WJjX\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-next.162_1681974081766_0.18991136622101923"},"_hasShrinkwrap":false},"0.4.1-unstable.172":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.172","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.172+434da66","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"434da6632cd4e5aacf6daa038652bdcb08afd270","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.172","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.5.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-NvatnJ2hgIhg0cvsuVzn1cexhVxqqZbPAJXRTyAE5vTt+AFzvIh+xQxxktG650zVAJf+MzwS4zuwFsTTvxXMdw==","shasum":"565e340bbe1bd634307dddc9ba70e14f09c5c287","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.172.tgz","fileCount":82,"unpackedSize":318175,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIH/KRBmRjWNWYWvu3D8pCZlOaNsullHLpQNMCctmuDZdAiEA3/eKH6RkORQUfvIuZl4mnwNrJvrr4oe5t8TnXh/qd1s="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkQPOEACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmo6Iw/9FNGK44w5zLYhDiTc3DwwFXat9K6uJfM0i+UKFA2+r/hLWc0Y\r\nxSIbCGE92tMz4CGj6pIbH6aQisuBQShp6toWxfXf4WrzgD/C4QkGw3f89qK5\r\n4q0Jg8RSTZGdRiZQwytDE4gZXKUywKG2ux7WgZgasr9tmMj1kDzS6CBRVudY\r\nJtan/PFWLn+u1L4iHuTSDyZPUNs6QdcwbgqvJJRsYhZm9hQvJSNWUB8XycGJ\r\nSY7rDHyIy2fOpDK7bdBK/Hc8ma+/Ty8ZmXEWqbL93z1GXi689ihh1dHVnMRY\r\n5wuFg2lMIawyK0NIe5r7mY9TPImDGWWV5xbZy7QSa72X2EM4ztkwq8WEWF/W\r\ntabBZamqDNxe5VmEIaUfRiabhpfhjAYVf7uV3QTGIu2UVEat7gXX0iWw2/2A\r\nN6qpNJSOoPt6cHzFP69RPw2dDbHMU9rQ3YkQz+RL0L8enlq2Oo49Ke1zutwT\r\nlb2fTg+HC4dxoaCQac98oSkroY8A48yg4wG6y0ccLtbxnuu8Aqcubv1FjJ4A\r\nATBcLrNRuYHc09KHEkKL6AtWNZiE2brlOE+S3uTXtfv2B7ighyys743Q+e8O\r\nPrjQwvGdBxnJnyAjGrzpxSVnY8aXKWhhGECyK7SEKhKtsWd3gGW2JfN15hqG\r\n4xfh7PMr13Pg9IQb1OBKPyy1fCbL+nHkObQ=\r\n=51N8\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.172_1681978244333_0.008967010022539412"},"_hasShrinkwrap":false},"0.4.1-unstable.163":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.163","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.163+a6b1eea","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"a6b1eeaabc0f34cc13a79cf967a8c35a6d8dc7f5","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.163","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.5.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-FUPSS2gsaOky5JwYqM7dTYMhQCcm9aK0gytlpwmf+LPGACsJcvM+v/iab0JxDwG0GIu068HSrmys+5NVz+Gxzg==","shasum":"2ff4f64eb0cd12add2a20e04c6754d82fcdefa73","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.163.tgz","fileCount":84,"unpackedSize":399533,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDc52/G8KVP8EumYKmaMVBH8s3APx4VAFo7LRqFyZFNvQIhAOHbyXgHLslC66zyY+Ao8S0Q9L9+EO9e5fjAiGWXxI4C"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkQP2YACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqxtQ//XQD5H6k+92kfjgBBDWvLO2f9JvbmRqBtkVHzlIQ6NMhSeeIi\r\nNUdLtGHzolnMmGsphTn2nQ+Iq6Eutt+jk+xfwLNaCznYQZYb0GjKd9/TuGeX\r\nK7ECHTs+PkgAWYUAuGQPpmpT3dgC/erDgL/6JplN7qdaHSLS0PfPPN/7aslZ\r\nyfURm4oknO2R9g0JgxyNbKAx7atwMZlKNMrTDJ410Wpq0FywrwSmH8+3CCUT\r\nQ5K507lzXUT9fbJv3Usgmxb7TR9bzw91t4+IpKYIjMh5+f+w81hihg/YTgcH\r\n+X5bUwziFcALAr2H4OWiKdGJrx6/YI2caiANd5SnVbbsfcjcONBlWm3PmFzb\r\nr1i91mKm1K6bi5uZybvxQQm+/5TJduZUxEbbQ7kIH9/PYIC2ZFyXhTnMsMFG\r\nM/E7XOSE0yQwN5RYkVtAhNsM7VNdYb8cXHb6lINxCGRIwa+ctPfjM+NLPYfl\r\nG1JS2Xr5hE7dmuARIsfrAwvhDBPO8vSzpFhWFaXtdUzBK9FMZYKezn1v9WoY\r\nBcFQ3+KwNKRNIJCV+zxS4p0mSNEZ9OYSCSZhhdQ+gTqvgutkpv1/ikr+VtIn\r\nD+W/e2rtU1cV+5Bp0k/55Zz6M1BrWgN/jvGzS1KqvXpgYrVhnBRsQSAcVuZE\r\nOjsGxk2N/A6YeC4fkB2JH3Ra+q0mmFUlSU0=\r\n=d/Ga\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.163_1681980824750_0.3393365739346177"},"_hasShrinkwrap":false},"0.4.1-unstable.176":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.176","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.176+881b8ed","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"881b8ed6cc35b56706cc4d2db63b47db7337f13c","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.176","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.5.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-VO0CxDfAGfyF7NlP19r4bXuPrCNrkOvrlz3IQfpi9l+WvabOJ/vZK9d8n5Y8/EmmQBE+IqekBjxstxo+h2wpZA==","shasum":"903ff3e97348b09ceda26aefa15172da3f59e8be","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.176.tgz","fileCount":82,"unpackedSize":318133,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDudiI/AjHI+fEG5To7ymKyQpTdw7ngh4q2DTysiDQKHwIgMKb60lj4s9ymI7mD9WXYv9SWPF+FzxPa4k7I6kEomWQ="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkQRLxACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqiDQ/+NBSglS7BFYugiS0NzU3QNteA4ODQRgRhZ5zQASCG1wvP7FFw\r\nd43C8QZCmcyjX35gIgSOPqG4v6gmrvPAoVUAMUHiePS5VE9joFI2oLNndvDz\r\n/MpEuvAGiBgwfyVaCHbmza51ohcnNWSGvWl6rQN4ZTPsEpH8Bx0bfGaVqoA7\r\nlF76bAfIhmDVia1U5pVkMy+t+skxr9eNqSw+X17k8xGzNWYInR4CV/D7hh9B\r\n89ITpM58HlRPs2V3981HfibTkOyyGRh4t8NaUfWWXd++qs2wZPhhSsLwYiSZ\r\nqbG6H4yssQeI1RYRDVa81YfLeC1WVYBfghwJq8CiO7h8Lv9TvdY8MXp6aBrr\r\nVUY48b/DCoJRcMly6umMhvE5ls1mdH5iwjYeVzCm7MIl5Nh62mWNC5T0WMqe\r\n03n2bg7YeWQAxRLCyPAFBoR4+jEG6b2I5yeWd5A+E32MdpqQ1ZU5a8fGdtTA\r\neEU3lhN6k3dPIzbOSCsnfTyLjotuvYTElHn5ZpuhhWYkrqLLpMgmmRz4xrRX\r\nY+LKuz7zg+oGYmY/NUl2BJXPY/GJzzwpgLx96LVAZhnXMlToOemTM2uGJo5S\r\n86UATgSlKhDfd3y8w/loal708f6IKodKHAcwSWM3j1MvxRSkF6+LoKXrbgoH\r\n68wZY5dCPbPH+xbaX1NJUpvOh7yoIjZB6Sw=\r\n=ZEPB\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.176_1681986288680_0.9425423207993808"},"_hasShrinkwrap":false},"0.4.1-unstable.164":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.164","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.164+50f2292","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"50f22928426761cc3bf5d973d1f15fea407a9175","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.164","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.5.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-LfScJz2P3o80BpW1Dff2WR1jODK6mjHXirUOQtwia23t7tITljSLG6WEg4t5y6Yyvjp53fwIzW+3LW59aFPfnA==","shasum":"06b2b44cedfc80c03dc781be931aaf7da3817bfc","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.164.tgz","fileCount":84,"unpackedSize":407092,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDrkJhfEzhijsMmgS6XHmVwq7R6fGoHz7T2LNbATUcirwIhAK5ysDggx1d8mE7rb+k743kPIiT9vkEiqXdiufEPakoV"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkQRfhACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmow8RAAhwrUHgaWQcnmp40PPfNqasS/BHDssWN16hs2qhCP0um2d88P\r\npgZsbFaKIIUKw0bX7LVQAOIf59cddRJRFMRelH/Eq/1lEgMnKfD4ilu4qq+c\r\nCvruPLd+IrSxYiEjMgbvLhnp8wPFm/ccBB89icf6LGPAVooqxlbu9e8FgbWC\r\nxz8o4s/JS4tiDygeN2dn0gGzuXbMX8tXFq/OpMixakpxFHunLqR2WDwcq46h\r\nrLTNH/z9xnnd5H5AR4xttB+9If6xzJeJlpeN7eX8JmZsAckyDFVTUyViIr1J\r\nZz6SLTqqOjU4FGQUkCDFyLs0ElNVu69opeGMsfkVf5dk9ZBfIcbT7tI1D2pL\r\nF2KA5TJZR2vIPaoEP9XlDIkkfEogv+OmDa8WFVlz+ZK3JZKcoUs4pUqG7LId\r\nf3ghtxU5HtHDcIZmSmKIGelFUDOFWy00lZ79HXWwTyPqxY3QqB52bCFXd9VJ\r\nK7geUqw9Z2nH5APWfOfhUVbeU29Z89zX5B/I/iRBfzjWLzoPLIjtZxXYTf3A\r\ndqzr2Vmi9Gna3lNGOjnnF99IyBeQkYisVPkxDzyTkis3Uv4WdzX4TemUN6Zf\r\nzCDQHfLtqAoQKItw1NNKphBgppV0KNlRYKbVoinHtgn9Fwyj0+3tzZsM9EDO\r\npIPi0DmyLF+1mW6r3JVFlZ4k1GMlMMZVTaU=\r\n=eeZj\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.164_1681987552862_0.5589517944682794"},"_hasShrinkwrap":false},"0.4.1-unstable.165":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.165","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.165+1c445e4","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"1c445e4a1c5cf8a069724c053f7a8e0cac2cd22f","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.165","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.5.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-7zgHZcpBVdSWPb+EYwcl2b0zgHt/rEKkUaPS241x0SMC7sEwcWtpsMOJgaMFFwUDwb5XAsFOvW98eCMhUk9bFQ==","shasum":"4d6a749afa09c5243fe95ca51fa0be8898778065","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.165.tgz","fileCount":83,"unpackedSize":366401,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIH/e2Qg7ts73uDydRzBq8dplju4krVTCALjqfv3tPDmIAiEA8iidINiZf7iBFdgyUcthPf1Je0fm3frTVbrUVqVibHk="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkQRm7ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmolORAAhy63ieRlCi2xPvbQOP97TsvZ7I8/Dpo6I+4MxgDZPpAUi6Ux\r\nq73vp52SU9XkgVOqgZLfOStflMmSndd1gdU8WY4r3Qx1Qdfwr690VZZD3znB\r\ndIzoE17Y0HW2ss+aXX18uhdbbzSctjpvGl/5kZ3M9FR7HmVHFAvi24BIF0a4\r\nnLt85bhbdLORLcyjm8YwOrM6JArP9GT2pm+gjhBbeRWNqpBhF5FiofMlcZnh\r\nW48HnUH0fMmNsJtTu6nwwVhj7BYI0DonZUzvMqgx/xZekTUIhcLT151BNYNw\r\nPhkvSMJRQMGjDAA5gSacrBkJQf2r3BAIj4m0Yox80ggRBVKXRwgVR2ny7gAT\r\neMBpmmX6GrQTvGGwG98ZUZJZKGM++i0yFQknjMh6tLPuDy0Y8bjauTSYGugP\r\niWm+f0fDHa5soLgEAWURFoyzIzhBYcOKW/Cchtko4YFg/h9X4ozhyFzh4fLE\r\nIfit8JDEK6pe0qCrpdJb/6aT9Jzs9itLi3RwBPzjeo4XABrwxvQZQ9OyNCCu\r\nKwNUvJgkdfdn9UEmQMkgWCMHf1i8NA0obOW80X2JD1+eyUNO5959EsMvjc31\r\n55LWVmvmQPBuO3hxbJQF45ANm6fqgG5ms5B4YydqfUSso3D3AgfwJBwE7pYz\r\nld564iQ4FFNOGL/zZkj+qdtGvy6tHhG8nn4=\r\n=i67r\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.165_1681988027235_0.29635502076989995"},"_hasShrinkwrap":false},"0.4.1-unstable.177":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.177","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.177+7a2f348","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"7a2f348e1b417c7fcfa6274e86a636cbb6d4c9e5","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.177","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.5.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-eFZwN/IcQm+K9WAhnfpcZboDahM+n7DKb5cscaN9+uIbrSw2qJkQoYjFmI5WDJ3wC8bItkagghJILYCLK2PeAw==","shasum":"77a82c7cc900d1230733a48e4add87927f8b755f","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.177.tgz","fileCount":82,"unpackedSize":318133,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC2BePKHHkaJqbBF1Ad95SvRwTfadVpefPQjbcb7+DRCgIgG2+toIzzG4xkbOmchKFbCQjHRt/cGclpcuub/bes1IA="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkQSXCACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrywBAAln00tnXL66VzJwKFF5m/1BfpeRw5nW+CWvp/MDlSWJpiJe2E\r\nhOUdqbM3Ug2OLlqJ9Y/okCoCvBcbGVl0KQ1Bc/oevgvBlfrkNwnp9SYgl8z5\r\nDmu6bCAIRPd6S8RV1j55HZXkryicmpFqIlpl7h/6ShrCACJfJ2IhMsKfDx9j\r\n6SZxpMXBVjnQ5PV4om3UzQxwqLrxWT7zcOiRNl0ThM+bRFmrLM6pGScT6rKe\r\ncWl+lujg2+TgheXU5KeoAhhoIgwGFlk5r94s1puL8Gob9nbLURULB3HdAMdA\r\nLO6GL0V7zIuR6ORPlKmUBQCxhZpPcdStZU5/Gq6gXmpKma8scEHazbJG6gcb\r\nla+zqL63IW9revIh3fOp0HsTyBQhC3QGM48XXAi7eK7ZrtKg7w1yp+KcQ3w+\r\nlYZ0VxL0vcP4oz0nU3U7R73uqmz5vyWE81jL93syofXynBrAZLnEuLahG2un\r\nvLaA5nwdOthllCwbZBrzz1YuwvLu+aEk1ssJBdc5Xg6Cpv+I2vIQNNwXQN8t\r\nZypnwXIcLOOR3tagRi/EEDpCSVVTt9KAQDQWlJwc/V+add/H4od+cmMEQjZP\r\nE6MJ4PLVDr3smyomghcjf4BjgBYdQ1wtH4e7shRGKC2LdDlRrg7n303r35e1\r\nzLVq1bZICyouRclzoQBeTtWQmOWdKvkefP0=\r\n=fU3k\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.177_1681991105894_0.1574876532963443"},"_hasShrinkwrap":false},"0.4.1-unstable.178":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.178","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.178+9f0f8ea","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"9f0f8eaf770cdeb3d04d68793529081223c460fc","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.178","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.5.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-09KZje8px91KsPsx2cpt3zzsqPEW1jYIGjyQSLQavg7Z7GZbg6Me4M6TH2RYU8TC0JpqCCR+RTBqiJdPfivV7w==","shasum":"62da64ff5ac12f6acde2a729b0a9ed0d35360c4b","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.178.tgz","fileCount":82,"unpackedSize":318133,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDj0psALbxN+D45TbxPjtetDz2mguRqSTySmHYVsNbCvgIhAIOexJh47aLXUwBCGInGBQbI9DzoUvp/FmWjPABKex/N"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkQSdyACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrbvA/8DG3OVAkS0whpLHYG6joL6Wh7KiTtbUzE8kiaYMwB8yVCimOw\r\nUQZV1adwk6nahm3PdWQPpGyQK9SuUNT+z7djoweA7nzUJJrhelboEhhEmRor\r\nfo6RSEIuJfIFU7KAGlOFdw+QmuHnpUn/4hlr3CdwCc2qFeUErBm02a+fLEql\r\nqULmS8RBT50EblzLn/B0CCHlplVtTl1Hp18ebkiOC9pNlu1ObmvZT1PomHbP\r\nwqQeQLnXOiCk/UxteNLQHVwtdeNbwIYOlw9aqumXIsOBCCVaRK8JOCsiunNZ\r\nXZwb5KuUtimN7tfXLJXWX6W7yquDltsAmkE09c9NZvGqLp4Bt7IjFU/1t3Es\r\n1Ni9qALAxpwTfForfGL2MbCOhPobupnLqtHD8CoU5RC3/h6ZWewwW4vuYdtt\r\nY9xtDTL/tsdegr6K4gRbER3u51cxMGhTvLdLoe9B8bpBg/LINItRL5fc7orh\r\nOgaZt4AeQsBQZE5+lYvW0APo6yVDK2aU9Rt517XyjDm2UaXl0Yl72FUI5FAQ\r\nviYi3Vn4toYQh33un1//A85rmQm6gnwPEqE0p9yCptZNvG+q4AknvGnOZQec\r\nMC+o1on802m+vE1BfMPPM27aUzsqli4ORpI/alwoGLixrONDCqxN3OALdOQ9\r\nQFbYYrlem0PXx2z4LkimtcGiFvDcv5Y3YqY=\r\n=yXGo\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.178_1681991537804_0.9714769842622921"},"_hasShrinkwrap":false},"0.4.1-unstable.180":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.180","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.180+a7695e6","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"a7695e68e2aa125f9554e716bfed0e2d3308107a","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.180","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.5.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-fAwnUFQ8fnZe24mMjA74sSpZMjLcI5f++iFVT3UIaA5xSzeU5egprh+GaZ00zDf9yTDGEemrLmNPy4Le6I8GOQ==","shasum":"26a8910038432cae96a3ae53c11cf1428a2d8e0d","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.180.tgz","fileCount":82,"unpackedSize":318133,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCfwz65EibYbJRlzfx+xRjA1Lu7p/GFn/+JU6xZbILKkAIgUjNGKdkCoPrtWrNUiebYvSOTrgduYAO5DRkAoY88MkE="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkQSqRACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmordg//XTyuhpe+qqLtgD+o9ru0PPnV/1ycDb+f0/PTCNfTo2g2Hr7e\r\nzQL7Z55Rk8M/yOqWxV7b1urx1AHDLGWRYdDaPI4G47nVFnms3y4ARatjRVm/\r\nuGK4O9yCNAB7m2Y9yzGH/9c1TtSKTeiJeXLyPLde8oXV7r6356A/ESSiww0P\r\n3rQqgThAtbuIuf94bVcs+f3m089PcxCWtAm0S7CeoFOPOWW8+fPnWY2LOqne\r\nejiH2lP4zkfNZ8C3wCnpzQJrOCxiuF6UKoLEPzXcKRerC0lRZIAvp1AcxNfW\r\n0SXgrTFiPTc8tM5o2sPgXY+PEGItlp8gRmLNhsTmZ9YXhDuVKf/M8F8DpsT6\r\n5jV93T6vZgnNg/hwuekU9ZyUKHIBt6p4rHjYv98LsqOlZSA97uDe4111izfZ\r\nLJ53HGb1HH1pImvd7EymAx5J72GsWpvpmnNTPvJltUr8HDTGx2I8qXjBqpG0\r\nWEV8t8QY2fgpXWLvqOAXkJbpN9UtlgA/uw5/3eIReVRSEPT3VJ+yZvtq+wDS\r\nMK2Ky8nXkE+hbwqvaFbd1IPJa1vVBoQ4VUlA3rRTthzx4IRC+R1v/HMJyiQW\r\nhT9JlbrAj6qXnrvV7SuVl3XZPM7ZPUR7RBE0sFv7/6Ofetft0nWH1XcZBIrW\r\nUS8dKWHgv2XMKQBIVEq8hfTPrmz6eXy27EY=\r\n=p+GO\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.180_1681992337465_0.41162943583296485"},"_hasShrinkwrap":false},"0.4.1-unstable.181":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.181","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.181+c410001","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"c4100017e150a7f7af4c17c817cd077ac529ad4b","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.181","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.5.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-YdH184DaDmuK/EE79TaPxRrM8IPUwF7mEWz70VwlvEn6idCg35iPtOO8EPCLMA+Yku89tL9uEc2e8eWkTLX25Q==","shasum":"34065924738db1ab1ef97cd113706de4ea3dd298","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.181.tgz","fileCount":82,"unpackedSize":318133,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCSR2HFoNWBZLftsvYai/tLYhtfpXHKH7QLZTcCpgGyiAIhAOL8tYUfoicLQRDLZAZIcTe4l+VaCnQ407aIMAlbQ0yx"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkQS0hACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoqlQ//fg737kZNbTjdE5awTVMXC3mxZIN2WHPpqBKxloMUo2wHUwPc\r\n3/CLQ9t9BJJbphhfM7oTOgOP6JO6EYR+4dY7EAmYanL8XAvov8LRSvWASMMy\r\nHe4ZA4KWj0D6TNVvRmoeTlEJaPPUFjOor6M06bmLUzkHWxqwClQwxGeo37Ai\r\nX7qZXRgP1ySODVn+cE1X4+3dIlf8pG+V025SKMIMjBvLjK5Kf4yMNZYDfaOY\r\nXFH6xlJMYY7zSmkM/KVyl2GUttgSxSh/3zycKd1ENywprvmM9hQiySQJ0hEx\r\nt+LZXbPzkG3mRyW7zpMUcfclnxiuDA9A8GsaA+yAd45/sCMLS5WbuWyWgohs\r\nRsa5xdAQSd3cZcxlYtl7Px3f1FXD6kKpzye2tkBib3FlEg+89sri403G7jxH\r\n6zPRFMYztj5k8+EriJyPur7aoeu+vtH/GDwU8DA0T7bA64xXSllkeTEsKyRu\r\n+k/dkAS05RbzBdLXs2JHZXClNDGLqmC79sqp8EQAeboBdfWr8XBoYRGE+EHI\r\njf9GLP3ZXZ6ywL+6P2+Z2+bzsli/1whCDB72lYg4/Iyu+qsl9izSH1Fni/zO\r\nShG7F2Guet0mt4J75xpm5Rb3UVdVAy00mK+YuyDbnwwPDhWr5IxlHf5V9k26\r\nO9GVAdh6lwBTHwnNotWPWLAJZ9f4U96AMW4=\r\n=So6h\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.181_1681992992766_0.14972699781844856"},"_hasShrinkwrap":false},"0.4.1-unstable.166":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.166","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.166+5cc5ab1","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","jose":"^4.10.0","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"5cc5ab10a4b5eb9c1741dc639f08d3613f9f45ea","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.166","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.5.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-ZxyIeEimGfc9uOKsyO0O+Rp5WyhDyFLr9w46v9t7U+adsWw2s8LQqNC3k3522ZQm5fM1YGUIF6qjSLHHndjpnA==","shasum":"a77dcdf9d63360cde188387ec8e4b2c66247c72c","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.166.tgz","fileCount":83,"unpackedSize":366560,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIB43/TyInaZ1WUvjJP0n1uLt6JfMsoIFvrvOmbKAF6R5AiBnOzVmK4FuGkzkJLwg8P8sTUvi2NCCy/dAh1gH1t3O8A=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkQTUeACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmo2MBAAkIRpycVLuhaKvqVwZXbhBSvgamUGK1DB26X5sGeekscqGsFG\r\no+Uij9a7vMEvXCat9xQ1A3cCfkW8EBbH5JsM/j5Bsqia1Ow/WNqWV5BcgHJY\r\nSBL+nkadhGB7qJ/m1Aexg/luZBvU9E2Ec6PiFMK6595Lgk6sG+g75+p9SrTH\r\nJl9ZNi1oMpABhyQ9dAgamikGLHgXpi30gV2JovH5T2+niR8g+GCyVeZhWnWh\r\nL3YYKLowX9w1crp4s3mySZpxE0u66JGTWNDH5hLyzt/oDZEEafRK+jndMft9\r\noks0GvjujEMygLv8Fll9ceNYnV5+1j+UTbIH1yFF36pFyF3ejGwE0aQYAQ3f\r\nxWO57NU+zt1396bOSeB88iIbTYikeKp+1d/eiEc4ZuhbMkLz9mbifRkP2OvD\r\nUrhBgQ+wZBdGKAFtlwX5LWxXQh/WLZKqXn/EWa+TxKV555QobZXNZnohH6MS\r\nphoIx5jGvxJaAZjHbACNZe/EoIavEYojqY3+SX7A0VQ7Ga4LH+MOBhkV1MkM\r\n1uaZxQaA/KWF0DugSgmrhCIvWqxuFV8TqYg9Cwn8lUrJPezU4KXRsGBZ/yYQ\r\nmo4YXQnRvM4Nyl2MvqcPZqD0d1tX6llaDlkizgKPe5RR5VT5u8wpIxs2cRHY\r\nB1oR2fctDdz0m2ByONfsHjj0/Ydr2dUmCig=\r\n=gc3V\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.166_1681995038130_0.5523830555540643"},"_hasShrinkwrap":false},"0.4.1-unstable.182":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.182","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.182+6a67c7c","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"6a67c7c696dc4cd58f69945cd75a94cdedac9b0e","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.182","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.5.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-okRecmkvfrd6CrY0vwu3dslR0SCkYE5gj9Xdek9K2ydtMyk5GsCTIkVZOW6Pi4gjfeZgbHGs7Md6A1cQNDrlhA==","shasum":"46cbbf2fef9d04dcebd7866d5a6d7e3ecf5a64fc","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.182.tgz","fileCount":82,"unpackedSize":318133,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCpP/1ucurmIHTXk0Ux2jEMWuW/zdQsPu9dpV5gM1x4tgIgTE/jTWXDBtzn4zd9tJeu6lFzERTlm4KlV8dqoFHPObY="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkQUG/ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmovMg//ZZktPtZPApZZiCIqY1UG8TyXv4fQMhmBDzzdedAR+2n2YiSX\r\npiq+my60sTCmrfV0lTtWr4Yksfv7z6+dOQYj1A0eLJItRtE72KoBJnmJ4hzJ\r\n6fE7Zz9j53hdVqDMyUvEDq4uQ7GMYPJonX73ptgKoSqu44qY5vs/5Vd+2f+/\r\n/3gMS/qEfGs7dGb+UBayIOhGTBIBVSV/Pzq/Ur6KcL+WStLIVykUtaRt3f5A\r\nMN8Fe63xO0hlgCVrTFeyOyEK289Np8kS/1h/uumRFbKcbg0HF7MKLNgBllsc\r\nQLQogFI92e4qXVai6w0EPEYZ61uqXJ6B3e3TvgseK5OBoJM4szYSJZXbFYrh\r\nmbzJN4wSX5S133ST5Mnj0R3+ttphIKqtQhVrrBYTwe0RLrP7O1H2O5CmAveB\r\nMrEPKyCrYe0mbvipd861emsZ/kw92UD7xbkJYx/ndtaRR/57OxW1zGC/6Dwk\r\n2+UXc8It9f2Dig9Gm1KgEhof1htB9YZF4ECttq3+9xadI+KZYLO0aLP9xITg\r\nlfyfpPh+VYYRpSLDq4jQ/AKTScE0DnutA+5d5Z3ld4oUEvmL/3QJSrX/1b9i\r\npItrvSNA5LKPR9Xz3Ea81+A9WYKaN7b15LKlMl9VM7y+X0f8yxN9j6y12+SQ\r\nJfWm+ps7RQqaneR128zIw7yYi/1Ca/NyuGs=\r\n=q5uO\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.182_1681998271137_0.5018308880198206"},"_hasShrinkwrap":false},"0.4.1-unstable.183":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.183","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.183+db4849d","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"db4849da33538cee3145b5717c1d2040da93871e","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.183","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.5.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-rNQ+SQbykfQGZKfp2FoOmmBqLo2SUgXMYgQJrvM+xToRWB9HbpYACF0nfPsr9nDqoeHcZhZF87YAaDG9pJO6Vg==","shasum":"b38a474f3a96a0ab88083664f55b8352b914bb4c","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.183.tgz","fileCount":82,"unpackedSize":318133,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHjby2MzffCnoaeSRN9YzxYkH6XAIwI5kNnJk1/OYy+TAiEA819xJ9lpDVI+Dkb50LhWahiM0fTV2RFwXkWAdscg8iM="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkQVEqACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrKSRAAjB/3ei1rOOWh+TWmY6VDdkPBO02iMq1WCerjGkYVzjCLMVKZ\r\n4Fpv0VAJBpnAzu4inIXHfr54OgTWUBeOKatDvTDab8v7/kOQRCwXycBmpuvt\r\nJ088B4b866VLm58gQldIaklKcZ5LN/66X53KzQC6/geW7ssT7rFSxtCd6ASZ\r\nN8EWbmt93N5SDZXUQ8q2iPb9APAezxXKK5oB5G2vu20Rjb75QeBgXwh8VJZF\r\nMGW3eSjTMGhiqJ8cCdrCHBSZP+jdJVaDfyOFdx/jpCaXGVplgAmQTz0uBW9I\r\nPjFF3ktlS5q88Im+836Hyhl16MDYpj6svao9ldWPPAXWQam8knboMsftEjDw\r\n+KnUIAv2ydqKcB9whSASNxiLzHd8IwKuu3aJn39jDdpYNLEnIKDkahfn1PM8\r\naMcYI7E35b6ZxeAQ2+k4tQBmc8yznDz4bLRthdPrD2R4o/Mw21yWKFk6Tgxt\r\nNcD4X++nDgjVItA/t7fkfu/3ZFiNzCF4jL/z27Rz1R7wmM3fIqcXIWVEXqux\r\nDbGhjQ9QOED/6/LvgmLdg9pxeW2uhqUzN1Qh38ZQT9id6ypLaVCtvBS7PeSV\r\n5YYaY8jJ6BGVTXVjsLznaMI8JL5jMNiriwD8bb4hg2usx61O08/oVOl7Anbq\r\nnIWKDLSAcu8maaNaGrV4VhakfHsojMm5Cj0=\r\n=tbrA\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.183_1682002218539_0.15024495349726363"},"_hasShrinkwrap":false},"0.4.1-next.192":{"name":"@sphereon/openid4vci-client","version":"0.4.1-next.192","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-next.192+3a0e6ce","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"3a0e6ce1feacc89369c9e257729680016550f5a1","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-next.192","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.5.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-aCkdQgl+TLSTXU3xeeaN1HbaPdAPSUAJStSSzCGOZLZvZaSiaHpXMNoqhhP772aPVkAluXfnjJKpZvX995upzQ==","shasum":"16ae4f281fec045efa51ce0fc8588d2bd76b86be","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-next.192.tgz","fileCount":83,"unpackedSize":367532,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDerDflPUFZVU38dBoUfPzy7xeepPB/YAKa4cxJ9UyfnAiEA6kRY5AEuwip8P2uGEqb60TkDDfkfiolFjBGvB833XlM="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkQVLQACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoP8g/+LX+j02AyFPWsstMYEjXN3l7KXYsRkurgTeS5HGFApP5f+5pW\r\nRb3cq9ZDo+0pY8hG20mIdQVs/KneUI0YzmYvOkae0Di0vyzStcqmUA9cO4ra\r\nbmQ9cm2pmIoRBJNfdi4AQc9k8xvYSxgcKotmOz5kIUXdqQ7k+/8BBWZXNp3U\r\nlopw07N6A0Q8Iya7cXbaGKOEpJEqKkG2J/sui8fxZeW/oqry7Ocx8i88dKoB\r\nKiSebZAkfaiMy68LWIjlnzLdqRh2DLtNWWFdufysyvim0wtCaRakAc0+GtC7\r\nGljvY/P/JEX74ENTr2IqAR6Soz7V1rdvHImgGB3YgtAV7kHsVT30+S9Kgee5\r\ni5A955SHeZ8TPhNH4H0CyKjvprPg9sJ+TrvbMDaAx8FRGV8IBCDp8Z3OgNBe\r\nusheuOTywwHADH5JOpTtJdW8Wpya/55NnRXiYVYy/eazAL44Ip76pMgf/APu\r\nGHdhLo0QGXhg8eYJhz09XmoTOhwAljsODYbrAB8uqKurKYu4t8S4e6VpCuoI\r\ndVg502S2NxpC74iY/SgTI8ucj0VrE68cmFaNfPf9fmK1c5RbgGVtlyKu+Lwx\r\nzwqL90Bg5o8GNsketPQ9liXJvDRf8YP1LYSGJrKmnZLoY4W3YA59OIzSvqjJ\r\ngGsRw53o4tWXTRWDfAcpIwITEHHAz8+CQQw=\r\n=HOZJ\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-next.192_1682002640215_0.4895279260942993"},"_hasShrinkwrap":false},"0.4.1-unstable.202":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.202","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.202+830c5d0","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"830c5d0ca878a7ef87a92ed9e9f5d580a6f962fc","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.202","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.6.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-3minCy1kj4mpmwuSREzlEH+rYBEA1iDOppTo7bMhLYHY2HKROOCHvDlUizAZEEAi1/BOIhmhKDeopJDWJEdfYg==","shasum":"09143bbb365c0d0bb429eb495687c6f463e75f4f","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.202.tgz","fileCount":83,"unpackedSize":367540,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC2I+3mff6xm/wMHU4B9te6HCiLRY7lQfsXRQAX1hYrTwIgdJ5DThVlbavC3N7XipH7fQ+1co/xdLqDZlmlVyruZzA="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkRmt0ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp/rA/+JpK0Wtg7i0qVIQCXkIQSAiImYjPNGIfLF4jGZN8xmjNFOVjs\r\nxK5l4PPSU/aRvqXB5G5c7LWOfYw8Cywwzo4V+2FBqv6PCvF+coduMWpW86ix\r\nRKpWAWMWszZ1VnjhwAbIQgL8Mt70L7jy9KOTZxA2vblelX/x413/cweIImt2\r\nUCmnP2gbi/Mu41jihK1CW4JjjCrx+5KQu/DNWRaw0Xqo80292uLaVJkt3XYf\r\ntdoYMlabXG0+ASNqbyH2+tHP0qovOU59S/kTjM38R46oZSe2szEtkBxRifv3\r\n6TBR/MtuCA1hPMleRSxrFN5EtlVA9qMCFeqtnKDcD85OE5VkhmG/fslH11V5\r\nA8QICuGGrhsE3z2m2CNSd9Gu5Ji4wTI0q5+EX1wY/ThN1VH1nLVqHX9Sg2CJ\r\nmG0gmOyU/KBVh/PX1xGevck/ldffEhnl7PuKWkqc/53k8q2ElZcn34dB6tkE\r\nPM2VOl71YGg991ptXT9pn2uMdFDUh+jSJfn9dy15BuzwI2T9RI0bRb3gYmJo\r\n6uLiM7mUudePeMH0rKDxhnEkAMiNLEujf8kNCTg3wgb3h52rxnLXjSzGuvLz\r\n7d95TGs4vnkWEN+qR+Wioh2MxPG6sAx9uxXLNVko5rsMeBQ+K30gv2d6JItb\r\ndv3iteY/2b/B1sojRSQ8NPgD0/ZB+rG+RQo=\r\n=LXEE\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.202_1682336628582_0.11295344144190578"},"_hasShrinkwrap":false},"0.4.1-unstable.203":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.203","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.203+dc30fb0","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"dc30fb0b37fe62531867fed45f8c4cda0824ac94","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.203","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.6.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-6yQNpajC2gb+ZQ8WTBVsIbuMSKPXr0qBmf64FAm6e27iLdhXo85ivfi1LGEfka52WqbNSsdIcBIRP4ZYfLmIyg==","shasum":"0d7ba6f7551f11b22c9cc81a36c0b3761778e0c2","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.203.tgz","fileCount":83,"unpackedSize":367540,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFv7amxRwGB7TcNSq4C64z27TXUDstF3PMp5BUNQRTQNAiEAtL2o7wpTzAwwnaGqPNP5PV/mIuRdZh84c3DTnFAtiNY="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkR4lRACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqhmRAAoJ7yLqyI94rN2LnExDuZPNll5n3SrknUcr9mWCSeWePDVllI\r\nwyqIv9tLsZyVizUGdvgPVHvid6elckDMc1fZjbDgCDKk8VBwcngIazn2Bj/E\r\nKp4h2UojxL48Aq9TEgOdlCPmKXk4rXKujPgqRuL1F4EhL7WTDkK+NDaT3fW2\r\nxp2+CjxowXEE3FHtkJqZJGwiOgPGHxqh0zmj8heG6hZHLtZ2wDFIuo3lRxfg\r\nIoNm+yDqweYV+aQ+VyvQXWlDkvoNfg9VCvZDDE+08qfoHd6PPdZ/vXXJ8jZl\r\nzJPNlyFtN0+Jd6yoSnwBcunLRBbH7d98+vRRpG0XfoZC0LOSAZlMWRdQdnsp\r\nEqvIik2FG/ewZPChKxeFGbU2pTwgkjRGTovepisoR9AmNh7WcoxgSwag4X1t\r\ng8RtOmecr7+W1YQ05AQB51XoiiEr4ZgDK3avI/fDUQvOdPjFOpqJcnpRddCD\r\nRd9YCYcaEFEBwHxRHQhW/Oy3IZ/hVLNnPnQhkICQBRXo1pp7v5VQMIfbLhRS\r\n7I1mXO3gYsWOU6piZmoL6haT7Bc1dMOauJm5uTjPFjh0hKJhH0PRMmxW6TgG\r\nbswn8zZrCblDoGda4OSowgAiaKuZMhp+bgkNgd3vmIDMmywRNz3KiyyJmWIu\r\ndDTuUbE+0JagOs8UXtmQCVo7WOt4ZC5nkNw=\r\n=oS+Z\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.203_1682409809722_0.5045997927567205"},"_hasShrinkwrap":false},"0.4.1-unstable.204":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.204","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.204+448befd","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"448befd90608ff3cbca5bfc9e6e725ff06fc1b27","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.204","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.6.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-K47lQosv3ncBIJ35UmpJRLpdpnfnfmX/AoWp25MLicz1j0RvuqCAeQxH5g/DEsdvLKUdoJrD2VKOVRhzbjScgw==","shasum":"7ef8f51a6a3a35f6d492c3e567dc70a5095770b2","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.204.tgz","fileCount":83,"unpackedSize":367540,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDzM36qHal8jPnJ7flc9uXNaRpf2Xukk20Eo7kUva/eBQIgb7+4ZYPbGQxQOSeMdWCtSw3ejFNe3J7bUWGtPK1jInI="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkR4r6ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqXwQ//XB/ehDJfEt18YBrSJjJHwrb7Cn0we6G1Ph6yC4XK0s+U8WE+\r\nDv8B+Wpp0YH0yIjSj7Vo4Y7mn1VGGBDAqPzk0Xb2/6WdMgWAzaLsvGMWQSzM\r\nCdQsfSPpSh7Mq089L5tb5p8PsNL9cQGIFcRPpOGqw2D7IOEb9JRi2BTzW1pe\r\nyPrs+bGFwIPascpi70k/B9J403ErF0s9YyAPFF8D/AeyVkqIm/WRdbCuqsXV\r\n8TUdt2Xc3h791FMJEpzKOloxMQgqQNueDVSrJbvIaB4ODeRVXvXARoWsoo3Q\r\nymvfOP+8RqVvZqm8/CSbmmwzieYrigdsH6IhQbKiDLB76ihLloxj9/N8L+Bc\r\n/WqfDxPQLe+lx/h0NY4sHRof/PPBgBvm9MiVmjGAIbmUrinkNVt2T7ui2dnb\r\nbUFG0dWMliGOirTnLoiL4nPssio6SRfuZU8tYmtvka1ta7vgWesmrtfqczEr\r\nGO0xmKNjXj1ZRW4d1FLO5KYxUe8/58ypQuBuS30iu5L5CzHB0zbN7vHxB+/g\r\nLKFhL+k88CfS86F73rLj9FbHFOWszZNmTaFMH6EaxHka1Rm9W1WNHcHQcxtZ\r\n/buaTESCCrUIEBk3mX0/kTAY4AlJ8dvrBgJCOuqPyEWNPvIuaA4rHz4/uduM\r\n/uGyP5qQiyWw1m6VboAzA69QUgvZeMMYeoo=\r\n=nqWc\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.204_1682410233798_0.8462582781390626"},"_hasShrinkwrap":false},"0.4.1-unstable.205":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.205","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.205+8630f5a","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"8630f5a6fcabb883d4e55ac730c74cae581a09aa","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.205","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.6.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-+K6X06fBDS4cHBAIIemnsB+OFqLerrNY9KbzgtTlvX0PvOubK32baSw0hzNEapqsVrJHsn273jcnbDXEXWMaqw==","shasum":"4913fcb19d08c8866b6ccbebf7fe6d98d3f2bb76","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.205.tgz","fileCount":83,"unpackedSize":367540,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCYv7MrQSGLxJTiAnrr46lFDNGcAfBi5TkaZx0CsjxAJQIhAJL/TPqL0oOpoWG7JidkFYE823M3uwAfvC2eYzEe59XD"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkR6LOACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrrIg//a4oJiNTZr46CQRq5fkzKIBuAquoQ8kGpKKFg6fvs+DesAGJZ\r\ny/dkFriY+Ei4feYBpR/T6OQDZ46ApOUQz48+uqmxOHRZQiwunAjvjPxDYBCo\r\nOAVAtHDpPkVz9vVK9BnW0WnNM676f9lStPOMHZ6vU5OF6fP4YRADmy8dDgbk\r\nnLoz0B8cbiiiodWokUF+KbjF1bp952jnTj2m6AIUHKuYmYfyp/Q4Il0sZRNw\r\n4GsZ19z5KY51TcxrTLLKxNj9bw6fZJZQB3QMPDbCSdYt3mUYPbLAGBLM/KOA\r\n6fIRqPN8cgYhAkLXiyrIVZgOT30nJp5oX49tlWJ+CUEIESP1JQ6ZP7tYLsPi\r\nHpRQqvmHugRHOqajrRJ33PRVitOR9ZZmpcxCtHInCn/z3jWaGIMrLiy8kKJX\r\n+pS+PXN9yP7ZkybBdwW8gINfbqQwzusZ5Ze/gs6i6co29Ka+TNiqcz8gkDoc\r\nHBsKYJHBNhV5I1U1FR0itcZc4Ua9vTLPVziXHpA4Q49ZVD11lp6BxkYcdifl\r\nzwTldx9GCwkB5Hlq9xb2PFXPyWUUPJuv8nw1ySACeqdUMm65jRJQ15n9bhlb\r\n3cAsOhtj9Yh5TygEXlpZ+d6mMoWQb2Rz/xLofLoWy4Ra5ddQFtb8Nz8Ebi6c\r\n+ha0mppiCwhU/LVFZ7ZCH1BL4587nSQM/yQ=\r\n=MHDJ\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.205_1682416334108_0.04016251539352189"},"_hasShrinkwrap":false},"0.4.1-unstable.206":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.206","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.206+31f6f44","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"31f6f449e1190be3658a9f32cc220b80985b93ab","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.206","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.6.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-fu8EwFixayrY40iH2ZUPW863Md1QZOzflc4TCyj+N9Oy4KrXdXcy/7xvE7X4nfYXeiPbOq6QWQycW5JRl37kqg==","shasum":"fd2162ca06f91b4e63155e99e6e9c9501b301141","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.206.tgz","fileCount":83,"unpackedSize":367540,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD2tHkiVGyp4HA1aVG7AojowpOdUo89kGjakGY19O3wwAIgYFcltSiBz+LQbQkiFXIy3uSMurMvLksYq+62eWVj0xI="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkR6NtACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp4GBAAk/Ihk/TamhB3XY/h3D6piN33SLibhwHqKuJyP/lR3ndh+Bhl\r\n09Lg4XQnx53TXZG55jj7CTODXU48SyaFYPa6gRNOpWCMkuQvghyl+I9AWBDb\r\n6zeDwEGlwv9C5lrO/Ot8p//iQ9RKVETrSUG2emN0J3zhNaF3MP5yy3D31BJ/\r\nZbimiurYXK2Mjwfs4kWlm1GaTL4I5o21OfkYeIKLxB8AYzLRNRTjANStLLHq\r\n/Ua4TySK3U0IktFLyNu5AAdq5JgPi8g4N6CjU2hy8T3/tKm6rXz0nVBqn4di\r\nCNLATrtFfgfywzc6oAfzDXcUoLMSd/xEd3gjdUx6bLUeVoKJFoivubw+G7WF\r\nMNhOTaALQupBDfPBU4/osYKq1kVuEDAj27d0zBv/IBLBYqpBlrTxk47qWbOj\r\nWNBOU3hHDiimlT02pWK0sk/qrWZrRy9XpAEKgf8ase7Amx6kvSS1QAxrNq4W\r\nWcsc5Ve6OYo6lKSIDqok81Ogbb6jHuE0M+liANjzhgO8BE9cUlzmNcnmCJk1\r\nyLnhwSnXXSueQrdl22U9TF0JIZ+M5jSwwn7Dcpggk5aRx5wHLNstWT3jhg8N\r\nGVS9OEhyRUHNX5VqVWR6UNh6A8vZoh34N/UFn7YC1Znm+8ZXTD9T5oR+4hht\r\np2inkB2n/x3jG97n5z8dOx4ued0jaWWZHGI=\r\n=rvS8\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.206_1682416493507_0.27293791863076855"},"_hasShrinkwrap":false},"0.4.1-unstable.207":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.207","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.207+a20be71","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"a20be71ffb67131e10e03692984852df2c8d2877","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.207","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.6.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-Vmh6kRsdTP2yFYltt+tG3YoM9GthW4dC76FIv1w9FsPbRpU5A2WghOdPcpCXCh8oOBRloyIwLkvjBHudvAsC5A==","shasum":"1296a1edb6438c327446ffb8ae263008b139a954","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.207.tgz","fileCount":83,"unpackedSize":367540,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFsatIvnKGWWqmzdEZgVTBPy4VnIUbMunDk2ATXjSBKSAiEAmMskLWTXbwqIib/NmoADY/lGwaOpReGWn5QvmU8yUVs="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkR8ijACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmpxsg//Y2Dc9UlOhHuffICNhS0/H8QnS3ivZuqH9N9gDz3rEZdEjTEG\r\ngobezOG9hJvfZ0sDio3QsrHYGcJYHffoMZQbWTTKwdFicIgupHyg4Zov1cj8\r\nzacj6Kg+19KZzfOd8jLwF8i8oFQVMIPPnyiT/UfOCiUX2HuD0v5IYY6Gv72z\r\n7Z5Dzwnkdwq9kkFyP2h53c10kISJdOz+mgfVv+rq5B7K+NDohTwzrwgvqR3N\r\naVEnhh4GOk+ai6lhdilk1t33fItsPLiBfFKFdTcxCz0gsuO4qNezkQjnThUp\r\n5cVZSKIqY99Z2kLBNHCu0pP4B4V+YJeErJIG+yOji/u8PaXLxBgGDZnRkkct\r\no++9DD/pz1j9mD1pj+dRqioiOyWmGhF2UIw/vF5h9y/0YMxEwt50EhLxGvH+\r\nCa/vZD1OoZjqJBZQQzv+AffZyfYlrDiOqvBrVh12s6RIFPc920JhJvnEFVYX\r\n8Mkv42Yu8BxmBuzzKDGmp66PTIccFaMT65/B5WFeMAUsYwQfA4rC1fqkAOFc\r\nmA8EXWoWjgOqyls0wCY2CPaohfTdzfm6Ab07aAAsAclgjCYtMedxfs09/0ol\r\nf+hZKfi0YM+AIfM+5Tz8TfqvbWWLODZKqmeUBlG2MSJ/BkwJAcKyg2/ekUVV\r\nmTW5QnGxmdB4df7jF4UoqqApZaVdvd+CzUc=\r\n=VH7L\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.207_1682426018876_0.22762216203148"},"_hasShrinkwrap":false},"0.4.1-unstable.208":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.208","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.208+862ea76","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"862ea76b4edf3ad0fc6458aa5898b4b7e12f391d","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.208","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.6.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-5z6vBOKN7glieAmbaZnOnxnHlIwl3B+OeTrxRm1iSxc8rLb6eIdV7I2OQjHBoC7B+SQXEId8GnPCbSieklLekQ==","shasum":"d1b48499471b990bc7b9ee0689e780f9dc42a59d","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.208.tgz","fileCount":83,"unpackedSize":367540,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEk+Ff5p3BR/CZHeVezvMGkxfTC/ySk+7M0zQRp9aQVaAiEA/eBjG2MTgIE7aItiaekzMCE3EzwTf5tYVJbkZ51tVeg="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkR+mIACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrbGw//dQuWyMaR/4sTQTzv/t0cn56KpthbJ/1fH5UDF8fQLbAB4ZVy\r\nDcf/9wbk6h/2afNUDICSskZEZiS1v/kmOCyQM4O9g2HQsNmawVtnZFyLk9xr\r\nwu2y5piL03LTkol/QyR92rIIYh/jNp4A6jlanWtwk8hd4/BFmG0g+1aZuS+4\r\np89P99ZHZ0WkNfpkOf0VIx7ZwUgXEO+d/iSNeye/Hx8uu7nUTPtfjZG2UHYb\r\nT+mFM91L6bUWKDvLsMRSGCjy7eLfoib/8Y6IekuO971dHpZ8rfruy+5iCW0Y\r\nZJ0d34blQ/h1rbUzdyaL3/PZMMMDnSTD/MEOW24tG+FOfjg684FBmAv2sYem\r\nZkOzkOecV4vixD1sQgqNNQuhclbvX1AL+rULScPwlG0s6qZayUDXGu2nwoAH\r\nhRNhshju95f+IyCm7e4f0gsKKj17Nv9VaTIcqUfXFqIgVqjuww59NoArR5wy\r\nz4H8BdfSSgQUd+yTKIe7+zX/AZz9VTpkpO3lFttixpJFnHSCHJ6PoL8MzP86\r\nHB/ST2AS70/+/mdxgNj84FlGhQCrOt51rDWif8IgRDMp3CHEDuqWvcxA9aBL\r\n3FVTB/fNLGkieKGaMoM4BHM+td+Tqq6zemP6NvERw+KoclJsn7XsCLRjAW2Z\r\nHx97rrhXYNnBQwxBUAIw3NMQmbueCAizlMQ=\r\n=uFPX\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.208_1682434439888_0.8269494845371672"},"_hasShrinkwrap":false},"0.4.1-unstable.209":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.209","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.209+2cfce17","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"2cfce1784f8b71594e026f91bf906d8f20b2fcdb","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.209","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.6.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-rXUf7sBVCzF49U/ye0kwqhhv4R3bP3V1OW9/dgkR46LXWFqhflFI40ZMQ9297DZ6mb8g0JKoD9WFspBEIjwTtg==","shasum":"eac77d84189e8fb3bb212ee7bf519d148a3923c9","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.209.tgz","fileCount":83,"unpackedSize":367540,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDJL+5DPCrjEkzJUhmzKv2tz17JJzdkPZQPjl3sRlGQSQIgBI1BQLNd+eZ2XhJHMjXfJjzNmZ/h3EOE0mAazY7X9Vw="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkR/QoACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpzJw/9GlEKq0acLwkiDIg00kn7u3TXZfGpXmjsT29ZDmyrPqAkOX/7\r\nDbHpjGAMI39lcxN89g0qRshW2O7LRY0Xxv/6JYPlaedZinFhR2IUoJVNsTws\r\nLnT+y3wHVGbaMwGGIkAwOh6wmJeOa0xGEQKqmgfaoau2FXSjA8Jf5BB/eTxA\r\nih0PwkQzRD0bsQzRO73cb21Iu1cT9KMJGhc/sAhT7rEvlrj6k+4EkNQNsTj2\r\n/wvrBkAOKrS9qIFKlKVI/AyHWQ/484cO5zvrUl45YG6Rs0Kbh8oyNKbtOvie\r\norhpwP6ecf+763dHJk1JEwuc3GfIGX7hlaN6FJGVT3vwsCuVBvDnXTUmycpl\r\n7pD8vkAvrK3WMNaGME/+B0sNkMeKfU8u3j8HxLpQqxmDzcXYA+frtyfmnuN4\r\nxD1GGEzDzg+/YqcrscZPPvlBkNE6yxywaB1dOwkKdslGn/O9H0pds0vd2exk\r\njDtbUE563pwkZgf8t0N1MxAk1UbtcFh87QSVpUL0t402Xrkm5Qe9M4J5u9ii\r\njhvdri/3dVlQZ6K7YeeB+g1V4NUq1NAVdOrV0gZbgoL6YhYckIy8t/pvsNeB\r\nNB3n69uYohEWh/IHzWebfSGuDiwJt+aGMiFExmmIDbNbdh2E1DPLvBevTJ0Y\r\nLe+RK+mf+kyY/V3eFQgucW//cDTMCOgAyrY=\r\n=TqYM\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.209_1682437160685_0.23341629160122235"},"_hasShrinkwrap":false},"0.4.1-unstable.210":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.210","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.210+c9aee2a","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"c9aee2a0459094c83c7d417e4a9476b56a0ce487","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.210","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.6.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-tTjLZ4+ydnUq2CIlhCRZZJ1UexJvX4gQK7ngHQE/BpI3MfDWO+LR984dOxi5jZX3zXteZuHd93EJPkFHPiEuWA==","shasum":"cc5dbc242d74fd9882292309492f7cd885168004","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.210.tgz","fileCount":83,"unpackedSize":367540,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDsM0zCHmTr4waePMKPwp0Ps/wPJPIfpIw9iSgoR9j2uAiBENCsSTWB5uatK6+vhaoz4V1d0UolCh66+N/XNffZgRw=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkR/gOACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmreIw//dHUzN0VRObja6YvsA+CU8D/kyQByQlcLCaMURViszDa4qKYZ\r\nVEVjbOJwlTGTAIg0sKCLwkqeMQ2N2mNgzrneHEVQJWhQn/tWDiVqhQ+xgvoG\r\nZTdmhhxrfjQfPN/Yr6go4M/R2nBCE3WfUjXV/PjJo9ro8eU+KJUUdf2aqPuo\r\nsFXyytwk4iqm2rHpsWd7U8y8fLuyrqGeCDaTv9uIwiI92DQ/3SRQqeXZgLCf\r\nKmfubv23POtsBvlLcfMGNa29YvonZ7fwPMkcYP4InRVJCnvWC6fmHPRVOHzI\r\neF+GVwBZZuCXYBA+Cyi3Jk85YTgxKKpQJ8Q1QRjxOWfE6FqGZYsPBWGsxrT0\r\nQ3aOI0HXmtZveO8hnp1fnjpMEOprBBF1VgujAWIDk81JdCkVAof8LDc8hvA4\r\nyHTK009Aaln85U6sA5ZZv3axdzqPwooDSGYCwC9Kys8mQpVLEkC4n1iPTrg5\r\n0DtQF2GE2zBBhzZT6jtbLJy1iTIJaluAJ1+XIgQb93T8UeDTfOhLzGrOTtNj\r\nFn2fWP9Av50vB2jiYuP5PoHe8y4tKSkkcERw9NVXRNfvRpEGSdEyUpCdQymy\r\nNF+G1Noi1GKTZoTLmyyNcagOcaFMMUQpvEojRhhio1fxRg5X5AC3kvK/Kqu7\r\njb7edMF5POPjlKqrEMgsJmQVvzKUMYtNtzM=\r\n=hhCp\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.210_1682438157933_0.09288204015542156"},"_hasShrinkwrap":false},"0.4.1-unstable.213":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.213","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.213+e41e940","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"e41e9406737022498aaf0869f99f560a3eea6507","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.213","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.6.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-yGml82/HJqxcOzqU4WlPI0O1R3Q08gk6GX3Wamuawqfy4gW11WWfbGofmEWd1EsHksABF6QCOK4LRQCEKm0yQA==","shasum":"018086cb5e918df8bb7b42516ca0b14296f74a14","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.213.tgz","fileCount":83,"unpackedSize":367540,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCq/oKmp1q/IKSzzeRej5tNfPaM5Pm+haLaQpXqgriqrAIgU7anZ+HgtYcvIb0HptXGg38eiEzrBqztRnFHJv4vE1o="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkSQiTACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmppWg//XK8RR/fx+nJo5r3Y3yp0DmUSDklfgk0lhOjvdnXysRHbCzjl\r\nBKV06/18D+/Q4j1hO9agTaZXX7ajVAfIgzCFNM9/yLz7xorX5UxipP8SEHsB\r\nnRMx1uSqWiwwl7lXLFxaWEa4we+zJt1BIrN1d82uT1Vev6LgvSUfptPNMlnH\r\nQ0JP3ZMz5gYYuhIiQmP6PkJZd4TNesdusn32wZoVEIJjxzK5x4MLbchRMWH2\r\n8zAWevbaXye/Uyx3AJvDebqJpLD5zXPM+p11vVFFjFep83NS5X4YNfw/rEGU\r\n4ufLLrBT3BAA+OHeqo1zAh77cdiSUzq1NNEv2yvYDDyCY60RqCy/erIsYYDF\r\nHhkeGYM4dlBb9BEgJMsWNkh9jQFT2kq4AlrNK9v2oOKY6gV6Q544APRWYM1V\r\no9OZlfrYYirDdDI78NgOQ4GTMeXbXywwlsi5WBC7+ThUOVpbk+B1565pfN2Z\r\nLEgIC4xzSTR5J491yrFxPlxFQmw5ypoL5bDjmsTSfW1payULxZIumWXqHBY3\r\nQDnTiG+IiPFmLBQtA6k4qP7g0Gbxx0CwVPNsj8UacwwrpsD/k19IkNO3n27A\r\nsoI9Us9VZfJsO8rZiCMDKuHkw79wo0Mv6K8pJU8EzkykTBz9Yyv4yilWZu+l\r\nnSwZ8nc1NId2u801SFLByUAFmR+M5f5kEKI=\r\n=GON7\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.213_1682507922806_0.40868877318598473"},"_hasShrinkwrap":false},"0.4.1-next.214":{"name":"@sphereon/openid4vci-client","version":"0.4.1-next.214","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-next.214+2e7be63","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"2e7be638cfcf36c623c2e957f7fbfd1c66887e90","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-next.214","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.6.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-o1lyjkxEPMlMu9g7IlQXmtJ8UDw7zZcmK71c2oarN1g3SOAokwjjSnIimJW7G4Qhu2zvgnqa+Wtx1gd7NEbk6w==","shasum":"6bf0ab32ce23a03afa7d2329e9a3f8a7d81c7b0f","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-next.214.tgz","fileCount":83,"unpackedSize":367532,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD6Dzc9fOpPazgQU9idaEsAz0/sGfokHXLSCI177oN/ngIgdQtugZMW0XafjrxGVL40vaKsE+/2vIRlwyNUa7/0Fok="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkSTATACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmojHA/9HlYHPPMU+ZulaN9as0kh8w3QJzLdw2584agnurf2bsIchxSb\r\nu16LbhQCiGN4i/xoC8+NMyf8cTomsBTh0MrqRY6ht/bhGzZfrHdX4mXE3l+3\r\nK5HgmRFXKmnssPvlIssiZKCtR3G8J3ZLcizda3FwjvPR9TenbRDbJnr9afo9\r\nzJwxR9x5tOETTAZWzN1ugKAKAPZJ70D974I2Ys5NaAI3W5a2xvuSYi2mSWPW\r\nSRdR05yMiqxQPhmF6wqyN4mqDidZA5nInm9dorqbpXmw6Ida/sKS3EkTK2lX\r\nQ/EfXdVYVGAZBgqRMF8P8ZsS7Q0WE6Hs9/3UBXavZdq3GWoxC2u/Aw7y7YMK\r\nQQ4X6Wi+cb19UHNOBjDvd0apURtYBcJgucr3Qr9dqIGVqbOLyvTTtoWkWojo\r\niAGQVWli5iu989aqCU/PjqMhcA0ACDaeVHYBog6jkhAHTzyAQmSPsZtJUoiA\r\n/a3jhfJa3OjQlOrOOqB63t5rrbIaN8stzES+4OaEvlzOKjG8nFgeJQopxdBy\r\nL1SiZ8rE0MUAoYUyzgz10Z9DxD+ZQSuY7JH+svCvXeeyXAyEXT61yIXpyT8U\r\n1p1/+n4rweiTbwqh9tHgLqlXdOF40STsEqDli2/0Vgymw+SeRh8KtzaJ3YQA\r\n6cw2txQnaXJ90Sm02h77TaRdzae6Hnbmkos=\r\n=GfnK\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-next.214_1682518035064_0.6216607623063675"},"_hasShrinkwrap":false},"0.4.1-unstable.220":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.220","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.220+b87095f","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"b87095f889ee782ab53414374e1cd3bdf7d09ed3","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.220","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.6.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-hNyORLBESEq+E7ihInjUfboCN75jkfTGpBOqtt8kMnziuP1S+R2bYuer67vfNYYA9Rwtu8D8QbvbB3Za8zBC0w==","shasum":"2e624dc617d365c4893f99143bf2569c5690141b","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.220.tgz","fileCount":83,"unpackedSize":367540,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDO/ZkJrnxuM+elDlQhIqF636VJ2K6npjMj14v+7ltQCQIhAI12hJi/AMKD1r44Kq20SvlnBO/Qncp6L+CzWAAu+J6m"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkS+RQACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp+bRAAoapzZN5YcNtEkNtXoGj7Ds5ZifP+Vy8Q44jVtcFqFuSrctQH\r\nk6QoBDvTdrCT8gAKvZWU46l9JkZiid6NeMUBJATs2Y5EsF2CgMTXwIHzoO5n\r\nHa+2za5YuUUBIFj72N6evXk6lSZJ2HbUrnjG2uo03y515nUthCV06i2TQw6m\r\nMa2kbkoZvXuIcSDSLW8oXnaL61Fwx53KrJYyQR6a+ChF+e5j59WUN0p5AO8c\r\nkQNK/gF8Y1Io7FTUT8Bb1p0OhB45JcecbVSUynTFB9/PCqWDazHza5y0mVuV\r\niwmQtUYHBb6/p0h34U/qfFhgmhGm4BzMPAMhGaO6O6fS3YMR7leyveMYMhVn\r\nZofbthICK3Ep5gD/en5uOSJu1DEVbFB0BafvLar3uSis0cMo9kpgtsUESlbZ\r\nsZSJApvqK3ntOyoVBns6F+Pw16K4A0PIEbd3O0OlhkDOHaUBcIuARDOMgP2B\r\nhR0mDzohE2L+LZGJdBkHYZTzCq80zaG9+nYKu0D1ujrTZIaF0FTEZGJrkDjq\r\nRaXlviy79Rvz2SX2mxyKLHD4FppxPEySE+urtQ+8iSLyKHm2sFt7N3lTpgil\r\nAlB8PiSYASFG3eIGNWMNvbCF7eO6mj/h5zU/n59q3iPLkOeR90XLm7mD6UhO\r\nN5MO8td93k686RP817Wh5w3DBPVSXZClEDk=\r\n=794y\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.220_1682695248062_0.3801741078691745"},"_hasShrinkwrap":false},"0.4.1-unstable.221":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.221","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.221+c0dd11e","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"c0dd11e105aa4f08646167e217127558cdce2e7a","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.221","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.6.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-7H0VEQfXaWfnhP4gh1d4cH4wSSjKj+zTenRYbGg5fwiyXba3PJA5n88Aza9nkZB42DGKutHK5ANUyX8aBh/blg==","shasum":"5ac2be3ce2fdcac295f3b48149d1ac4743e6b1e1","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.221.tgz","fileCount":83,"unpackedSize":367540,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCjR2WZUonQt4uSl4pK9v+qJ9rvIuD3M7jLMzH8wJwzwQIgNMg6W0222H6PyjM2DotfvBbUQmLBOA4F5zCg67QK388="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkS+pwACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmphxw/8Dq/V+Ji/nnYI7AwhwdXVycXF0LmFVjAbz0xLQRCIg2UOtRw1\r\nTiCVHPeMN8PjbfL1DfcHgTSuTdOptFF119vLz3dnK5FmGhNb7gG5K7WMLVm9\r\nzrUQq8k+Io7rIusuZBfDg/XKP5NFoT+M4rJC7Gj7g2qz3E+ZrZdkJ5SDjQBw\r\n2mauuUE3pjTIq2xnJE4v32RihdVS2hV8Fd+ucb9gSDmzJK7CmpVjtX268vF0\r\nUZo445OB8sHs0PLW5EnfArDc4o86CJypNRmX99kUENmU3XpUcH1ytealvGkR\r\n7Go+Psx8D5QssKAyV9Lrcsn/9RDHqG2aCNBLSTmxU9u+kSSQUoTcEAiJj9cp\r\nMbOjvE3rqSQGa1nMKiO2S76+FDOXjqRPnYUqGldhrKX50pMWJBXSLYDzFY7v\r\n29MT5+qAac9RLKM1kiRmsmzHpSS/K+54FiwxLPsEHD75I85Nw5Ypvb4vzqCT\r\nsEq0HlktQYapFHdJ6YBKEuJVfJ5gt1r2WSqeXEDexNtP7FTpAa3yDiMQ739a\r\nh1vxwonhCNHqHL87neUPCZGoDSzrpXUGsOj9eJNMhEaUFh0JuFzpMJji5HYV\r\n518TkNYCsAGqT5j8FX0x98WOVnwmrp575AUvsGBH5TYuUGFGdXJONFLWIR4/\r\nWBioypRHzNuAuH/Ylx0mMeEPf8qeAwi30K0=\r\n=0EpQ\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.221_1682696816378_0.6745462718225506"},"_hasShrinkwrap":false},"0.4.1-unstable.227":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.227","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.227+55186e1","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"55186e1c1d8b116f520d28d0ada0319a0fe75545","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.227","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.6.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-TNqET8r2wWJbSmdlUfFTYf4LFESHRKlCfUmIUAQnN4MNIKQmnIBfDeZPnm0ECa6pTCgsTTedIWwKVK+Xcuq/9g==","shasum":"868e97715399080e5108e6e3b801dea71b23326d","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.227.tgz","fileCount":83,"unpackedSize":367540,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBSYl3XRPM3ARoMLrT0od00msCcrRa0q6yw7UxKJpiz/AiAszYiIKLEyHuO9hBrRDv9TNT3dClbApXSLMciA+stkBw=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkUOIYACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqXdBAAniiqXyu9pcOz9vFqtvBKIz7AxveKK1XbQLdYkXOze4M0KMKk\r\ndUsHLsmbHKjKDaORxNtTX3mjBCmbVXK4x9r3AMdAzoT6vygcolsf4hEv6SQy\r\nAlnWyBL9q51DlvOWjhtK8mAD+XGJ6UVgMzlnqnyXABIhVPTSo4Ryr2Fi4H2n\r\ngrU7PINhRi+cGo236TKQjebux2sF4LIaQtkDfaF4BxHu1kItG90QVZZ6ITS8\r\nr1NlQIUN5oJMj6E3BQDOrebIu6Z1eBWuvDgbxLRZDFb3bpA5QcretCEdNW09\r\nog5CnQFKKFKs3yjNqkxv/xFVvoABeoLSvIbUQiVqUkmrV77PqDDfvv9DXZVB\r\n5ZbBsSn8ygyTrTQtI0xgOD2kduIR79lplDt/DgwvqFeY9urG8g5dETmmcxas\r\nQIDxIEGJlYZ5yOQGvMt64hp+oZ08zrEGzWnNtS5460Npktgey/XM7f6Ex5gp\r\nbblpV7VWRHkJUkYimvJ0VVjI0Gc3v1f4sOj69suTUisEXjcJ83TxIRv8i4vf\r\nkPglLD2YbIsHWaPeFain6Iv/AnPWDlbLchmGIHY4W8+I9WzIugeiPfN7jY1l\r\njFds0hc5fxMEzEN9fR46d36Oq1Oj6+E+Gwl/5E29YfeLKfpGh5emQm2/auTo\r\nOxD5WVLLgjD5ZVxls46KYyrNxbIlzwTp4W0=\r\n=Q7rg\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.227_1683022360395_0.9872248951340243"},"_hasShrinkwrap":false},"0.4.1-unstable.238":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.238","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.238+62eb579","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"62eb57948262c33035084642b06e49033b38bd45","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.238","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.6.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-9CC2DVsfMr4NcG/2RT6jcEMnAeyC/B7sEjO9S+OSFGN9Lu2Spx3opfX2lza19xM5TD7Hc25206j7OAJPp3ZTlg==","shasum":"cb0647dd32bc8da1d3b8723e5e9769257b85116a","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.238.tgz","fileCount":83,"unpackedSize":367540,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDJdpX0odVptTj8T4SmclxGW0iXI+2aSjesjP8wdcQR1gIhAP6TxvcVe+5fQx+T94Hro/uhtPjOFqZmGyXRhE1PyCA4"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkUoBbACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqNjg/+KldFdvHwiFB+lU8Fm7iwUl6QpTeitomQ0F4gzWYTLq6nWkhS\r\nqVrVisqt5b/wMWE6WwVGzsVUz6ZIi3CToATcrGh0oBqEnZ+sVIcBTUpnZ+kf\r\nJNm2F5Gxm7gRMK59SqHhoD6U5RWpXq92fVbLSJb86p4BuGNUUDIwEtOZF1MR\r\nUDI7h650fgRZj8tIhmWcPI7/spEkgGEAOJGwR8WLfzr4C++FQYqJNDyc22hu\r\nrOodo1LVe+Y4IPPnzwaq0D7MFRAxQ4/lpftZoed1Lsh2U8aYNbTXlq0vF7r1\r\nHisWPB4s7/nEZMPJLKx0XpM8RZdDzkJ73tXx12OMKQhlTqv/xbJ0pTk0j+dX\r\ncdkCyuG6KD4kvrkF07YQ98B6kb0uVORkx0odKkJ9fPIEoTVsoGqDbBrLQafm\r\nztSolQaxUGJqOxTIYk5Ob0+PzBxn93TFd/04kG77Ml5tP9Vpp3CNJ2lzpTwK\r\n8pUwij7uR7FLLq34/rK/XDzfzcNnG4+wShfqvZBhqUkLTj6oJDO2gFoeCwsg\r\nefdMkyc/4oRd58HIrivTiAOpRma4CYSrm6CCwlcp+0slJZleeGks40svQZww\r\nGeCUX4twPxOGVZNqiQi/BmWUytK1ShDyFtgLSxMFySEpckf+saNjGIblbEqg\r\nGQceVIZ3FrohNng3IZ9SGQt/PP6M+Wm4kSE=\r\n=SBwa\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.238_1683128411086_0.8105221558814086"},"_hasShrinkwrap":false},"0.4.1-unstable.242":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.242","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.242+e593738","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"e5937386f5a77ca6b1b1d23664343200be3fcc15","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.242","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.6.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-r5DQYy427xGGkF7wtrXHec3JzWKlVgvxV3ECGzfzNa9ochVDbTCaclWeFrv0IgqLMv7CjIwihqEUDhhmZyb9oA==","shasum":"234a3475ba876e363c7e5564981fa839e30d6023","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.242.tgz","fileCount":83,"unpackedSize":367540,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGGYUVAvvTvuUGMgL4GqMDYQwHByDuDKbFnEavNlyeUTAiBI8ql9Glw7+HP6FxRlVGTNZAgUTBQOM/NvUxAxmQw0vQ=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkU4XMACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoqCQ//eOjktoXA3fs5p7Y9cpo1Zj1+F2gzNHSwt81UHkbbj8l1+SX3\r\na3sW9epr2qCAvXku2JdTWj2Ysat2JnoMGY5TCRmVG48eBJlSZ2yfOD910dnB\r\nOdFqz0tb5/IzeGgQ7N5zv8ndY2qyU/+hkOvwskGdqTshm9ajAQAIeWATT0mR\r\nO9/rDI4+6RH6s7jh05XQQsKAr1NX5IRumV9JIaLS0bsApURaGTfZjc9tscRG\r\n6YTscZWC0r+o1brbzuvhxvxtEm3+uFbkTY05tVn5W3BFh3L3TGEkW89LReqB\r\nv9a9tLnrmFKBpSNjhrn7B7as+0ZpDqoF3z0SNW4ag5i49KR81M8FNsyGSWBl\r\nx5dYd0aImhtrOEQueCYDJAE/s38W+l0y+uQ4/5TPsaLmabqjQQAnsWXEQfEo\r\nr0RelmQETPnODgE+2M482WTJ+xQOe1DwPzTbWdgBDvFgoQv2Up7SJ0/MGUyP\r\nDZImr4hklLh8S+hfnj7HERozVM6vunVN7yXFheKxUQkm1ONVhAdmNlv033eB\r\nEAaV/GMq1baHFHPli+3+9o+T1ga1/HhET5Lj5dojULUafa2oyHEV1prebMBx\r\nUJs8ZU4+wsD+FB12Y9UUMYhEtHWFL5Or2BTFgTRXx6ECSomgs7dQnhK/GgAB\r\nu1f0cJGRpXjhTFG8QK+7wTi8IyxPbcGaVz4=\r\n=cnyS\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.242_1683195339872_0.5444708539077638"},"_hasShrinkwrap":false},"0.4.1-unstable.243":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.243","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.243+5fc3193","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"5fc31939db12acec51fcc4818849df8fe18d92be","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.243","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.6.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-gf3yGxaRRYgacwMbCljezFN2BsGVZqxSmx1NJCEUIDi5Pl24aBemAt3OY1OU4CUrkZ7fcXMGr4pF+my5WH+xqQ==","shasum":"3b263168df8cff1fc42822a68ac5cb2222596dae","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.243.tgz","fileCount":83,"unpackedSize":367540,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHyYGGF8s4GJTeEyN94hJDnLm/By1ZtCqg2unwMnN1fNAiEA4ctVRt38pEyHtbkBSumRUfUglChEgWmUzS9ULc7lCWU="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkU7zVACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmqkhg//R4ZlZCCPQhLkG347jZXL6oSkW8bJFM2NgxZ0INb9Ov+r1iyd\r\niN9KH+GBcBF5auCGi97Jxsttj8BfYAogjSW2DRxU6UNYCluos2ewrpWEUsmD\r\nZ3Z+fqgj5mSnFEwP+FAwioXu9gRq53rm92BDwuK45GxCf6SWr7jbnxrLyN4A\r\n91av71JQE//ThC7UeLjjDezCrOxYDTq8YRAguuVs9FepFb7L81MP5RCvKsWk\r\naChzZbJLfXeIW1om1E0QhBSLFDAOOFPsFSisLSvVIFk5jRxK1pVMl0gwGWYq\r\nn+hpz4hakX4hPItxccpmmgjKcJZgfU2gEQrXKtnw6PStBgsoOvARWicncWqF\r\n8CKdjsPmAIh80Lz7GzYumg6r7vbmHEyqmNg1WZRYFqHq1O5kkd3N+mdPLZEO\r\nu4tbO7Wbu99zj7l8kcuB78iVcB5+pgb4fMm7PoY0LzpikGNGLeN6H8Z2Pf8+\r\neOboZIQ05+odyHQjAHQxBa5eaQumwKDj81BGUvZ7qWrRvAavcjWrVx5gEUNX\r\niqp8Rxpdazxae2RUkPRBzrmRlDNtn/Tg3f4ADdJid3QzuiFE6PRucgHzrhUU\r\nzGFaP/QbeAPMqdZ4z2ix6Y0QWevjp5+pjaDqRNbZjkQZPC1rq7KC0Ekk6SoO\r\nJGN4ibrwnBJUjtipDtuFmeI92PTnYgvsAJs=\r\n=y8gO\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.243_1683209428856_0.9315439847760987"},"_hasShrinkwrap":false},"0.4.1-unstable.245":{"name":"@sphereon/openid4vci-client","version":"0.4.1-unstable.245","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-unstable.245+0dd57ef","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"0dd57ef20dca62a3f7fe00a682c6851f8562134e","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-unstable.245","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.6.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-0SGsexsEFQN+3Q5AtV8mIdjxHdYBS4330X7IFJrbRNQ9RBQZ/TCUCqCvFcj9OoBX/Wjzgj3rVlRBV9L9Bc0QCw==","shasum":"5cc6df22a7692f2e42f16bb22364f7445337d171","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-unstable.245.tgz","fileCount":83,"unpackedSize":367540,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIF/PyZs0h3WGD7OhBH0r0c8Ltjt5ZWbWJxmJygnaV/UqAiEAsX9HM7/EqeLCmmQM7jca8da6Dkhww4Y9GpwSZQGrF5E="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkU8UBACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp8KQ/9Haz8mPDn7PwEqRaUbP6p+5WoDsTYR6oLLcZSW2cJobtZJIs/\r\n8h6R+VbgYCIsgsIZHTcNpHPHaOZiUna9GDLeObk/rWoBvn/RYX7BmbeibyJa\r\n8te5mxmXiI7Wiu3/v+uczFuW7bKA/qJXiHlbyEq1z4kKTthwvbw/eF0l+l2G\r\nioBdKfiKxwH8YmyghBnif4D1hWBKKDwlF02l0Lwp3hsq2uo11TOjlldE1Qd+\r\ngkY9TS8UWq1RHDJfgXNKg6jGeyMdei1DsfC4GSY/e8KERha5lN3sbAkGeNWE\r\nnXLeI8gKUDadZe8TlxM2xDb4luBXheer9Vgc3jB9/7NzjTBbuJ0i/0Nwpq+M\r\nS8ijCKrmVGPl0IsE/HwOB/a6gmnobSKiilpymChKwqQMwzyAusvQqSb/Z5Gs\r\nvC3X/O0UwdsAdDAm/khhLkz5Fq8na4uh7+Nl8/rVhCvBxmXfHq+6hIkXbTfw\r\nH9/o3EoBBnV69fPg7cM3+M2uMxWnlybqfa3oDdxsUVh9x8lTUkNfUM6ZPVtr\r\nU23wviO+rNpg9EWnSVumdWK+Z+FuwBEQVz/mT+b2anQVvFtMGL9WaoyNNov6\r\nTfwhYlyGY7Uj6ECgh8MnICsdkFEjT4afB1ZSje7Pl9wesKESQsYcxvx8AXLd\r\naHNpF53dWkj/RTeUt7vzlvcPDAZA+dGmvCQ=\r\n=q4pj\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-unstable.245_1683211520917_0.5941107539138781"},"_hasShrinkwrap":false},"0.4.1-next.246":{"name":"@sphereon/openid4vci-client","version":"0.4.1-next.246","description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","source":"lib/index.ts","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"Sphereon"},"license":"Apache-2.0","private":false,"publishConfig":{"access":"public"},"scripts":{"build":"tsc"},"dependencies":{"@sphereon/openid4vci-common":"0.4.1-next.246+75ea2a7","@sphereon/ssi-types":"^0.9.0","cross-fetch":"^3.1.5","debug":"^4.3.4","uint8arrays":"^3.1.1"},"devDependencies":{"@types/jest":"^29.5.0","@types/node":"^18.15.3","@typescript-eslint/eslint-plugin":"^5.36.1","@typescript-eslint/parser":"^5.36.1","codecov":"^3.8.3","dotenv":"^16.0.2","eslint":"^8.23.0","eslint-config-prettier":"^8.5.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.26.0","jest":"^29.1.2","jest-junit":"^14.0.1","jose":"^4.10.0","nock":"^13.2.9","npm-run-all":"^4.1.5","open-cli":"^7.0.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"4.9.5"},"engines":{"node":">=16"},"prettier":{"singleQuote":true,"printWidth":150},"keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"gitHead":"75ea2a7a3e9df347aa1ee9428c3e16e702542e62","readme":"<h1 align=\"center\">\n  <br>\n  <a href=\"https://www.sphereon.com\"><img src=\"https://sphereon.com/content/themes/sphereon/assets/img/logo.svg\" alt=\"Sphereon\" width=\"400\"></a>\n    <br>OpenID for Verifiable Credential Issuance - Client \n  <br>\n</h1>\n\n[![CI](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/openid4vci-client.svg)](https://npm.im/@sphereon/openid4vci-client)\n\n_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of\nOpenID4VCI!_\n\n# Background\n\nA client to request and receive Verifiable Credentials using\nthe [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (\nOpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.\n\nOpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and\ncorresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to\nreceive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing\nOAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.\nIt also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and\ninteroperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.\n\n# Flows\n\nThe spec lists 2 flows. Currently only one is supported!\n\n## Authorized Code Flow\n\nThis flow isn't supported yet!\n\n## Pre-authorized Code Flow\n\nThe pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to\nauthenticate first.\n\nThe below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like\nsaving VCs) are out of scope for this library.\n\n![Flow diagram](https://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/Sphereon-Opensource/OID4VCI-client/develop/docs/preauthorized-code-flow.puml)\n\n# OpenID4VCI Client\n\nThe OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a\nclient you can use to finish the pre-authorized code flows.\n\n## Initiating the client\n\nThis initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also\nalready fetching the Server Metadata\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\n// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.\nconst client = await OpenID4VCIClient.fromURI({\n  uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',\n  flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID.  You can defer this also to when the acquireCredential method is called\n  alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called\n  clientId: 'test-clientId', // The clientId if the Authrozation Service requires it.  If a clientId is needed you can defer this also to when the acquireAccessToken method is called\n  retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.\n});\n\nconsole.log(client.getIssuer()); // https://issuer.research.identiproof.io\nconsole.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential\nconsole.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token\n```\n\n## Server metadata\n\nThe OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional\ninformation about supported Credentials, and their cryptographic suites and formats.\nThe code above already retrieved the metadata, so it will not be fetched again. If you however not used\nthe `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:\n\n```typescript\nimport { OpenID4VCIClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await client.retrieveServerMetadata();\n```\n\n## Access token from Authorization Server\n\nNext we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is\nfound from the metadata if the server supports it. Otherwise a default location based on the issuer value from the\nInitiate Issuance Request is used.\n\n```typescript\nconst accessToken = await client.acquireAccessToken({ pin: '1234' });\nconsole.log(accessToken);\n/**\n * {\n *   access_token: 'ey6546.546654.64565',\n *   authorization_pending: false,\n *   c_nonce: 'c_nonce2022101300',\n *   c_nonce_expires_in: 2025101300,\n *   interval: 2025101300,\n *   token_type: 'Bearer',\n * }\n */\n```\n\n## Getting the credential\n\nNow it is time to get the credential. In order to achieve this, we will be using the metadata together with the access\ntoken, but first we will have to create a so-called Proof of Possession. Please see\nthe [Proof of Posession](#proof-of-possession) chapter for more information.\n\nThe Proof of Possession using a signature callback function. The example uses the `jose` library.\n\n```typescript\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n};\n```\n\nNow it is time to get the actual credential\n\n```typescript\nconst credentialResponse = await client.acquireCredentials({\n  credentialType: 'OpenBadgeCredential',\n  proofCallbacks: callbacks,\n  format: 'jwt_vc',\n  alg: Alg.ES256K,\n  kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',\n});\nconsole.log(credentialResponse.credential);\n// JWT format. (LDP/JSON-LD is also supported by the client)\n// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA\n```\n\n# Using individual classes and methods instead of the client\n\nInstead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a\nbit more control and options, at the expense of a bit more complexity.\n\n## Issuance Initiation\n\nIssuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed\nas a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object\ncontaining the baseUrl and a `uri` JSON object\n\n```typescript\nimport { CredentialOffer } from '@sphereon/openid4vci-client';\n\nconst initiationURI =\n  'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';\n\nconst initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);\nconsole.log(initiationRequestWithUrl);\n\n/**\n * {\n *    \"baseUrl\": \"https://server.example.com\",\n *    \"request\": {\n *      \"credential_type\": [\n *        \"https://did.example.org/healthCard\",\n *        \"https://did.example.org/driverLicense\"\n *      ],\n *      \"issuer\": \"https://server.example.com\",\n *      \"op_state\": \"eyJhbGciOiJSU0Et...FYUaBy\"\n *    },\n *   \"version\": 9\n * }\n */\n```\n\n## Getting OpenID4VCI Server and OIDC/OAuth2 metadata\n\nThe OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they\nsupport. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery\nconfiguration and\nOauth2 Authorization Server configuration. These contain for instance the token endpoints.\nThe MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the\nOpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:\n\nExample:\n\n```typescript\nimport { MetadataClient } from '@sphereon/openid4vci-client';\n\nconst metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);\n\nconsole.log(metadata);\n/**\n * {\n *  issuer: 'https://server.example.com',\n *  credential_endpoint: 'https://server.example.com/credential',\n *  token_endpoint: 'https://server.example.com/token',\n *  jwks_uri: 'https://server.example.com/jwks',\n *  grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],\n *  credentials_supported: {\n *   OpenBadgeCredential: {\n *     formats: {\n *       jwt_vc: {\n *         types: [\n *           'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',\n *           'https://w3id.org/ngi/OpenBadgeExtendedCredential',\n *         ],\n *         binding_methods_supported: ['did'],\n *         cryptographic_suites_supported: ['ES256'],\n *       },\n *     },\n *   },\n *  },\n * }\n */\n```\n\n## Acquiring the Access Token\n\nNow you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from\nthe `IssuanceInitiationRequestPayloadV9` payload.\nFor now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for\nknown until the\nfollowing [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is\nresolved. So the token endpoint would become https://<issuer-hostname>/token.\nThe library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS\nif you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.\n\n```typescript\nimport { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/openid4vci-client';\n\nconst clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)\nconst pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.\n\n// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used\nconst asOpts: AuthorizationServerOpts = {\n  clientId,\n};\n\nconst accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({\n  credentialOffer,\n  asOpts,\n  pin,\n  metadata,\n});\nconsole.log(accessTokenResponse);\n/**\n * {\n *      access_token: \"eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ\"\n *      token_type: \"bearer\",\n *      expires_in: 86400\n * }\n */\n```\n\n# Proof of Possession\n\nPart of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will\nbe the subject of the to be issued Verifiable Credential.\nThis proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.\nThis Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the\nInitiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function\nto sign the JWT and optionally a callback to verify the JWT.\nThe signature of the callback functions you need to implement are:\n\n```typescript\nexport type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;\nexport type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;\n```\n\nThis is an example of the signature callback function created using the `jose` library.\n\n```typescript\nimport { Jwt } from '@sphereon/openid4vci-client';\n\nconst { privateKey, publicKey } = await jose.generateKeyPair('ES256');\n\n// Must be JWS\nasync function signCallback(args: Jwt, kid: string): Promise<string> {\n  return await new jose.SignJWT({ ...args.payload })\n    .setProtectedHeader({ alg: args.header.alg })\n    .setIssuedAt()\n    .setIssuer(kid)\n    .setAudience(args.payload.aud)\n    .setExpirationTime('2h')\n    .sign(keypair.privateKey);\n}\n```\n\nAlongside signing, you can optionally provide another callback function for verifying the created signature with\npopulating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are\nfound.\nbelow is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.\n\n```typescript\nasync function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {\n  await jose.compactVerify(args.jwt, keypair.publicKey);\n}\n```\n\nSome important interface around Proof of Possession:\n\n```typescript\nexport enum Alg {\n  EdDSA = 'EdDSA',\n  ES256 = 'ES256',\n  ES256K = 'ES256K',\n}\n\nexport interface JWTHeader {\n  alg: Alg; // REQUIRED by the JWT signer\n  typ?: string; //JWT always\n  kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.\n  jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.\n  x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.\n}\n\nexport interface JWTPayload {\n  iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.\n  aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.\n  iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].\n  nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow\n  jti?: string; // A new nonce chosen by the wallet. Used to prevent replay\n  exp?: number; // Not longer than 5 minutes\n}\n\nexport interface Jwt {\n  header?: JWTHeader;\n  payload?: JWTPayload;\n}\n```\n\nThe arguments requested by `jose` and `@sphereon/openid4vci-client`\n\n```typescript\nimport { Jwt, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n```\n\n### Using the builder from metadata and access token response\n\nNormally you would use the Proof of Possession builder using the server metadata and access token response together with\nthe callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.\n\n```typescript\nimport { ProofOfPossessionBuilder } from '@sphereon/openid4vci-client';\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({\n  accessTokenResponse,\n  callbacks,\n})\n  .withEndpointMetadata(metadata)\n  .withClientId('s6BhdRkqt3')\n  .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')\n  .build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n### Using the builder with a self-created JWT\n\nYou can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will\nhave to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using\nthe `jti` property.\n\n```typescript\nimport { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/openid4vci-client';\n\nconst callbacks: ProofOfPossessionCallbacks = {\n  signCallback,\n  verifyCallback,\n};\n\nconst keyPair = await jose.generateKeyPair('ES256');\n\n// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:\nconst jwt: Jwt = {\n  header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },\n  payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },\n};\n\nconst proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({\n  jwt,\n  callbacks,\n}).build();\nconsole.log(proofInput);\n// {\n//   \"proof_type\": \"jwt\",\n//   \"jwt\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI\"\n// }\n```\n\n## Credential Issuance\n\nNow it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match\nthe keypair created earlier.\n\n```typescript\nimport { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/openid4vci-client';\n\nconst credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();\n\n// In 1 step:\nconst credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({\n  proofInput,\n  credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!\n  format: 'jwt_vc', // Allows us to override the format\n});\n\n// Or in 2 steps:\n// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format\n// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)\n```\n\n# Helper Functions\n\nSeveral utility functions are available\n\n## convertJsonToURI:\n\nConverts a Json object or string into an URI:\n\n```typescript\nimport { convertJsonToURI } from '@sphereon/openid4vci-client';\n\nconst encodedURI = convertJsonToURI(\n  {\n    issuer: 'https://server.example.com',\n    credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n    op_state: 'eyJhbGciOiJSU0Et...FYUaBy',\n  },\n  {\n    arrayTypeProperties: ['credential_type'],\n    urlTypeProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(encodedURI);\n// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy\n```\n\n## convertURIToJsonObject:\n\nConverts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to\nbe converted into an array.\n\n```typescript\nimport { convertURIToJsonObject } from '@sphereon/openid4vci-client';\n\nconst decodedJson = convertURIToJsonObject(\n  'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',\n  {\n    arrayTypeProperties: ['credential_type'],\n    requiredProperties: ['issuer', 'credential_type'],\n  }\n);\nconsole.log(decodedJson);\n// {\n//   issuer: 'https://server.example.com',\n//   credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],\n//   op_state: 'eyJhbGciOiJSU0Et...FYUaBy'\n// }\n```\n\n## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion\n\n```typescript\nconst CREDENTIAL_OFFER_URI =\n  'openid-credential-offer://?' +\n  'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';\n\nconst openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);\nconsole.log(openId4VCIVersion);\n\n/**\n * 11\n */\n```\n","readmeFilename":"README.md","_id":"@sphereon/openid4vci-client@0.4.1-next.246","_nodeVersion":"16.20.0","_npmVersion":"lerna/6.6.1/node@v16.20.0+x64 (linux)","dist":{"integrity":"sha512-6y+mw7erA9DZ2LqitevtlfFA8Xx6lGhGR1CheHsjJGKhv4xeRqJX+UfgEL8+f4T2hbtlF/S+YutPW1C13cjpwQ==","shasum":"1d98db15cddc2b1b388fa201347eef63ca0c0078","tarball":"https://registry.npmjs.org/@sphereon/openid4vci-client/-/openid4vci-client-0.4.1-next.246.tgz","fileCount":83,"unpackedSize":367532,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGIBkRE8D25+5vsKoUye8gZYkRI5csQ5jmsKLdKIhr89AiAsvIWII6ZBban4is0ppnCzdUwl39RtIY1H5akfVB/yDg=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkVKsVACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpogQ/7BpJMYSQf6Qdfo9PwxtoRsVvVQ9O6Y2okxkHQttKw8vroQ+OF\r\nUn7dn616crkaREvhfIAzS/uFTh7cQKIKXPfNTPVqEK6pdAm8pUELvphTs+WN\r\nLY+02WKeOpcQRWLhXbkQK8BPmRKBJ6MTjWoeRFPgaY4sEKKXfpom/YFtucm1\r\nokrphZLglR5ZE25iTTafNs3Wcpa8pv7fqASwl1WrUeUm1ZoKJ0srsrUceywa\r\n+ebEJAsfhqECVD5JyRoIMMq6//5qk4iwxXa28o9RnBa8oTpcOIAksCO8vMqf\r\n/DavVCabZQfL3+S9XVEaWfl6Xdv26bpmT7rI7N9hjkDCZBUhVe0csUEoPno7\r\nLggkpDFLfuI7VYlsQ04B9dhtNTwt8hPq8C8l0soLKDswoN01d8iXJdasXZuS\r\na6ZKR8YsogEZ8MaTkJR71Xh0fRPjNC0Bt0C2fThC1LzDeQlj3MIGeSjRs0v7\r\nR2uoveNeskIUpNKc8WYZeDkvrBW5r1b9dfgAHz4PWEQOrDJ3L4hFP11pAzLN\r\nhMSsANTV63BMcWQT5gsX0Uyy3X04QztMQ8sF49oN9QXY2IurX3/W9TphTb/x\r\n4tF9yvYcR8Zao+TIUoBXa0M+C3zN7pgzF7REZK4V1wTf7Veyo8fMFbnLzJj/\r\nxau/dZrao7+QM3MYjwFIrCjkYc+jIWj6np8=\r\n=waqF\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"nklomp78","email":"dev@sphereon.com"},"directories":{},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openid4vci-client_0.4.1-next.246_1683270421703_0.9039440532234204"},"_hasShrinkwrap":false}},"time":{"created":"2022-11-19T20:52:34.449Z","0.3.0":"2022-11-19T20:52:34.686Z","modified":"2023-05-05T07:07:02.007Z","0.3.1-unstable.0":"2022-11-19T21:56:26.980Z","0.3.1-unstable.1":"2022-11-20T00:08:32.128Z","0.3.1-unstable.2":"2022-11-20T02:43:11.934Z","0.3.1-unstable.3":"2022-11-20T03:31:54.832Z","0.3.1-unstable.4":"2022-11-20T03:44:20.941Z","0.3.1":"2022-11-20T11:58:33.898Z","0.3.2-unstable.1":"2022-11-21T11:26:28.460Z","0.3.2":"2022-11-21T11:53:48.520Z","0.3.3":"2022-11-24T12:18:23.439Z","0.3.4":"2022-11-24T12:42:31.009Z","0.3.5":"2023-01-10T20:50:41.276Z","0.3.6":"2023-01-12T00:27:26.763Z","0.4.0":"2023-03-17T00:37:14.523Z","0.4.1-unstable.30":"2023-03-18T22:23:31.683Z","0.4.1-next.31":"2023-03-18T22:34:23.471Z","0.4.1-unstable.50":"2023-03-18T23:10:43.864Z","0.4.1-unstable.51":"2023-03-20T08:41:48.852Z","0.4.1-unstable.54":"2023-03-20T09:58:57.449Z","0.4.1-unstable.55":"2023-03-20T13:50:29.802Z","0.4.1-unstable.32":"2023-03-22T10:32:33.471Z","0.4.1-unstable.58":"2023-03-22T12:31:20.982Z","0.4.1-unstable.59":"2023-03-22T12:32:25.825Z","0.4.1-unstable.61":"2023-03-22T12:58:00.064Z","0.4.1-unstable.33":"2023-03-22T15:01:11.470Z","0.4.1-unstable.36":"2023-03-23T11:11:31.582Z","0.4.1-unstable.64":"2023-03-23T11:16:34.462Z","0.4.1-unstable.62":"2023-03-23T13:02:26.987Z","0.4.1-unstable.63":"2023-03-23T13:05:17.691Z","0.4.1-unstable.67":"2023-03-23T13:59:07.040Z","0.4.1-unstable.68":"2023-03-23T14:00:44.343Z","0.4.1-unstable.69":"2023-03-23T14:05:25.956Z","0.4.1-unstable.37":"2023-03-23T15:46:44.339Z","0.4.1-unstable.41":"2023-03-27T17:19:13.051Z","0.4.1-unstable.70":"2023-03-28T08:51:17.305Z","0.4.1-unstable.71":"2023-03-28T08:52:28.679Z","0.4.1-next.42":"2023-03-28T23:27:51.329Z","0.4.1-unstable.45":"2023-03-29T08:37:30.907Z","0.4.1-unstable.46":"2023-03-29T11:30:13.986Z","0.4.1-unstable.47":"2023-03-29T11:32:30.107Z","0.4.1-unstable.48":"2023-03-29T11:59:03.253Z","0.4.1-unstable.49":"2023-03-29T13:46:03.941Z","0.4.1-unstable.43":"2023-03-29T21:46:25.066Z","0.4.1-unstable.44":"2023-03-29T22:25:13.779Z","0.4.1-unstable.52":"2023-03-30T10:29:01.063Z","0.4.1-unstable.53":"2023-03-30T11:32:34.320Z","0.4.1-unstable.56":"2023-03-30T12:48:24.038Z","0.4.1-unstable.57":"2023-03-30T12:53:33.330Z","0.4.1-next.59":"2023-03-31T07:11:58.465Z","0.4.1-next.71":"2023-03-31T09:36:37.792Z","0.4.1-unstable.73":"2023-03-31T15:13:47.687Z","0.4.1-unstable.74":"2023-04-03T09:35:13.634Z","0.4.1-unstable.84":"2023-04-03T11:20:17.432Z","0.4.1-unstable.72":"2023-04-03T11:25:15.779Z","0.4.1-unstable.75":"2023-04-03T12:35:40.504Z","0.4.1-unstable.76":"2023-04-03T13:43:40.039Z","0.4.1-unstable.77":"2023-04-03T14:38:21.364Z","0.4.1-unstable.78":"2023-04-04T07:23:54.589Z","0.4.1-unstable.85":"2023-04-04T11:05:52.242Z","0.4.1-unstable.80":"2023-04-04T11:55:34.014Z","0.4.1-unstable.87":"2023-04-04T13:11:44.012Z","0.4.1-unstable.89":"2023-04-04T14:14:43.239Z","0.4.1-unstable.100":"2023-04-04T14:58:55.435Z","0.4.1-unstable.101":"2023-04-04T15:06:05.643Z","0.4.1-unstable.88":"2023-04-05T08:28:58.296Z","0.4.1-unstable.102":"2023-04-05T08:38:07.430Z","0.4.1-unstable.111":"2023-04-05T09:00:20.983Z","0.4.1-unstable.103":"2023-04-05T11:23:23.869Z","0.4.1-unstable.104":"2023-04-05T11:56:04.115Z","0.4.1-unstable.112":"2023-04-05T12:32:40.793Z","0.4.1-unstable.90":"2023-04-05T12:58:53.599Z","0.4.1-unstable.91":"2023-04-05T13:16:31.832Z","0.4.1-unstable.92":"2023-04-05T13:26:36.870Z","0.4.1-unstable.93":"2023-04-06T07:43:23.359Z","0.4.1-unstable.94":"2023-04-06T08:44:08.584Z","0.4.1-unstable.96":"2023-04-06T09:02:43.092Z","0.4.1-unstable.97":"2023-04-06T09:12:17.108Z","0.4.1-unstable.98":"2023-04-06T09:17:46.297Z","0.4.1-next.72":"2023-04-06T11:19:07.460Z","0.4.1-unstable.99":"2023-04-06T11:30:51.105Z","0.4.1-next.106":"2023-04-06T21:55:06.461Z","0.4.1-next.158":"2023-04-07T00:47:49.604Z","0.4.1-next.159":"2023-04-07T00:50:55.809Z","0.4.1-next.160":"2023-04-07T00:55:22.549Z","0.4.1-unstable.161":"2023-04-11T14:38:09.622Z","0.4.1-unstable.170":"2023-04-17T13:25:04.541Z","0.4.1-unstable.171":"2023-04-19T11:18:41.382Z","0.4.1-next.162":"2023-04-20T07:01:21.939Z","0.4.1-unstable.172":"2023-04-20T08:10:44.549Z","0.4.1-unstable.163":"2023-04-20T08:53:44.939Z","0.4.1-unstable.176":"2023-04-20T10:24:48.988Z","0.4.1-unstable.164":"2023-04-20T10:45:53.019Z","0.4.1-unstable.165":"2023-04-20T10:53:47.386Z","0.4.1-unstable.177":"2023-04-20T11:45:06.163Z","0.4.1-unstable.178":"2023-04-20T11:52:18.094Z","0.4.1-unstable.180":"2023-04-20T12:05:37.683Z","0.4.1-unstable.181":"2023-04-20T12:16:33.021Z","0.4.1-unstable.166":"2023-04-20T12:50:38.313Z","0.4.1-unstable.182":"2023-04-20T13:44:31.341Z","0.4.1-unstable.183":"2023-04-20T14:50:18.762Z","0.4.1-next.192":"2023-04-20T14:57:20.407Z","0.4.1-unstable.202":"2023-04-24T11:43:48.741Z","0.4.1-unstable.203":"2023-04-25T08:03:29.891Z","0.4.1-unstable.204":"2023-04-25T08:10:33.968Z","0.4.1-unstable.205":"2023-04-25T09:52:14.286Z","0.4.1-unstable.206":"2023-04-25T09:54:53.623Z","0.4.1-unstable.207":"2023-04-25T12:33:39.023Z","0.4.1-unstable.208":"2023-04-25T14:54:00.052Z","0.4.1-unstable.209":"2023-04-25T15:39:20.876Z","0.4.1-unstable.210":"2023-04-25T15:55:58.178Z","0.4.1-unstable.213":"2023-04-26T11:18:43.024Z","0.4.1-next.214":"2023-04-26T14:07:15.228Z","0.4.1-unstable.220":"2023-04-28T15:20:48.256Z","0.4.1-unstable.221":"2023-04-28T15:46:56.523Z","0.4.1-unstable.227":"2023-05-02T10:12:40.614Z","0.4.1-unstable.238":"2023-05-03T15:40:11.299Z","0.4.1-unstable.242":"2023-05-04T10:15:40.049Z","0.4.1-unstable.243":"2023-05-04T14:10:29.044Z","0.4.1-unstable.245":"2023-05-04T14:45:21.124Z","0.4.1-next.246":"2023-05-05T07:07:01.848Z"},"maintainers":[{"name":"nklomp78","email":"dev@sphereon.com"},{"name":"nklomp","email":"nklomp@sphereon.com"},{"name":"spostma","email":"spostma@sphereon.com"},{"name":"bramtencate","email":"btencate@sphereon.com"}],"description":"OpenID for Verifiable Credential Issuance (OpenID4VCI) client","keywords":["Sphereon","Verifiable Credentials","OpenID","OpenID for Verifiable Credential Issuance","OAuth2","SSI","OpenID4VCI","OIDC4VCI","OID4VCI"],"author":{"name":"Sphereon"},"license":"Apache-2.0","readme":"","readmeFilename":""}