Created
January 9, 2011 14:28
-
-
Save DanielG/771724 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <script type="text/javascript" src="../../scripts/require.js" data-main="./blog.js"></script> | |
| <body> | |
| <h2>This code is only for demonstration and not safe to run in production.</h2> | |
| <h2>Only run it in a local development environment, never on a public IP or production server.</h2> | |
| <div id="blogposts">Loading unhosted json...</div> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function blogError(err){ | |
| document.getElementById('blogposts').innerHTML = 'ERROR: ' + err.message; | |
| } | |
| require({ baseUrl: "/scripts/", waitSeconds: 2 } | |
| , ['unhosted', 'user', 'crypto', 'key-storage', 'step'] | |
| , blog); | |
| function blog(Unhosted, User, crypto, keyStorage, Step){ | |
| // Usually the rsa key would be retrived on login | |
| var n = '3e5af785629a8f35ec67f71fd0ee388f43472c1f6413467a29f0ebaf0f56bcba4245bd77e8d526d59e69ea3d50a33b7bcf7e67df22dfc662f5d8eb346bbd2bffdd0993ebae2e022f5dc75eaac09b4f7d2ec6f45d7a2a50be4ecdad4b7282221e904ee810274102e2faf4bc2f34fc4bcb1ec3b53178ef9176e5e222a398b05ddf667973331d0b3c7c36b81a365a7c428c4a95aebaaea3b8aecf34f985a293b6cd'; | |
| var e = '10001'; | |
| var d = '19c13eed33fdfcdadbeb51322dfcc715bd471f5d53db7647ad1d1a6bb31d3354875d00d60f30431b06945eb0b6a6c541ed411bac195e6e359fafd9ee4bf5d5bf97cf85ee59821d5aed1414f0d81f0e247b81542d43eea345d60b9f316cecf317e4fdea57f62dbdf5c974b256ef86f4b5b1ffddca750ca24de67973a32560c0bbfd19520aa8b91374cb7d8b6017a0d8ad7b6802a497faa0d1b429a19cc77e4901'; | |
| var key = new crypto.rsa.PrivKey(n, e, d); | |
| // Store the key for later use | |
| var keyID = keyStorage.storePrivKey(key); | |
| var node = null; | |
| var nodeUser = null; | |
| Step( | |
| function init(){ | |
| nodeUser = new User('me@example.com'); | |
| nodeUser.password = '1234'; | |
| nodeUser.keyID = keyID; | |
| nodeUser.getID(this); | |
| } | |
| , function getPost(userID){ | |
| node = new Unhosted(nodeUser, document.location.host); | |
| node._get('/AwesomeBlog/posts/0', this); | |
| } | |
| , function(err, data){ | |
| if(err) { blogError(err); return; } | |
| } | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment