-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d09a326
commit 0102582
Showing
9 changed files
with
2,201 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# DAF REST API example | ||
|
||
## Install | ||
|
||
``` | ||
npm i | ||
npm start | ||
``` | ||
|
||
## Sample queries | ||
|
||
### List identity providers | ||
|
||
``` | ||
curl --location --request GET 'http://localhost:8080/providers' | ||
``` | ||
|
||
### Create identity | ||
|
||
``` | ||
curl --location --request POST 'http://localhost:8080/create-identity' \ | ||
--header 'Content-Type: application/json' \ | ||
--data-raw '{ | ||
"type": "rinkeby-ethr-did-fs" | ||
}' | ||
``` | ||
|
||
### List identities | ||
|
||
``` | ||
curl --location --request GET 'http://localhost:8080/identities' | ||
``` | ||
|
||
### Sing VC | ||
|
||
``` | ||
curl --location --request POST 'http://localhost:8080/handle-action' \ | ||
--header 'Content-Type: application/json' \ | ||
--data-raw '{ | ||
"type": "action.sign.w3c.vc", | ||
"did": "did:ethr:rinkeby:0x7dd28328c8b05a852839284c304b4bd4b628e357", | ||
"data": { | ||
"sub": "did:web:uport.me", | ||
"vc": { | ||
"@context": ["https://www.w3.org/2018/credentials/v1"], | ||
"type": ["VerifiableCredential"], | ||
"credentialSubject": { | ||
"you": "Rock" | ||
} | ||
} | ||
} | ||
}' | ||
``` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import express from 'express' | ||
const app = express() | ||
const port = process.env.PORT || 8080 | ||
|
||
import { core } from './setup' | ||
|
||
app.use(express.json()) | ||
|
||
app.get('/identities', async (req, res) => { | ||
const identities = await core.identityManager.getIdentities() | ||
res.json(identities.map(identity => identity.did)) | ||
}) | ||
|
||
app.get('/providers', async (req, res) => { | ||
const providers = await core.identityManager.getIdentityProviderTypes() | ||
res.json(providers) | ||
}) | ||
|
||
app.post('/create-identity', async (req, res) => { | ||
const identity = await core.identityManager.createIdentity(req.body.type) | ||
res.json({ did: identity.did }) | ||
}) | ||
|
||
app.post('/handle-action', async (req, res) => { | ||
const result = await core.handleAction(req.body) | ||
res.json({ result }) | ||
}) | ||
|
||
app.listen(port, () => console.log(`Server running at http://localhost:${port}`)) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"watch": ["./"], | ||
"ext": "ts", | ||
"ignore": ["**/*.spec.ts"], | ||
"exec": "ts-node ./index.ts" | ||
} |
Oops, something went wrong.