Skip to content

Commit

Permalink
Merge pull request #3 from ayanworks/refactor/did-resolver
Browse files Browse the repository at this point in the history
refactor: update dependencies
  • Loading branch information
sairanjit authored Feb 19, 2024
2 parents 0825885 + 2a0836f commit 152b289
Show file tree
Hide file tree
Showing 8 changed files with 1,211 additions and 88 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
node_modules/
package-lock.json
dist
build/
29 changes: 8 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,22 @@ Driver exposing resolution functionality for the did:polygon method through an i

The latest published version of this Dockerized service is used by the deployed dev instance of the aforementioned Universal Resolver service.


## Example DID

```
did:polygon:0x88f8ce435611f27bc89525b47fc147632bbdadac
```sh
did:polygon:testnet:0x50e775B5c3050e8B2Cfa404C3dE95ab97E43e771
```

## Build and Run (Docker)

Command to create docker image:

```
docker build -f Dockerfile . -t ayanworks/driver-did-polygon:1.0
```

Command to run docker container with using this image:

```
docker run -p 8080:8080 ayanworks/driver-did-polygon:1.0
```

Request to resolve DID

```
curl -X GET http://localhost:8080/1.0/identifiers/did:polygon:0x88f8ce435611f27bc89525b47fc147632bbdadac
```sh
docker build -f ./docker/Dockerfile . -t ayanworks/driver-did-polygon
docker run -p 8080:8080 ayanworks/driver-did-polygon
curl -X GET http://localhost:8080/1.0/identifiers/did:polygon:testnet:0x50e775B5c3050e8B2Cfa404C3dE95ab97E43e771
```

## Build and Run (NodeJS)

```sh
yarn dev
```
npm start
```
8 changes: 5 additions & 3 deletions Dockerfile → docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
FROM node:12.16.1
FROM node:18-alpine

# Create Directory for the Container
WORKDIR /usr/src/app

# Only copy the package.json and yarn.lock to work directory
COPY package.json .
COPY yarn.lock .

# Install all Packages
RUN yarn install
Expand All @@ -13,5 +14,6 @@ RUN yarn install
ADD . /usr/src/app
RUN yarn build

CMD [ "yarn", "server" ]
EXPOSE 8080
EXPOSE 8080

CMD [ "yarn", "start" ]
23 changes: 0 additions & 23 deletions index.ts

This file was deleted.

53 changes: 26 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
{
"name": "polygon-did-driver",
"version": "1.0.0",
"main": "js/index.js",
"license": "MIT",
"private": false,
"files": [
"js"
],
"scripts": {
"start": "ts-node index.ts",
"build": "tsc",
"clean": "rm -rf js node_modules",
"server": "yarn build && node js/index.js",
"test": "echo 'No tests yet'"
},
"dependencies": {
"did-resolver": "^1.1.0",
"express": "^4.16.4",
"@ayanworks/polygon-did-resolver": "0.0.3"
},
"devDependencies": {
"@types/express": "^4.17.2",
"ts-node": "^8.5.4",
"typescript": "^3.7.3",
"ethers": "^5.1.0",
"dotenv": "^8.0.0"
}
"name": "polygon-did-driver",
"version": "1.0.0",
"main": "build/index",
"license": "MIT",
"private": false,
"files": [
"build"
],
"scripts": {
"start": "node ./build/index.js",
"compile": "tsc",
"build": "yarn run clean && yarn run compile",
"clean": "rm -rf ./build",
"dev": "ts-node src/index.ts",
"test": "echo 'No tests yet'"
},
"dependencies": {
"@ayanworks/polygon-did-resolver": "0.0.16-alpha.8",
"did-resolver": "^4.1.0",
"express": "^4.18.2"
},
"devDependencies": {
"@types/express": "^4.17.21",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
}
}
36 changes: 36 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import express from "express"
import { getResolver } from "@ayanworks/polygon-did-resolver"
import { Resolver, ResolverRegistry } from "did-resolver"

const PORT = 8080
const app = express()

app.use(express.json())

app.use((err, req, res, next) => {
res.status(err.status || 500).json({
message: err.message,
errors: err.errors,
})
})

app.get("/1.0/identifiers/:did", async (req, res) => {
try {
const did = req.params.did
const resolver = new Resolver(getResolver() as ResolverRegistry)

const didDocument = await resolver.resolve(did)

res.send(JSON.stringify(didDocument, null, 2))
} catch (error) {
res.sendStatus(404)
}
})

app.listen(PORT, () => {
console.log(
"Your server is listening on port %d (http://localhost:%d)",
PORT,
PORT
)
})
26 changes: 14 additions & 12 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"extends:": "../../tsconfig.json",
"compilerOptions": {
"outDir": "js",
"esModuleInterop": true,
"lib": [
"es2015"
]
},
"exclude": [
"js"
]
}
"compilerOptions": {
"module": "commonjs",
"target": "ES2017",
"outDir": "./build",
"lib": [],
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},
"include": ["src/**/*"],
"exclude": ["build"]
}
Loading

0 comments on commit 152b289

Please sign in to comment.