Skip to content

Commit

Permalink
updates to bitstring status list and renames env vars for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
kezike committed May 8, 2024
1 parent 3a69c4b commit 63aaefc
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ TENANT_SEED_RANDOMTESTING=generate
TENANT_SEED_DEFAULT=generate

# see the README for an explanation of logging
LOG_ALL_FILE=logs/all.log
ALL_LOG_FILE=logs/all.log
ERROR_LOG_FILE=logs/error.log
CONSOLE_LOG_LEVEL=silly # default is silly, i.e. log everything - see the README for allowed levels
LOG_LEVEL=silly # default is silly
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,18 @@ There is a sample .env file provided called .env.example to help you get started
| `PORT` | http port on which to run the express app | 4006 | no |
| `ENABLE_HTTPS_FOR_DEV` | runs the dev server over https - ONLY FOR DEV - typically to allow CORS calls from a browser | false | no |
| `TENANT_SEED_{TENANT_NAME}` | see [tenants](#tenants) section for instructions | no | no |
|`TENANT_DIDMETHOD_{TENANT_NAME}` | did method (`key` or `web`) to use for signing on this tenant | `key` | no |
|`TENANT_DID_METHOD_{TENANT_NAME}` | did method (`key` or `web`) to use for signing on this tenant | `key` | no |
| `TENANT_DID_URL_{TENANT_NAME}` | url to use for did:web | | no |
| `ERROR_LOG_FILE` | log file for all errors - see [Logging](#logging) | no | no |
| `LOG_ALL_FILE` | log file for everything - see [Logging](#logging) | no | no |
| `ALL_LOG_FILE` | log file for everything - see [Logging](#logging) | no | no |
| `CONSOLE_LOG_LEVEL` | console log level - see [Logging](#logging) | silly | no |
| `LOG_LEVEL` | log level for application - see [Logging](#logging) | silly | no |

### Tenants

You might want to allow more than one signing key ([DID](https://www.w3.org/TR/did-core/)) to be used with the issuer. For example, you might want to sign university/college degree diplomas with a key ([DID](https://www.w3.org/TR/did-core/)) that is only used by the registrar, but then also allow certificates for individual courses to be signed by by different keys ([DIDs](https://www.w3.org/TR/did-core/)) that are owned by the faculty or department that teaches the course.

We're calling these differents signing authorities 'tenants' (or 'instances'). You can set up as many tenants as you like by including a `TENANT_SEED_{TENANT_NAME}={seed}` environment variable for every 'tenant'. (NOTE: if you are using a did:web key, you must additinally specify `TENANT_DIDMETHOD_{TENANT_NAME}=web` and `TENANT_DID_URL_{TENANT_NAME}={the url for your did:web}`) for each did:web tenant. Read more in the [did:web generator section](#didweb-generator).
We're calling these differents signing authorities 'tenants' (or 'instances'). You can set up as many tenants as you like by including a `TENANT_SEED_{TENANT_NAME}={seed}` environment variable for every 'tenant'. (NOTE: if you are using a did:web key, you must additinally specify `TENANT_DID_METHOD_{TENANT_NAME}=web` and `TENANT_DID_URL_{TENANT_NAME}={the url for your did:web}`) for each did:web tenant. Read more in the [did:web generator section](#didweb-generator).

NOTE: the `seed` is explained below in the [Signing key section](#signing-key).

Expand Down Expand Up @@ -307,7 +307,7 @@ and save that in a file called did.json at the url where you'll host the documen

```https://raw.githubusercontent.com/jchartrand/didWebTest/main/.well-known/did.json```

You must also set `TENANT_DIDMETHOD_{TENANT_NAME}=web` and set `TENANT_DID_URL_{TENANT_NAME}` to the url where your `.well-known/did.json` did-document is hosted, which for this example would be:
You must also set `TENANT_DID_METHOD_{TENANT_NAME}=web` and set `TENANT_DID_URL_{TENANT_NAME}` to the url where your `.well-known/did.json` did-document is hosted, which for this example would be:

```https://raw.githubusercontent.com/jchartrand/didWebTest/main```

Expand All @@ -329,7 +329,7 @@ The issuer is by default set up to use the did:key implemenation of a [DID](http

The did:web implementation is preferable for production becuase it allows you to rotate (change) your signing keys whithout having to update every document that points at the old keys.

To use it set `TENANT_DIDMETHOD_{TENANT_NAME}=web` and set `TENANT_DID_URL_{TENANT_NAME}` to the url where your `.well-known/did.json` did-document is hosted.
To use it set `TENANT_DID_METHOD_{TENANT_NAME}=web` and set `TENANT_DID_URL_{TENANT_NAME}` to the url where your `.well-known/did.json` did-document is hosted.

## Usage

Expand Down Expand Up @@ -544,7 +544,7 @@ There are also two log files that can be enabled:
Enable each log by setting an env variable for each, indicating the path to the appropriate file, like this example:

```
LOG_ALL_FILE=logs/all.log
ALL_LOG_FILE=logs/all.log
ERROR_LOG_FILE=logs/error.log
```

Expand Down
4 changes: 2 additions & 2 deletions src/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ describe('api', () => {
resetConfig()
process.env[`TENANT_SEED_${tenantName}`] =
'z1AeiPT496wWmo9BG2QYXeTusgFSZPNG3T9wNeTtjrQ3rCB'
process.env[`TENANT_DIDMETHOD_${tenantName}`] = 'web'
process.env[`TENANT_DID_METHOD_${tenantName}`] = 'web'
process.env[`TENANT_DID_URL_${tenantName}`] = 'https://example.com'
})

after(() => {
delete process.env[`TENANT_SEED_${tenantName}`]
delete process.env[`TENANT_DIDMETHOD_${tenantName}`]
delete process.env[`TENANT_DID_METHOD_${tenantName}`]
delete process.env[`TENANT_DID_URL_${tenantName}`]
})

Expand Down
6 changes: 3 additions & 3 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ async function parseTenantSeeds() {
DID_SEEDS[tenantName] = {
didSeed: await decodeSeed(value),
didMethod:
process.env[`TENANT_DIDMETHOD_${tenant}`] &&
process.env[`TENANT_DIDMETHOD_${tenant}`].toLowerCase() === 'web'
process.env[`TENANT_DID_METHOD_${tenant}`] &&
process.env[`TENANT_DID_METHOD_${tenant}`].toLowerCase() === 'web'
? 'web'
: 'key',
didUrl: process.env[`TENANT_DID_URL_${tenant}`]
Expand All @@ -56,7 +56,7 @@ function parseConfig() {
env.CONSOLE_LOG_LEVEL?.toLocaleLowerCase() || defaultConsoleLogLevel,
logLevel: env.LOG_LEVEL?.toLocaleLowerCase() || defaultLogLevel,
errorLogFile: env.ERROR_LOG_FILE,
logAllFile: env.LOG_ALL_FILE,
allLogFile: env.ALL_LOG_FILE,
port: env.PORT ? parseInt(env.PORT) : defaultPort
})
return config
Expand Down
6 changes: 3 additions & 3 deletions src/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Config', () => {
beforeEach(async () => {
resetConfig()
delete process.env[`TENANT_SEED_${tenantName}`]
delete process.env[`TENANT_DIDMETHOD_${tenantName}`]
delete process.env[`TENANT_DID_METHOD_${tenantName}`]
})

afterEach(async () => {})
Expand All @@ -27,15 +27,15 @@ describe('Config', () => {
it('uses DID:key when requested', async () => {
process.env[`TENANT_SEED_${tenantName}`] =
'z1AeiPT496wWmo9BG2QYXeTusgFSZPNG3T9wNeTtjrQ3rCB'
process.env[`TENANT_DIDMETHOD_${tenantName}`] = 'key'
process.env[`TENANT_DID_METHOD_${tenantName}`] = 'key'
const seed = await getTenantSeed('configtest')
expect(seed.didMethod).to.eql('key')
})

it('uses DID:web when requested', async () => {
process.env[`TENANT_SEED_${tenantName}`] =
'z1AeiPT496wWmo9BG2QYXeTusgFSZPNG3T9wNeTtjrQ3rCB'
process.env[`TENANT_DIDMETHOD_${tenantName}`] = 'web'
process.env[`TENANT_DID_METHOD_${tenantName}`] = 'web'
const seed = await getTenantSeed('configtest')
expect(seed.didMethod).to.eql('web')
})
Expand Down
2 changes: 1 addition & 1 deletion src/test-fixtures/.env.testing
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PORT=4007
ENABLE_HTTPS_FOR_DEV=false

LOG_ALL_FILE=logs/all.log
ALL_LOG_FILE=logs/all.log
ERROR_LOG_FILE=logs/error.log
CONSOLE_LOG_LEVEL=silly # default is silly, i.e. log everything - see the README for allowed levels
LOG_LEVEL=silly # default is silly
Expand Down
7 changes: 2 additions & 5 deletions src/test-fixtures/vc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const unsignedVC = {
'@context': [
'https://www.w3.org/2018/credentials/v1',
'https://purl.imsglobal.org/spec/ob/v3p0/context-3.0.2.json',
'https://w3id.org/vc/status-list/2021/v1',
'https://w3id.org/security/suites/ed25519-2020/v1'
],
id: 'urn:uuid:951b475e-b795-43bc-ba8f-a2d01efd2eb1',
Expand Down Expand Up @@ -45,7 +44,7 @@ const unsignedVC = {
// "credentialStatus":
const credentialStatus = {
id: 'https://digitalcredentials.github.io/credential-status-jc-test/XA5AAK1PV4#16',
type: 'StatusList2021Entry',
type: 'BitstringStatusListEntry',
statusPurpose: 'revocation',
statusListIndex: 16,
statusListCredential:
Expand All @@ -70,13 +69,11 @@ const getUnsignedVCWithStatus = () => {
}
const ed25519_2020suiteContext =
'https://w3id.org/security/suites/ed25519-2020/v1'
const statusListContext = 'https://w3id.org/vc/status-list/2021/v1'

export {
getUnsignedVC,
getUnsignedVCWithoutSuiteContext,
getCredentialStatus,
getUnsignedVCWithStatus,
ed25519_2020suiteContext,
statusListContext
ed25519_2020suiteContext
}
6 changes: 3 additions & 3 deletions src/utils/logger.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import winston from 'winston'
import { getConfig } from '../config.js'

const { errorLogFile, logAllFile, logLevel, consoleLogLevel } = getConfig()
const { errorLogFile, allLogFile, logLevel, consoleLogLevel } = getConfig()
/*
These are the default npm logging levels
that Winston uses, but we include them explicitly
Expand Down Expand Up @@ -59,10 +59,10 @@ if (errorLogFile) {
)
}

if (logAllFile) {
if (allLogFile) {
transports.push(
new winston.transports.File({
filename: logAllFile
filename: allLogFile
})
)
}
Expand Down

0 comments on commit 63aaefc

Please sign in to comment.