blockades / scuttle-dark-crystal

API for validating, building, publishing and reading Dark Crystal records
http://darkcrystal.pw
MIT License
42 stars 2 forks source link

dark-crystal HTTP API #46

Open m4gpi opened 5 years ago

m4gpi commented 5 years ago

This is different from https://github.com/blockades/scuttle-dark-crystal/issues/45. A Dark Crystal HTTP API would open up the a set of end-points to scuttle-dark-crystal (rather than just the secrets wrapper), enabling other applications to use Dark Crystal and Scuttlebutt via a set of end-points.

This is a larger body of work than the secrets wrapper API. It requires creating a scuttlebot server instance (or connecting to an existing instance, see scuttle-shell) and initialising scuttle-dark-crystal there, and exposing its access to and interaction with the SSB database as a HTTP API.

Includes the following end-points:

// gets the ritual and its component parts
GET /v1/rituals/:id

// performs the ritual, requires parameters
POST /v1/share

// Gets the requests applicable to a specific root / ritual
GET /v1/requests/:id
POST /v1/requests/:id

// requests have a one-to-one relationship to replies
GET /v1/requests/:id/reply
POST /v1requests/:id/reply

// returns the secret, requires parameters
POST /v1/recombine/:id

// forwards shards to a recipient, requires parameters
POST /v1/forwards

An example use-case:

var params = {
  name: 'My first Dark Crystal',
  label: 'Bitcoin Private Key',
  secret: 'KyP4ki12YcX2Fo4gw6DRdF2HcWP81tVAUXFEPTtCtsa52gAHu9bb',
  quorum: 3,
  recipients: [
    '@vEJe4hdnbHJl549200IytOeA3THbnP0oM+JQtS1u+8o=.ed25519',
    '@NeB4q4Hy9IiMxs5L08oevEhivxW+/aDu/s/0SkNayi0=.ed25519',
    '@MpDd66GPXgN1+eMNrZInHkWq1THMurWwLdMx8BZ1ncw=.ed25519'
  ]
}

request('http://localhost:8187/v2/share', params, (err, response) => {
  // Returns a JSON response object
  console.log(response)
  // Looks something like...
  // {
  //   code: 200,
  //   body: {
  //     rootId,
  //     ritualId,
  //     name,
  //     label,
  //     quorum,
  //     shards: [...]
  //   }
  // }
})
samparsky commented 5 years ago

@KGibb8 this quite interesting, I will start work on this