|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | + <head> |
| 4 | + <title>Publish to IPNS from the browser</title> |
| 5 | + <link |
| 6 | + rel="stylesheet" |
| 7 | + href=" https://unpkg.com/[email protected]/css/tachyons.min.css" |
| 8 | + /> |
| 9 | + <link rel=" stylesheet" href=" https://unpkg.com/[email protected]/ipfs.css" /> |
| 10 | + </head> |
| 11 | + <body class="sans-serif"> |
| 12 | + <header class="pv3 ph2 ph3-l bg-navy cf mb4"> |
| 13 | + <a href="https://ipfs.io/" title="ipfs.io"> |
| 14 | + <img |
| 15 | + src="https://ipfs.io/images/ipfs-logo.svg" |
| 16 | + class="v-mid" |
| 17 | + style="height: 50px;" |
| 18 | + /> |
| 19 | + </a> |
| 20 | + <h1 class="aqua fw2 montserrat dib ma0 pv2 ph1 v-mid fr f3 lh-copy"> |
| 21 | + IPNS Publish from JS to Go Peer |
| 22 | + </h1> |
| 23 | + </header> |
| 24 | + <div class="ph3 mb3"> |
| 25 | + <div class="fw2 tracked ttu f6 teal-muted mb2"> |
| 26 | + IPNS PUBLISH SET-UP STEPS |
| 27 | + </div> |
| 28 | + <main class="page" data-v-4f5abb4a=""> |
| 29 | + <div class="theme-default-content content__default" data-v-4f5abb4a=""> |
| 30 | + <div |
| 31 | + class="custom-block callout" |
| 32 | + style="font-size: 0.75em; width: 75%; margin: 1em;" |
| 33 | + > |
| 34 | + <p> |
| 35 | + Code repo for this demo |
| 36 | + <a |
| 37 | + href="https://github.com./js-ipfs/examples/browser-ipns-publish/" |
| 38 | + >on Github</a |
| 39 | + > |
| 40 | + </p> |
| 41 | + <p> |
| 42 | + The idea is to publish from js-ipfs so you control your own |
| 43 | + private keys, but publish to go-ipfs to benefit from the DHT. |
| 44 | + Since the DHT in js-ipfs is still in the experimental phase, we need to use PubSub |
| 45 | + and have a go-ipfs node subscribed to that PubSub to get our IPNS |
| 46 | + record onto the DHT. In order to use PubSub between these two |
| 47 | + nodes, you'll need a websocket to connect them. |
| 48 | + </p> |
| 49 | + <div> |
| 50 | + To make this demo work, you're going to need: |
| 51 | + <ul> |
| 52 | + <li style="list-style-type: none;"> |
| 53 | + <b>1. Access to a go-ipfs node and it's API</b>, a-la |
| 54 | + <pre>/dns4/domain.com/tcp/5001</pre> |
| 55 | + </li> |
| 56 | + <li> |
| 57 | + This is how the demo talks to the server, to ensure things |
| 58 | + like: |
| 59 | + </li> |
| 60 | + <ul> |
| 61 | + <li> |
| 62 | + A) pubsub is enabled, { EXPERIMENTAL: { ipnsPubsub: true } } |
| 63 | + and --enable-pubsub-experiment |
| 64 | + </li> |
| 65 | + <li> |
| 66 | + B) go-ipfs is connected to the js-ipfs node in the browser, |
| 67 | + via node.swarm.peers(), |
| 68 | + </li> |
| 69 | + <li> |
| 70 | + C) the pubsub messages are getting through to the go node, |
| 71 | + via node.pubsub.subscribe(). |
| 72 | + </li> |
| 73 | + </ul> |
| 74 | + </ul> |
| 75 | + <ul> |
| 76 | + <li style="list-style-type: none;"> |
| 77 | + <b>2. Access to a go-ipfs Websocket port</b>, a-la |
| 78 | + <pre>/dns4/domain.com/tcp/4003/wss/p2p/QmTheDomainPeerId</pre> |
| 79 | + </li> |
| 80 | + <li> |
| 81 | + Since we need PubSub for IPNS to reach the go-IPFS node (and |
| 82 | + further replicate through the go-DHT network) we need to |
| 83 | + connect our pubsub enabled JS-IPFS node in the browser to our |
| 84 | + go-IPFS node on the server. The way we connect is via |
| 85 | + Websocket. See |
| 86 | + <a |
| 87 | + href="https://github.com./ipfs/js-ipfs/tree/master/packages/ipfs-http-client/examples/browser-pubsub" |
| 88 | + >this example</a |
| 89 | + > |
| 90 | + for reference. |
| 91 | + </li> |
| 92 | + </ul> |
| 93 | + <p> |
| 94 | + Once we can talk to go-IPFS and we're connected via Websocket, |
| 95 | + then we can publish in our browser node, have the pubsub push it |
| 96 | + to the go-IPFS server, and then check with the server that it's |
| 97 | + confirmed as published. Once it's on the go-IPFS node it should |
| 98 | + replicate throughout the rest of the DHT amongst the go-Nodes. |
| 99 | + </p> |
| 100 | + </div> |
| 101 | + </div> |
| 102 | + </div> |
| 103 | + </main> |
| 104 | + </div> |
| 105 | + <div class="ph3 mb3"> |
| 106 | + <div class="fw2 tracked ttu f6 teal-muted mb2"> |
| 107 | + 1. Connect to Go-IPFS via API MultiAddress |
| 108 | + </div> |
| 109 | + <input |
| 110 | + id="api-url" |
| 111 | + class="dib w-50 ph1 pv2 monospace input-reset ba b--black-20 border-box" |
| 112 | + placeholder="/dns4/yourdomain.com/tcp/5001" |
| 113 | + disabled="disabled" |
| 114 | + /> |
| 115 | + <button |
| 116 | + id="node-connect" |
| 117 | + class="dib ph3 pv2 input-reset ba b--black-20 border-box" |
| 118 | + disabled="disabled" |
| 119 | + > |
| 120 | + Connect |
| 121 | + </button> |
| 122 | + </div> |
| 123 | + <div class="ph3 mb3"> |
| 124 | + <div class="fw2 tracked ttu f6 teal-muted mb2"> |
| 125 | + 2. Connect to Go-IPFS via Websocket MultiAddress (for PubSub to work) |
| 126 | + </div> |
| 127 | + <input |
| 128 | + id="peer-addr" |
| 129 | + class="dib w-50 ph1 pv2 monospace input-reset ba b--black-20 border-box" |
| 130 | + placeholder="/dns4/yourdomain.com/tcp/4003/wss/p2p/QmTheirServerPeerId" |
| 131 | + disabled="disabled" |
| 132 | + /> |
| 133 | + <button |
| 134 | + id="peer-connect" |
| 135 | + class="dib ph3 pv2 input-reset ba b--black-20 border-box" |
| 136 | + disabled="disabled" |
| 137 | + > |
| 138 | + Connect |
| 139 | + </button> |
| 140 | + </div> |
| 141 | + |
| 142 | + <div class="ph3 mb3"> |
| 143 | + <div class="fw2 tracked ttu f6 teal-muted mb2"> |
| 144 | + 3. Choose a key: |
| 145 | + </div> |
| 146 | + <form> |
| 147 | + <ul style="list-style-type: none;"> |
| 148 | + <li> |
| 149 | + <input type="radio" id="male" name="keyName" value="self" checked /> |
| 150 | + <label for="male" |
| 151 | + >Self (the |
| 152 | + <a |
| 153 | + href="https://github.com./ipfs/js-ipfs/blob/master/docs/core-api/KEY.md#ipfskeylistoptions" |
| 154 | + target="_blank" |
| 155 | + >PeerId of the runing node</a |
| 156 | + >)</label |
| 157 | + ><br /> |
| 158 | + </li> |
| 159 | + <li> |
| 160 | + <input type="radio" id="female" name="keyName" value="custom-key" disabled="disabled" /> |
| 161 | + <label for="female" |
| 162 | + >Custom Key (<a |
| 163 | + href="https://github.com./ipfs/js-ipfs/blob/master/docs/core-api/KEY.md#ipfskeyimportname-pem-password-options" |
| 164 | + target="_blank" |
| 165 | + >imported</a |
| 166 | + > |
| 167 | + onto the keychain) [waiting for <a href="https://github.com./ipfs/go-ipfs/issues/6360">#6360</a> to work]</label |
| 168 | + ><br /> |
| 169 | + </li> |
| 170 | + </ul> |
| 171 | + </form> |
| 172 | + </div> |
| 173 | + <div class="ph3 mb3"> |
| 174 | + <div class="fw2 tracked ttu f6 teal-muted mb2"> |
| 175 | + 4. IPFS hash to publish |
| 176 | + </div> |
| 177 | + <input |
| 178 | + id="topic" |
| 179 | + class="dib w-50 ph1 pv2 monospace input-reset ba b--black-20 border-box" |
| 180 | + disabled="disabled" |
| 181 | + /> |
| 182 | + <button |
| 183 | + id="publish" |
| 184 | + class="dib ph3 pv2 input-reset ba b--black-20 border-box" |
| 185 | + disabled="disabled" |
| 186 | + > |
| 187 | + Publish to IPNS |
| 188 | + </button> |
| 189 | + </div> |
| 190 | + |
| 191 | + <div class="ph3 mb3"> |
| 192 | + <div class="fw2 tracked ttu f6 teal-muted mb2">Browser Console</div> |
| 193 | + <div |
| 194 | + id="console" |
| 195 | + class="f7 db w-100 ph1 pv2 monospace input-reset ba b--black-20 border-box overflow-scroll" |
| 196 | + style="height: 300px;" |
| 197 | + ></div> |
| 198 | + </div> |
| 199 | + <div class="ph3 mb3"> |
| 200 | + <div class="fw2 tracked ttu f6 teal-muted mb2">Server Console</div> |
| 201 | + <div |
| 202 | + id="server-console" |
| 203 | + class="f7 db w-100 ph1 pv2 monospace input-reset ba b--black-20 border-box overflow-scroll" |
| 204 | + style="height: 300px;" |
| 205 | + ></div> |
| 206 | + </div> |
| 207 | + <script src="index.js"></script> |
| 208 | + </body> |
| 209 | +</html> |
0 commit comments