├── README.md └── SiteLoader ├── BitDiary Secondary Siteloader.html ├── README.md ├── RSA_SiteLoader.html └── RSA_SiteUpdater.html /README.md: -------------------------------------------------------------------------------- 1 | # MetaNet-Website 2 | Demos and Instructions on How to Build a Website on BSV MetaNet. 3 | 4 | ## Get Started 5 | 6 | 1. Build a HTML page 7 | 2. upload it to bitcoin at b.bitdb.network 8 | 9 | ## Topic 10 | 11 | ### SiteLoader 12 | 13 | Siteloader is kind of middleware that help browser access metanet website. 14 | 15 | A website loader prepare pages, scripts and other resources from blockchain. 16 | 17 | See [Siteloader](./SiteLoader) 18 | 19 | For multi page website, see [metasite-loader](https://github.com/monkeylord/MetaSite-Loader) 20 | 21 | ### Data 22 | 23 | See [Bitcoin Application Data protocol](https://github.com/monkeylord/BAD) 24 | 25 | The basic principles are 26 | 27 | 1. Each data(Or data group) should have it's own key, we call it DataKey. 28 | 2. From DataKey and other information, a deterministic cryptic prefix can be derived, which allow DataKey and only DataKey to search. 29 | 3. Data should be encrypted with key that derived deterministic from DataKey, which allow DataKey and only DataKey to decrypt. 30 | 4. Data should be signed with key derived deterministic from DataKey. 31 | 32 | ### User 33 | 34 | In metanet, user is identity, which may be a master private key. 35 | 36 | Neither the identity key nor its public key should exposed to public. 37 | 38 | One should not use identity key to sign or transact. 39 | 40 | 41 | 42 | All the other key are derived from identity key. 43 | 44 | The derivation path from identity key should be hardened to make sure identity key is not recoverable. 45 | 46 | The derivation path from its child keys can be hardened (e.g DataKey) or unhardened (e.g FilesystemKey). 47 | 48 | Unhardened derivation allow deriving child public key from parent public key. 49 | 50 | ### Transaction 51 | 52 | integrate Moneybutton in your html page. 53 | 54 | implement a simple wallet whose xpriv is derived from identity key. 55 | 56 | ### Crypto 57 | 58 | ### Parameters 59 | 60 | Parameters from `#` 61 | 62 | ### Security 63 | 64 | ### API and Protocol 65 | 66 | ## Advanced 67 | 68 | ### Chatroom 69 | 70 | ### Games on Chain 71 | 72 | ### News 73 | 74 | ### forum -------------------------------------------------------------------------------- /SiteLoader/BitDiary Secondary Siteloader.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /SiteLoader/README.md: -------------------------------------------------------------------------------- 1 | ## SiteLoader 2 | 3 | ### What is SiteLoader? 4 | 5 | Siteloader is kind of middleware that help browser access metanet website. 6 | 7 | A website loader prepare pages, scripts and other resources from blockchain. 8 | 9 | Generally, a siteloader 10 | 11 | 1. Acquire latest sitemap from blockchain. 12 | 2. Preload scripts and resources. 13 | 3. Handle path and redirection. 14 | 15 | ### Why Siteloader? 16 | 17 | For metanet, bitcoin network itself is wrapped public database which is immutable. 18 | 19 | It still needs abstraction and middleware to build something complicated. 20 | 21 | > e.g. on-chain or not on chain, you still need name service for a human readable address. 22 | 23 | Basically, gateways like bico.media are also siteloader, but you may want more. 24 | 25 | And, maybe most important, siteloader can be the unchanging entrance for a metanet website. 26 | 27 | ### How to Build/Use SiteLoader? 28 | 29 | #### Endpoint 30 | 31 | BitDB or Insight-api , you need decide how to access blockchain from browser. 32 | 33 | Bisides, endpoint may not always be trustworthy, so relying a single endpoint is not recommended. 34 | 35 | I use BitDB, cause it's easy to query, you can build and verify query on BitDB explorer. 36 | 37 | #### Acquring Latest Sitemap 38 | 39 | There are several ways to acquire latest sitemap. 40 | 41 | A basic approach is to wrap it into a signed on-chain data that can be queried. 42 | 43 | So the on-chain data model contains 3 parts: 44 | 45 | 1. Prefix for query, cryptic prefix or non-cryptic prefix. 46 | 2. Sitemap data, encrypted or not encrypted. 47 | 3. Signature, ECDSA or non-ECDSA. 48 | 49 | Then you can build the OP_RETURN data model. 50 | 51 | ~~~javascript 52 | function buildScript(prefixbuf, databuf, signaturebuf) { 53 | var script = bsv.Script.buildDataOut(prefixbuf) 54 | script.add(databuf) 55 | script.add(signaturebuf) 56 | return script 57 | } 58 | 59 | function bitdbQuery(prefix){ 60 | return { 61 | "q": { 62 | "find": { "out.s1": prefix} 63 | }, 64 | "r": { 65 | "f": "[ .[] | {data: .out[0].s2, signature: .out[0].s3, blk:.blk.i} ]" 66 | } 67 | } 68 | } 69 | 70 | //Don't forget to verify signature. 71 | //Signature should include prefix. 72 | ~~~ 73 | 74 | #### Using Sitemap 75 | 76 | It's for your convenience that using sitemap. 77 | 78 | Basically, you redirect browser to index page, which is quite simple. 79 | 80 | There are multiple approach, like iframe, document, service worker. 81 | 82 | ~~~javascript 83 | function renderPage (txid){ 84 | // clean up the old page. 85 | document.open() 86 | // load new page from tx 87 | fetch("./"+txid).then(res=>res.text()).then(html=>document.write(html)) 88 | } 89 | ~~~ 90 | 91 | Then you may want to preload your script. An AMD module loader may be great, but eval is ok. 92 | 93 | ~~~javascript 94 | // Eval is OK here, for on-chain script are trustworthy. 95 | window.eval(script) 96 | ~~~ 97 | 98 | For other resources, you may want to have a service worker, but using TXID directly is also fine. 99 | 100 | #### Mapping URL to TXID 101 | 102 | That will need service worker 103 | 104 | ### Demo 105 | 106 | #### RSA-signature based Siteloader 107 | 108 | The reason why using RSA instead of ECDSA is because 109 | 110 | 1. BSV library is relatively heavy. 111 | 2. ASN.1 format Key is immigration candidate for traditional certificate. 112 | 113 | ##### The Siteloader 114 | 115 | See RSA_SiteLoader.html 116 | 117 | ##### The SiteUpdater 118 | 119 | SiteUpdater commits sitemap to blockchain. 120 | 121 | See RSA_SiteUpdater.html 122 | 123 | ##### Secondary SiteLoader 124 | 125 | Used as sitemap in BitDiary. 126 | 127 | Actually is a siteloader loaded by siteloader. 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /SiteLoader/RSA_SiteLoader.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | Loading, Please Wait.... 10 | 79 | 80 | -------------------------------------------------------------------------------- /SiteLoader/RSA_SiteUpdater.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |