@windingtree/org.id-resolver 2.4.2 → 3.0.0-beta.7

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -1,237 +1,29 @@
1
1
  [![Build Status](https://travis-ci.org/windingtree/org.id-resolver.svg?branch=master)](https://travis-ci.org/windingtree/org.id-resolver)
2
- [![Coverage Status](https://coveralls.io/repos/github/windingtree/org.id-resolver/badge.svg?branch=master)](https://coveralls.io/github/windingtree/org.id-resolver?branch=master&v=2.0)
3
2
 
4
- <a href="https://orgid.tech"><img src="https://github.com/windingtree/branding/raw/master/org.id/svg/org.id-logo.svg" height="50" alt="ORG.ID"></a>
3
+ # ORGiD DID Resolver
5
4
 
6
- ## ORG.ID DID Resolver
5
+ A utility for ORGiD DID resolution according to [Decentralized Identifier Resolution](https://w3c-ccg.github.io/did-resolution/) specification.
7
6
 
8
- ORG.ID DID Resolver is an application for resolving ORG.ID data in [W3C DID](https://w3c.github.io/did-core/) format.
7
+ ## Documentation
9
8
 
10
- ## Usage
9
+ - [ORGiD DID resolver documentation](docs/index.md)
10
+ - [ORGiD SDK documentation](https://windingtree.github.io/org.id-sdk/)
11
11
 
12
- ### Command Line
12
+ ## Setup
13
13
 
14
- ```sh
15
- git clone git@github.com:windingtree/org.id-resolver.git
16
- cd org.id-resolver
17
- npm i
18
- npm link
19
- chmod +x src/cli.js
20
- ```
21
-
22
- ```sh
23
- ./src/cli.js endpoint=<WEB3_PROVIDER> orgid=<ORGID_ADDRESS> did=did:orgid:0x6d98103810d50b3711ea81c187a48245109ba094644ddbc54f8d0c4c
24
- ```
25
-
26
- ### NPM Module
27
-
28
- ```sh
29
- npm i @windingtree/org.id-resolver
30
- ```
31
-
32
- ```javascript
33
- const Web3 = require('web3');
34
- const {
35
- OrgIdResolver,
36
- httpFetchMethod,
37
- linkedInFetchMethod,
38
- twitterFetchMethod,
39
- whoisService
40
- } = require('@windingtree/org.id-resolver');
41
-
42
- const web3 = new Web3('<WEB3_PROVIDER>'); // HTTP(s) or WS(s)
43
- const resolver = new OrgIdResolver({
44
- web3,
45
- orgId: '<ORGID_ADDRESS>', // TODO: #3
46
- authorizedTrustProofsIssuers: [
47
- 'did:orgid:0x52f750...' // These DIDs will be allowed to be used as issuers and verifiers for the Trust proofs issuing in form of Verifiable Credentials
48
- ]
49
- });
50
- resolver.registerSocialFetchMethod(linkedInFetchMethod, {
51
- key: '<LINKEDIN_API_KEY>'
52
- });
53
- resolver.registerSocialFetchMethod(twitterFetchMethod, {
54
- key: '<TWITTER_API_KEY>'
55
- });
56
- resolver.registerFetchMethod(httpFetchMethod);
57
- resolver.registerService(whoisService);
58
-
59
- const result = await resolver.resolve('did:orgid:0x62a7502f4c44d8147b8f7b2a1dbeb8503e8446e77355bb2e4ebf999c7ecc5808');
60
- ```
61
-
62
- ## Algorithm
63
-
64
- 1. Validate DID syntax (must be `did:orgid:bytes32`)
65
- 2. Read organization data from ORG.ID Registry
66
- 3. Fetch and validate [ORG.JSON](https://github.com/windingtree/org.json-schema):
67
- 4. Try to resolve assertions and credentials
68
-
69
- The response of the resolver contains the following information
70
-
71
- ```json
72
- {
73
- // An object that has been resolved from the given DID.
74
- // Can be equal to `null` if JSON file not passed hashes equality check
75
- // or if the file is not passed validation against the ORG.ID schema
76
- "didDocument": {...},
77
-
78
- // Organization identifier
79
- "id": "<organization_id>",
80
-
81
- "organization": {
82
- "orgId": "<organization_id>",
83
- "orgJsonHash": "<organization_json_hash>",
84
- "orgJsonUri": "<organization_json_uri>",
85
- "orgJsonUriBackup1": "<organization_json_uri>",
86
- "orgJsonUriBackup2": "<organization_json_uri>",
87
- "parentOrgId": "<parent_organization_hash_or_zero_hash>",
88
- "owner": "<owner_eth_address>",
89
- "director": "<director_eth_address>",
90
- "isActive": true,// true for `enabled` and false for `disabled`
91
- "isDirectorshipAccepted": true,// director confirmation status
92
- },
93
-
94
- // List of validation results
95
- "checks": [
96
- {
97
- "type": "DID_SYNTAX",
98
- "passed": true,
99
- "errors": [],
100
- "warnings": []
101
- },
102
- {
103
- "type": "ORGID",
104
- "passed": true,
105
- "errors": [],
106
- "warnings": []
107
- },
108
- {
109
- "type": "DID_DOCUMENT",
110
- "passed": true,
111
- "errors": [],
112
- "warnings": []
113
- },
114
- {
115
- "type": "TRUST_ASSERTIONS",
116
- "passed": true
117
- }
118
- ],
119
-
120
- // Verified trust section of the `didDocument`
121
- "trust": {
122
- "assertions": [
123
- {
124
- "type": "dns",
125
- "claim": "test.com",
126
- "proof": "TXT",
127
- "verified": true
128
- },
129
- {
130
- "type": "domain",
131
- "claim": "test2.com",
132
- "proof": "http://test2.com/orgid.txt",
133
- "verified": true,
134
- "whois": {
135
- "domainName": "TEST2.COM",
136
- "registryDomainId": "1234567_DOMAIN_COM-VRSN",
137
- "registrarWhoisServer": "whois.server.net",
138
- "registrarUrl": "http://www.whois.net",
139
- "updatedDate": "2021-03-22T05:01:08Z",
140
- "creationDate": "2011-05-09T18:58:13Z",
141
- "expiryDate": "2024-05-09T18:58:13Z",
142
- "registrar": "Cool Domain",
143
- "registrarIanaId": "345",
144
- "registrarAbuseContactEmail": "abuse@support.server.net",
145
- "registrarAbuseContactPhone": "+33.1234567",
146
- "domainStatus": "clientTransferProhibited",
147
- "nameServer": "NS.SERVER.COM",
148
- "DNSSEC": "unsigned"
149
- }
150
- },
151
- {
152
- "type": "domain",
153
- "claim": "test3.com",
154
- "proof": "http://test3.com/orgid.txt",
155
- "verified": false // Not verified
156
- },
157
- {
158
- "type": "social",
159
- "claim": "twitter.com/jack",
160
- "proof": "https://twitter.com/jack/status/123456789/",
161
- "verified": true
162
- }
163
- ]
164
- },
165
-
166
- // Resolver meta-data like version, date of result and process duration
167
- "resolverMetadata": {
168
- "version": "2.0.0",
169
- "retrieved": "2020-02-21T18:14:13.278Z",
170
- "duration": 979,
171
- "orgIdAddress": "0x2cb8dCf26830B969555E04C2EDe3fc1D1BaD504E"
172
- }
173
- }
174
- ```
175
-
176
- ## Fetching methods
177
-
178
- At least one fetching method is required to the proper working of the resolver.
179
- This library provides a simple fetching method of a file that available via http/https - `httpFetchMethod`.
180
-
181
- To use this method you can get its configuration from the package this way:
182
-
183
- ```javascript
184
- const { OrgIdResolver, httpFetchMethod } = require('@windingtree/org.id-resolver');
185
- const resolver = new OrgIdResolver({...});
186
- resolver.registerFetchMethod(httpFetchMethod);// fetching method should be registered
187
- ```
188
-
189
- Future versions of `DID resolver` library will support more fetching methods like:
190
- IPFS, Swarm and Arweave
191
-
192
- Creation of custom fetching methods is quite simple task. Look at the example of simple fetching method configuration:
193
-
194
- ```javascript
195
- module.exports = {
196
- name: 'unique_method_name',
197
-
198
- // Regexp to match your URI schema
199
- pattern: '^yourpatternrule:',
200
-
201
- fetch: async uri => {
202
- const data = await yourCustomHandler(uri);
203
- return data;
204
- }
205
- };
206
- ```
207
-
208
- ## Development
209
-
210
- ### Test
211
-
212
- ```sh
213
- npm run test
214
- npm run test ./<path_to_test_file>.js
14
+ ```bash
15
+ yarn install
215
16
  ```
216
17
 
217
- ## Test coverage
18
+ ## Build
218
19
 
219
20
  ```bash
220
- npm run coverage
21
+ yarn build
221
22
  ```
222
23
 
223
- ## Lint
24
+ ## Linting & Testing
224
25
 
225
26
  ```bash
226
- npm run lint
227
-
27
+ yarn lint
28
+ yarn test
228
29
  ```
229
-
230
- ## ORG.ID Ecosystem
231
-
232
- - [Winding Tree DAO](https://github.com/windingtree/dao) controls ORG.ID Registry smart contract and some Directories (including their rules)
233
- - [ORG.ID Registry](https://github.com/windingtree/org.id) contains records of all organizations and organizational units
234
- - [ORG.JSON Schema](https://github.com/windingtree/org.json-schema) is a data format for describing organizations
235
- - **ORG.ID Resolver (you are here)**
236
- - [ORG.ID Directories](https://github.com/windingtree/org.id-directories) are curated lists of organizations
237
- - [Arbor](https://arbor.fm) can be used to look up an ORG.ID, and also to create and manage your own ORG.ID
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@windingtree/org.id-resolver",
3
+ "version": "3.0.0-beta.5",
4
+ "description": "ORGiD DID resolver",
5
+ "main": "dist/src/index.js",
6
+ "types": "dist/src/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "scripts": {
14
+ "lint": "npx eslint . --ext .ts",
15
+ "lint:fix": "npx eslint . --ext .ts --fix",
16
+ "build": "rm -rf dist && npx tsc -p tsconfig-build.json",
17
+ "test": "npx hardhat test",
18
+ "test:coverage": "npx nyc --reporter=html --reporter=lcov hardhat test"
19
+ },
20
+ "keywords": [
21
+ "windingtree",
22
+ "orgid",
23
+ "did",
24
+ "resolver",
25
+ "typescript"
26
+ ],
27
+ "author": "Kostiantyn Smyrnov <kostysh@gmail.com>",
28
+ "homepage": "https://github.com/windingtree/org.id-resolver#README",
29
+ "license": "MIT",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+ssh://git@github.com:windingtree/org.id-resolver.git"
33
+ },
34
+ "dependencies": {
35
+ "@windingtree/org.id": "3.0.0-beta.6",
36
+ "@windingtree/org.id-auth": "1.0.0-beta.26",
37
+ "@windingtree/org.id-core": "1.0.0-beta.26",
38
+ "@windingtree/org.id-utils": "1.0.0-beta.26",
39
+ "@windingtree/org.json-schema": "1.0.0-beta.5",
40
+ "ethers": "5.5.1",
41
+ "luxon": "2.1.1"
42
+ },
43
+ "devDependencies": {
44
+ "@istanbuljs/nyc-config-typescript": "1.0.1",
45
+ "@nomiclabs/hardhat-ethers": "2.0.2",
46
+ "@types/chai": "4.2.22",
47
+ "@types/chai-as-promised": "7.1.4",
48
+ "@types/luxon": "2.0.7",
49
+ "@types/mocha": "9.0.0",
50
+ "@windingtree/org.id-test-setup": "1.0.0-beta.26",
51
+ "chai": "4.3.4",
52
+ "chai-as-promised": "7.1.1",
53
+ "eslint": "8.3.0",
54
+ "hardhat": "2.7.0",
55
+ "nyc": "15.1.0",
56
+ "ts-node": "10.4.0",
57
+ "typescript": "4.5.2"
58
+ }
59
+ }
@@ -0,0 +1,118 @@
1
+ import type { ORGJSONVCNFT } from '@windingtree/org.json-schema/types/orgVc';
2
+ import type { ORGJSON, CapabilityDelegationReference } from '@windingtree/org.json-schema/types/org.json';
3
+ import type { JWK } from '@windingtree/org.id-auth/dist/keys';
4
+ import type { OrgIdData, KnownProvider } from '@windingtree/org.id-core';
5
+ export interface ChainResolver {
6
+ getOrgId(orgId: string): Promise<OrgIdData | null>;
7
+ }
8
+ export interface FetcherResolver {
9
+ getOrgJson(uri: string): Promise<ORGJSONVCNFT>;
10
+ }
11
+ export interface ChainConfig {
12
+ blockchainId: string;
13
+ blockchainType: string;
14
+ init(): ChainResolver;
15
+ }
16
+ export interface FetcherConfig {
17
+ id: string;
18
+ name: string;
19
+ init(): FetcherResolver;
20
+ }
21
+ export interface ResolverOptions {
22
+ chains: ChainConfig[];
23
+ fetchers: FetcherConfig[];
24
+ maxDepth?: number;
25
+ }
26
+ export interface Chains {
27
+ [blockchainId: string]: {
28
+ resolver: ChainResolver;
29
+ config: {
30
+ blockchainId: string;
31
+ blockchainType: string;
32
+ };
33
+ };
34
+ }
35
+ export interface Fetchers {
36
+ [id: string]: {
37
+ resolver: FetcherResolver;
38
+ config: {
39
+ id: string;
40
+ name: string;
41
+ };
42
+ };
43
+ }
44
+ export declare type DidResolutionContext = 'https://w3id.org/did-resolution/v1';
45
+ export declare type DidResolutionContentType = 'application/did+ld+json';
46
+ export interface NormalizedOrgIdData extends Omit<OrgIdData, 'tokenId'> {
47
+ tokenId: string;
48
+ }
49
+ export interface DidResolutionMetaData {
50
+ contentType: DidResolutionContentType;
51
+ retrieved: string;
52
+ duration: number;
53
+ resolverVersion: string;
54
+ credential?: ORGJSONVCNFT;
55
+ error?: string;
56
+ }
57
+ export interface DidDocumentMetadata {
58
+ created?: string;
59
+ updated?: string;
60
+ deactivated?: boolean;
61
+ data?: NormalizedOrgIdData;
62
+ }
63
+ export interface DidResolutionResponse {
64
+ '@context': DidResolutionContext;
65
+ did: string;
66
+ didDocument: ORGJSON | null;
67
+ didResolutionMetadata: DidResolutionMetaData;
68
+ didDocumentMetadata: DidDocumentMetadata | null;
69
+ }
70
+ export interface OrgIdResolverAPI {
71
+ resolve(orgId: string): Promise<DidResolutionResponse>;
72
+ }
73
+ export interface DidGroupedCheckResult extends RegExpExecArray {
74
+ groups: {
75
+ did: string;
76
+ method: string;
77
+ network?: string;
78
+ id: string;
79
+ query?: string;
80
+ fragment?: string;
81
+ };
82
+ }
83
+ export interface IpfsUriGroupedResult extends RegExpExecArray {
84
+ groups: {
85
+ protocol: string;
86
+ cid: string;
87
+ };
88
+ }
89
+ export interface ParsedDid {
90
+ did: string;
91
+ method: string;
92
+ network: string;
93
+ orgId: string;
94
+ query?: string;
95
+ fragment?: string;
96
+ }
97
+ export interface ParsedUri {
98
+ uri: string;
99
+ type: string;
100
+ }
101
+ export interface ResolverCache {
102
+ [did: string]: DidResolutionResponse;
103
+ }
104
+ export declare type VerificationMethodPublicKey = JWK | string;
105
+ export declare const setupChains: (chains: ChainConfig[]) => Chains;
106
+ export declare const setupFetchers: (fetchers: FetcherConfig[]) => Fetchers;
107
+ export declare const parseDid: (did: string) => ParsedDid;
108
+ export declare const parseUri: (uri: string) => ParsedUri;
109
+ export declare const parseCapabilityDelegates: (capabilityDelegate: CapabilityDelegationReference) => string[];
110
+ export declare const buildEvmChainConfig: (blockchainId: string, blockchainType: string, orgIdContractAddress: string, providerOrUri: KnownProvider) => ChainConfig;
111
+ export declare const buildHttpFetcherConfig: () => FetcherConfig;
112
+ export declare const buildDidResolutionResponse: (did: string, resolutionStart: number, orgId?: OrgIdData | undefined, didDocument?: import("@windingtree/org.json-schema/types/org.json").OrgJsonReference | undefined, error?: string | undefined) => DidResolutionResponse;
113
+ /**
114
+ * ORGiD resolver implementation
115
+ * according to https://w3c-ccg.github.io/did-resolution
116
+ * and https://www.w3.org/TR/did-core/#did-resolution
117
+ */
118
+ export declare const OrgIdResolver: (options: ResolverOptions) => OrgIdResolverAPI;