├── .github └── workflows │ ├── generated-pr.yml │ └── stale.yml ├── .gitignore ├── LICENSE ├── README.md ├── package-lock.json ├── package.json └── src ├── index.html └── index.js /.github/workflows/generated-pr.yml: -------------------------------------------------------------------------------- 1 | name: Close Generated PRs 2 | 3 | on: 4 | schedule: 5 | - cron: '0 0 * * *' 6 | workflow_dispatch: 7 | 8 | permissions: 9 | issues: write 10 | pull-requests: write 11 | 12 | jobs: 13 | stale: 14 | uses: ipdxco/unified-github-workflows/.github/workflows/reusable-generated-pr.yml@v1 15 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | name: Close Stale Issues 2 | 3 | on: 4 | schedule: 5 | - cron: '0 0 * * *' 6 | workflow_dispatch: 7 | 8 | permissions: 9 | issues: write 10 | pull-requests: write 11 | 12 | jobs: 13 | stale: 14 | uses: ipdxco/unified-github-workflows/.github/workflows/reusable-stale-issue.yml@v1 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Henrique Dias 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IPFS ID and Public Key example 2 | 3 | > Simple demo app that connects to API port of IPFS node, reads its PeerID and displays it as QR code. 4 | > 5 | > **Note:** ⚠️ this is just a PoC, not meant for production use. Due to the way browser security model works, this example requires CORS safelisting via `API.HTTPHeaders.Access-Control-Allow-Origin` 6 | 7 | > ![2021-06-21--17-57-49](https://user-images.githubusercontent.com/157609/122792237-45b26000-d2ba-11eb-8681-55485692fd72.png) 8 | 9 | 10 | Demo: https://bafybeib77af5a2ymrhl2etf4hq2x32o7qs3shkaatznyjxrhnipksjkh4i.ipfs.dweb.link (needs to be appended to `API.HTTPHeaders.Access-Control-Allow-Origin`) 11 | 12 | ## Install 13 | 14 | 1. This requires the user to have an [IPFS node running](https://ipfs.io/#install) with the app Origin added to `API.HTTPHeaders.Access-Control-Allow-Origin` 15 | 2. Install dependencies `npm install` 16 | 3. Build the app `npm run build` 17 | 4. Start the app `npm start` 18 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ipfs-id-qr-codes", 3 | "description": "A sample app using window.ipfs to build QR codes of the Private Key and Peer IPNS Address", 4 | "version": "1.0.2", 5 | "private": true, 6 | "author": "Henrique Dias ", 7 | "main": "dist/index.html", 8 | "scripts": { 9 | "start": "ecstatic dist", 10 | "clean": "shx rm -rf dist", 11 | "build": "run-s build:*", 12 | "build:copy": "run-p build:copy:*", 13 | "build:copy:html": "shx mkdir -p dist && shx cp src/index.html dist/index.html", 14 | "build:copy:ipfs-css": "run-p build:copy:ipfs-css:*", 15 | "build:copy:ipfs-css:css": "shx mkdir -p dist && shx cp node_modules/ipfs-css/ipfs.css dist", 16 | "build:copy:ipfs-css:fonts": "shx mkdir -p dist/fonts && shx cp node_modules/ipfs-css/fonts/* dist/fonts", 17 | "build:copy:tachyons": "shx mkdir -p dist && shx cp node_modules/tachyons/css/tachyons.css dist", 18 | "build:js": "browserify -g uglifyify src/index.js -o dist/bundle.js", 19 | "test": "standard" 20 | }, 21 | "license": "MIT", 22 | "keywords": [ 23 | "ipfs", 24 | "qr", 25 | "example", 26 | "demo" 27 | ], 28 | "dependencies": { 29 | "ipfs-css": "^1.3.0", 30 | "ipfs-http-client": "^50.1.1", 31 | "ipfs-provider": "^2.0.1", 32 | "qrcode-generator": "^1.4.4", 33 | "tachyons": "^4.12.0" 34 | }, 35 | "devDependencies": { 36 | "browserify": "^17.0.0", 37 | "ecstatic": "^4.1.4", 38 | "npm-run-all": "^4.1.5", 39 | "shx": "^0.3.3", 40 | "standard": "^16.0.3", 41 | "uglifyify": "^5.0.2" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | IPFS QR Codes 5 | 6 | 7 | 8 | 9 | 18 | 19 | 20 |
21 | 22 | 23 | 24 |
25 | 26 |
27 |
28 | Using ipfs-http-client, we try to connect to the default IPFS address 29 | on your computer, and then we are able to get your peer information and generate a 30 | QR Code with your IPNS Link and your public key. 31 |
32 | 33 |
34 | 35 |
36 |
37 |
38 |

IPNS Link

39 | 40 |
41 | 42 |
43 |

Public Key

44 |
45 |
46 |
47 |
48 | 49 |
50 | Peer ID:
51 | IPNS Link: 52 |
53 |
54 | 55 | 56 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | const { getIpfs, providers } = require('ipfs-provider') 2 | const qrcode = require('qrcode-generator') 3 | 4 | function makeQR (data, id) { 5 | // Build QR 6 | const qr = qrcode(0, 'L') 7 | qr.addData(data) 8 | qr.make() 9 | 10 | // Create Base64 11 | let tag = qr.createSvgTag() 12 | tag = tag.replace('black', '#0b3a53', -1) 13 | const base64 = window.btoa(tag) 14 | 15 | // Fill element 16 | const el = document.getElementById(id) 17 | el.innerHTML = `` 18 | } 19 | 20 | function showError (e) { 21 | console.error(e) 22 | const el = document.getElementById('error') 23 | el.classList.remove('dn') 24 | el.innerHTML = e.message 25 | } 26 | 27 | document.addEventListener('DOMContentLoaded', async () => { 28 | const res = await getIpfs({ 29 | loadHttpClientModule: () => require('ipfs-http-client').create, 30 | providers: [ 31 | providers.httpClient({ 32 | apiAddress: '/ip4/127.0.0.1/tcp/5001' 33 | }), 34 | providers.httpClient() 35 | ] 36 | }) 37 | 38 | if (!res) { 39 | showError(new Error('Could not find an active IPFS instance.')) 40 | return 41 | } 42 | 43 | const ipfs = res.ipfs 44 | 45 | try { 46 | const { id, publicKey } = await ipfs.id() 47 | const ipnsLink = `https://gateway.ipfs.io/ipns/${id}` 48 | 49 | // Display and make QRs 50 | document.getElementById('qrs').classList.remove('dn') 51 | makeQR(ipnsLink, 'ipns-link') 52 | makeQR(publicKey, 'pub-key') 53 | 54 | // Display peer info 55 | document.getElementById('infos').classList.remove('dn') 56 | document.getElementById('id').innerHTML = id 57 | document.getElementById('ipns-link-raw').innerHTML = ipnsLink 58 | } catch (err) { 59 | showError(err) 60 | } 61 | }) 62 | --------------------------------------------------------------------------------