Commit 0c3ee03e authored by Johan Nordberg's avatar Johan Nordberg
Browse files

Document API

parent 3267eec4
......@@ -22,41 +22,106 @@ Run `make lint` to run the autolinter, `make test` to run the unit tests.
Defaults are in <./config/default.toml> and can be overridden by env vars as defined in <./config/custom-enviroment-variables.toml>
Defaults are in <./config/default.toml> and can be overridden by env vars as defined in <./config/custom-environment-variables.toml>
Load order is: env vars > `config/$NODE_ENV.toml` > `config/default.toml`
See the `config` module docs for more details.
#### Usage
Responses should be determined by the Content-Type header, errors will have a status of `>=400` and a Content-Type of `application/json` with the body in the format:
"error": {
"name": "error_name",
"info": {"optional": "metadata"}
### `POST /<username>/<signature>` - upload an image.
Multipart image upload, will only consider first file if there are multiple.
Returns a JSON object containing the url to the uploaded image, example:
"url": ""
Requires a signature from a Steem account in good standing, see the "Signing uploads" section below for more information.
### `GET /<image_hash>/[<filename>]` - fetch an uploaded image.
Download a previously uploaded image.
`filename` is optional but can be provided to help users and applications understand the content type (Content-Type header will still always reflect actual image type).
> curl -v -F "data=@<path_to_file>" http://localhost:3234/<blockchain_username>/<hex(sign(hash256(data), d))>
### `GET /<width>x<height>/<image_url>` - proxy and resize an image.
> curl -L http://localhost:3234/<ipfsHash(data)>/<[optional_file_name]>
Downloads and serves the provided `image_url`, note that a copy will be taken of the image and that will be served on subsequent requests so even if the upstream is removed or changes you will still get the original from the proxy endpoint.
`width` and `height` can be set to `0` to preserve the image dimensions, if they are `>0` the image will be aspect resized (down-sample only) to fit inside the rectangle.
### `GET /u/<username>/avatar/[<size>]` - get user avatar image.
Serves the avatar for `username`, if no avatar is set a default image will be served (set in service config).
Sizes are:
* `small` - 64x64
* `medium` - 128x128
* `large` - 512x512
Note that the avatars follow the same sizing rules as proxied images, so you are not guaranteed to get a square image, just an image fitting inside of the `size` square.
Signing uploads
Uploads require a signature made with by a Steem account's posting authority, further that account has to be above a (service configurable) reputation threshold.
Creating a signature (psuedocode):
signature = secp256k1_sign(sha256('ImageSigningChallenge'+image_data), account_private_posting_key)
The `optional_file_name` is ignored but should be provided to help users and applications understand the URL.
Creating a signature (node.js & [dsteem](
#### Example Download
#!/usr/bin/env node
> curl -L http://localhost:3234/QmXJShecaM2pvkcax4Lt6h3Q6wBn1ZhESB6dFkfwSPLuN4/blue_red_pill.jpg > $HOME/Pictures/blue_red_pill.jpg
const dsteem = require('dsteem')
const crypto = require('crypto')
const fs = require('fs')
#### Example Upload (user `steem` signed using a test key)
const [wif, file] = process.argv.slice(2)
> curl -v -F "data=@$HOME/Pictures/blue_red_pill.jpg" http://localhost:3234/steem/205d8bcafb9e0e0897e2db330aa2bd1ca4f7764ad9b1ba04a2a9651453aee72f4a685bd631ad60111f8018fd65d3fc7e951c0039476c270e859bb6760836dcb40d
if (!wif || !file) {
process.stderr.write(`Usage: ./sign.js <posting_wif> <file>\n`)
## Create a signature
const data = fs.readFileSync(file)
const key = dsteem.PrivateKey.fromString(wif)
const imageHash = crypto.createHash('sha256')
process.stdout.write(key.sign(imageHash).toString() + '\n')
import {PrivateKey, Signature} from 'shared/ecc'
const bufSha = new Buffer('a190c0596a37398427e51bcbee7c94f1007075629828d62005735c6c2d2ffeef', 'hex')
const d = PrivateKey.fromSeed('') // blockchain_username's posting_private_key
const sig = Signature.signBufferSha256(bufSha, d)
console.log('Signature', sig.toHex())
$ ./sign.js 5J9jN691Gf3MKdwvqWVx54drx9qub6koyA3mjhenyN12CURua8W test.jpg
Outputs: `205d8bcafb9e0e0897e2db330aa2bd1ca4f7764ad9b1ba04a2a9651453aee72f4a685bd631ad60111f8018fd65d3fc7e951c0039476c270e859bb6760836dcb40d`
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment