Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(uniregistrar): ✨ docker image #57

Merged
merged 23 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5d67679
feat(uniregistrar): ✨ add constracts to create from uniregistrar
matteo-cristino Nov 16, 2023
a23257b
feat(uniregistrar): ✨ customize restroom to handle different contract…
matteo-cristino Nov 16, 2023
249638f
feat(uniregistrar): ✨ add Dockerfile WIP
matteo-cristino Nov 16, 2023
fcd7d2c
fix(uniregistrar): 🐛 use redis instead of fs
matteo-cristino Nov 16, 2023
7d3ac2d
fix: 🐛 reduce docker image dimension
matteo-cristino Nov 16, 2023
1173693
fix(uniregistrar): 🐛 update sandbox.uniregistrar admin url
matteo-cristino Nov 16, 2023
0991b71
fix(uniregistrar): 🐛 path to created did in zencode contract
matteo-cristino Nov 16, 2023
e324ba0
ci: 👷 publish uniregistrar docker image
matteo-cristino Nov 16, 2023
fb6bfca
test(uniregistrar): 🚨 add small bash test for uniregistrar flow
matteo-cristino Nov 16, 2023
5831b08
docs(uniregistrar): 📖 add README.md
matteo-cristino Nov 16, 2023
ffb9972
fix(uniregistrar): 🐛 remove debug leftover
matteo-cristino Nov 17, 2023
b6ab089
fix(uniregistrar): 🐛 specify operation to eprform in the post to the …
matteo-cristino Nov 20, 2023
db29d3a
feat(uniregistrar): ✨ add update api
matteo-cristino Nov 20, 2023
8e8a15d
test(uniregistrar): 🚨 add update to bash test
matteo-cristino Nov 20, 2023
76c40fa
fix(uniregistrar): 🐛 avoid multiple identical keys file
matteo-cristino Nov 21, 2023
fb1440b
feat(uniregistrar): ✨ deactivate api
matteo-cristino Nov 21, 2023
ca7a48f
test(uniregistrar): 🚨 add deactivate to bash test
matteo-cristino Nov 21, 2023
5049196
fix(uniregistrar): 🐛 add some checks before api call
matteo-cristino Nov 21, 2023
4edb867
fix(uniregistrar): 🐛 add more checks to input data to APIs in js
matteo-cristino Nov 21, 2023
b645fb6
fix(uniregistrar): 🐛 APIs return the correct status code
matteo-cristino Nov 21, 2023
da93060
fix: 🐛 remove unused file
matteo-cristino Nov 21, 2023
1b123e8
ci: 👷 publish uniregistrar docker image on dockerhub
matteo-cristino Nov 30, 2023
341c290
ci: 👷 various fixes to docker publish uniregistrar
matteo-cristino Nov 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/workflows/docker-publish-uniregistrar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Publish Docker image

on:
push:
branches: ['main']

jobs:
file-changes:
name: "🗃️ Check file changes"
runs-on: ubuntu-latest
outputs:
registrar: ${{ steps.filter.outputs.registrar }}
steps:
- name: 🛎️ Checkout
uses: actions/checkout@v4
- name: 📂 paths filter
uses: dorny/paths-filter@v2
id: filter
with:
filters: |
registrar:
- 'universal-registrar/**'

set-version:
name: "📌 Set version"
runs-on: ubuntu-latest
needs: [file-changes]
if: "needs.file-changes.outputs.registrar == 'true'"
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: ⬇ install dependecy
run: sudo apt-get install -y skopeo jq
- name: 📡 get docker version
id: version
run: |
(skopeo inspect docker://docker.io/dyne/did-registrar:0.1 2>/dev/null || echo '{"RepoTags": ["0.0"]}') \
| jq -r '.RepoTags | .[]' \
| sort -Vr \
| head -n 1 \
| awk 'BEGIN{FS=OFS="."} {$2+=1} { printf("version=%s.%s\n",$1, $2) }' >> $GITHUB_OUTPUT

push_to_registry:
name: 🐋 Push Docker image to Docker Hub
runs-on: ubuntu-latest
needs: [set-version]
steps:
- name: 🛎️ Checkout
uses: actions/checkout@v4
- name: 🔐 Log in to Docker Hub
uses: docker/login-action@v3
with:
username: dyne
password: ${{ secrets.DOCKERHUB_PASS }}
- name: ⛏️ Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
dyne/did-registrar
labels: |
org.opencontainers.image.vendor=Dyne.org
- name: 🏗️ Build and push Docker image
uses: docker/build-push-action@v5
with:
context: universal-registrar
push: true
tags: ${{ needs.set-version.outputs.version }}
labels: ${{ steps.meta.outputs.labels }}
10 changes: 10 additions & 0 deletions universal-registrar/.env.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
USE_HTTP=y
USE_TIMESTAMP=y
USE_REDIS=y
CHAIN_EXT=chain
YML_EXT=yml
OPENAPI=true
HTTP_PORT=3000
HTTPS_PORT=443
ZENCODE_DIR=/var/contracts
FILES_DIR=/var/files
10 changes: 10 additions & 0 deletions universal-registrar/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
USE_HTTP=y
USE_TIMESTAMP=y
USE_REDIS=y
CHAIN_EXT=chain
YML_EXT=yml
OPENAPI=true
HTTP_PORT=3000
HTTPS_PORT=443
ZENCODE_DIR=contracts
FILES_DIR=files
27 changes: 27 additions & 0 deletions universal-registrar/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
ARG NODE_VERSION=18
FROM node:$NODE_VERSION-alpine

WORKDIR /app

# Add dependencies
RUN apk add redis --no-cache

# contracts folders
RUN mkdir -p /var/contracts

# copy contracts and env
COPY contracts/* /var/contracts/
COPY restroom.mjs .
COPY package.json .
COPY yarn.lock .
COPY .env.docker .env

# expose port
EXPOSE 3000

# copy start script
COPY start.sh .
RUN chmod +x start.sh

# yarn start
ENTRYPOINT ["sh", "/app/start.sh"]
34 changes: 34 additions & 0 deletions universal-registrar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Universal Registrar Driver: did:dyne

This is a [Universal Registrar](https://github.com/decentralized-identity/universal-registrar/) driver for **did:dyne** identifiers.

## Specifications

* [Decentralized Identifiers](https://w3c.github.io/did-core/)
* [DID Registration](https://identity.foundation/did-registration/)
* [dyne](https://dyne.org/W3C-DID/)

## Build and Run (Docker)

```
docker build -t universalregistrar/driver-did-dyne .
docker run -p 3000:3000 universalregistrar/driver-did-dyne
```

## Driver Environment Variables

```
(none)
```

## Driver Input Options

```
(none)
```

## Driver Output Metadata

```
(none)
```
118 changes: 118 additions & 0 deletions universal-registrar/contracts/create-1-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
zenchain: 1.0
start: create-11-check-prefix.zen
blocks:
create-11-check-prefix.zen:
zenContent: |
Scenario 'w3c': did document

# data
Given I have a 'string dictionary' named 'didDocument'

# keys
Given I have a 'string' named 'get'

# check id
When I pickup from path 'didDocument.id'
and I verify 'id' has prefix 'did:dyne:sandbox.uniregistrar:'

# prepare get for did
When I append 'id' to 'get'

Then print the 'get'
and print the 'didDocument'
keysFile: did-get.keys
next: create-12-check-exist.zen
create-12-check-exist.zen:
zenContent: |
Rule unknown ignore

# restroom statement
Given I have a endpoint named 'get'
and I connect to 'get' and save the output into 'get_result'
and I fetch the local timestamp and store it into 'timestamp'

# restroom data
Given I have a 'string dictionary' named 'get_result'
and I have a 'string' named 'timestamp'

# data
Given I have a 'string dictionary' named 'didDocument'

# check it does not exists
When I pickup from path 'get_result.status'
and I write number '200' in '200'
and I verify 'status' is not equal to '200'

Then print the 'didDocument'
and print the 'timestamp'
next: create-13-action.zen
create-13-action.zen:
zenContent: |
Rule unknown ignore

Scenario 'w3c': did doc

# Restroom statement
Given I have a redis connection on 'redis://localhost:6379'

# data
Given I have a 'string dictionary' named 'didDocument'
and I have a 'string' named 'timestamp'

# keys
Given I have a 'string dictionary' named 'didState'

When I create the 'eddsa' public key from did document 'didDocument'
and I pickup from path 'didDocument.id'

# jobId
When I copy 'id' to 'jobId'

# kid
When I write string '' in 'kid'
and I append 'id' to 'kid'
and I append the string '#eddsa_public_key' to 'kid'

# alg
When I write string 'EdDSA' in 'alg'

# serializedPayload
When I create the 'string dictionary' named 'to_be_hashed'
and I copy 'didDocument' in 'to_be_hashed'
and I copy 'timestamp' in 'to_be_hashed'
and I create the json escaped string of 'to_be_hashed'
and I create the hash of 'json_escaped_string'
and I write string '' in 'serializedPayload'
and I append 'base64' of 'hash' to 'serializedPayload'

# signingRequest
When I create the 'string dictionary' named 'signingRequest'
and I create the 'string dictionary' named 'signingRequest1'
and I move 'kid' in 'signingRequest1'
and I move 'alg' in 'signingRequest1'
and I move 'serializedPayload' in 'signingRequest1'
and I move 'signingRequest1' in 'signingRequest'

# did State
When I move 'signingRequest' in 'didState'

# to be stored
When I create the 'string dictionary' named 'stored'
and I copy 'didState' in 'stored'
and I copy 'didDocument' in 'stored'

Then print the 'didState'
and print the 'stored'
and print the 'jobId' as 'hex'

# Restroom on success
Then I write 'stored' into redis under the key named by 'jobId'
keysFile: did-state.keys
next: create-14-print.zen
create-14-print.zen:
zenContent: |
Given I have a 'string dictionary' named 'didState'
and I have a 'string' named 'jobId'

Then print the 'didState'
and print the 'jobId'
97 changes: 97 additions & 0 deletions universal-registrar/contracts/create-2-sign.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
zenchain: 1.0
start: create-21-check-sign.zen
blocks:
create-21-check-sign.zen:
zenContent: |
Rule unknown ignore
Scenario 'w3c': did
Scenario 'eddsa': verify sign

# Restroom statement
Given I have a redis connection on 'redis://localhost:6379'
Given I read from redis the data under the key named 'jobId' and save the output into 'redis_data'

# restroom data
Given I have a 'base64' in path 'redis_data.didState.signingRequest.signingRequest1.serializedPayload'
and I have a 'string dictionary' in path 'redis_data.didDocument'

# data
Given I have a 'base64' in path 'secret.signingResponse.signingRequest1.signature'
and I have a 'string' named 'jobId'

#verify signature
When I create the 'eddsa' public key from did document 'didDocument'
and I verify the 'serializedPayload' has a eddsa signature in 'signature' by 'eddsa_public_key'

# prepare post for oracle
When I create the 'string dictionary' named 'post'
and I create the 'string dictionary' named 'data'
and I copy 'didDocument' in 'data'
and I write string 'create' in 'operation'
and I move 'operation' in 'data'
and I move 'data' in 'post'

# prepare output
When I create the 'string dictionary' named 'didState'
# didState.did
When I pickup from path 'didDocument.id'
and I move 'id' to 'did' in 'didState'

Then print the 'didState'
and print the 'post'
and print the 'jobId'

# restroom on success
Then I remove the key 'jobId' in redis
next: create-22-post.zen
create-22-post.zen:
zenContent: |
Rule unknown ignore

# Restroom statement
Given I connect to 'oracle_url' and pass it the content of 'post' and save the output into 'oracle_output'

# Restroom data
Given I have a 'string dictionary' named 'oracle_output'

# data
Given I have a 'string dictionary' named 'didState'

When I pickup from path 'oracle_output.status'
and I set '200' to '200' as 'float'
and I set '500' to '500' as 'float'

If I verify 'status' is equal to '200'
When I remove 'status'
and I pickup from path 'oracle_output.result.did_result.status'
EndIf

# If created print didState
If I verify 'status' is equal to '200'
# didState.state
When I write string 'finished' in 'state'
and I move 'state' in 'didState'
# didState.didDocument
When I pickup from path 'oracle_output.result.did_result.result.result.didDocument'
and I move 'didDocument' in 'didState'
EndIf

# If not create print error
If I verify 'status' is equal to '500'
# didState.state
When I write string 'failed' in 'state'
and I move 'state' in 'didState'
# didState.reason
When I write string 'something went wrong see didRegistrationMetadata for a complete error log' in 'reason'
and I move 'reason' in 'didState'

# didRegistrationMetadata
When I create the 'string dictionary' named 'didRegistrationMetadata'
and I pickup from path 'oracle_output.result'
and I move 'result' to 'error_log' in 'didRegistrationMetadata'

Then print the 'didRegistrationMetadata'
EndIf

Then print the 'didState'
keysFile: oracle-post.keys
Loading