Skip to content

Commit

Permalink
Refactor registry client API.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrizagidulin committed Jan 3, 2024
1 parent 85265fb commit 949044e
Show file tree
Hide file tree
Showing 18 changed files with 243 additions and 170 deletions.
10 changes: 10 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ module.exports = {
extends: 'standard-with-typescript',
parserOptions: {
project: './tsconfig.json'
},
rules: {
'@typescript-eslint/strict-boolean-expressions': 'off'
}
},
{
files: ['test/**/*.spec.ts'],
extends: 'standard-with-typescript',
parserOptions: {
project: './tsconfig.spec.json'
}
}
]
Expand Down
36 changes: 18 additions & 18 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
timeout-minutes: 10
strategy:
matrix:
node-version: [16.x]
node-version: [18.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
Expand All @@ -20,27 +20,27 @@ jobs:
run: npm run test-node
env:
CI: true
test-karma:
runs-on: ubuntu-latest
# needs: [lint]
timeout-minutes: 10
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- name: Run karma tests
run: npm run test-karma
# test-karma:
# runs-on: ubuntu-latest
## needs: [lint]
# timeout-minutes: 10
# strategy:
# matrix:
# node-version: [16.x]
# steps:
# - uses: actions/checkout@v2
# - name: Use Node.js ${{ matrix.node-version }}
# uses: actions/setup-node@v1
# with:
# node-version: ${{ matrix.node-version }}
# - run: npm install
# - name: Run karma tests
# run: npm run test-karma
lint:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
node-version: [18.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# issuer-registry-client Changelog

## 2.0.0 -

### Changed
- **BREAKING**: Refactor the client to use a more streamlined API, `client.load(config)`
and `client.didEntry(did)`

## 1.0.0 - 2022-11-30

### Added

- Initial commit.
61 changes: 51 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@ spec is being incubated in the W3C CCG.

Assumes the loaded registries are public, accessible via `https`.

Note that an individual DID can appear in multiple registries.
Because of that, the _order_ of registries loaded matters. For example, given
a registry:

```js
const knownRegistries = [{
"name": "DCC Pilot Registry",
"url": "https://digitalcredentials.github.io/issuer-registry/registry.json"
},
{
"name": "DCC Sandbox Registry",
"url": "https://digitalcredentials.github.io/sandbox-registry/registry.json"
}]
```

If an issuer DID is contained in both of those registries, the issuer entry
(that contains the issuer name and URL) will come from the _first_ registry,
"DCC Pilot Registry".

In other words, verifiers and other implementers must order the registries
_in order of most authoritative to least_.

## Install

- Node.js 18+ is recommended.
Expand Down Expand Up @@ -76,21 +98,40 @@ const knownRegistries = [
]
```

You can now fetch them and query them
You can now:

```js
import { loadRegistries } from '@digitalcredentials/issuer-registry-client'
import { RegistryClient } from '@digitalcredentials/issuer-registry-client'

// Load the registries from the web (typically done at app startup).
const registries = loadRegistries(knownRegistries)
const registries = new RegistryClient()

registries.contains('did:example:123')
// { result: false }
// Load the registries from the web (typically done at app startup).
await registries.load({ config: knownRegistries })

// You can now query to see if a DID is known in any registry
console.log(registries.didEntry('did:key:z6MkpLDL3RoAoMRTwTgo3rs39ZwssfaPKtGdZw7AGRN7CK4W'))
/**
DidMapRegistryEntry {
name: 'My University',
url: 'https://digitalcredentials.mit.edu',
location: 'Cambridge, MA, USA',
inRegistries: Set(2) {
{
name: 'DCC Community Registry',
url: 'https://digitalcredentials.github.io/community-registry/registry.json',
rawContents: [Object]
},
{
name: 'DCC Sandbox Registry',
url: 'https://digitalcredentials.github.io/sandbox-registry/registry.json',
rawContents: [Object]
}
}
}
*/

// or
registries.contains('did:example:456')
// This DID is contained in one registry, DCC Registry
// { result: true, names: ['DCC Registry'] }
registries.didEntry('did:example:does-not-exist')
// undefined
```

## Contribute
Expand Down
1 change: 0 additions & 1 deletion declarations.d.ts

This file was deleted.

1 change: 1 addition & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = function (config) {
],

karmaTypescriptConfig: {
tsconfig: './tsconfig.spec.json',
reports: {} // Disables the code coverage report
},

Expand Down
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
"scripts": {
"build": "npm run clear && tsc -d && tsc -p tsconfig.esm.json",
"clear": "rimraf dist/*",
"lint": "ts-standard --fix",
"lint": "ts-standard --fix --project tsconfig.spec.json",
"prepare": "npm run build",
"rebuild": "npm run clear && npm run build",
"test": "npm run lint && npm run test-node && npm run test-karma",
"test": "npm run lint && npm run test-node",
"test-karma": "karma start karma.conf.js",
"test-node": "cross-env NODE_ENV=test TS_NODE_PROJECT=tsconfig.spec.json TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha -r ts-node/register --project tsconfig.spec.json 'test/*.ts'"
},
"files": [
"dist",
"CHANGELOG.md",
"README.md",
"LICENSE.md"
],
Expand Down Expand Up @@ -43,7 +44,10 @@
"rimraf": "^5.0.1",
"ts-node": "^10.9.1",
"ts-standard": "^12.0.2",
"typescript": "^5.1.6"
"typescript": "5.2.2"
},
"resolutions": {
"@typescript-eslint/typescript-estree": "^6.1.6"
},
"publishConfig": {
"access": "public"
Expand Down
30 changes: 0 additions & 30 deletions src/Registry.ts

This file was deleted.

39 changes: 0 additions & 39 deletions src/RegistryCollection.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/declarations.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module '@digitalcredentials/http-client'
Loading

0 comments on commit 949044e

Please sign in to comment.