@windingtree/org.id-resolver 2.3.4 → 3.0.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,234 +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
- });
47
- resolver.registerSocialFetchMethod(linkedInFetchMethod, {
48
- key: '<LINKEDIN_API_KEY>'
49
- });
50
- resolver.registerSocialFetchMethod(twitterFetchMethod, {
51
- key: '<TWITTER_API_KEY>'
52
- });
53
- resolver.registerFetchMethod(httpFetchMethod);
54
- resolver.registerService(whoisService);
55
-
56
- const result = await resolver.resolve('did:orgid:0x62a7502f4c44d8147b8f7b2a1dbeb8503e8446e77355bb2e4ebf999c7ecc5808');
57
- ```
58
-
59
- ## Algorithm
60
-
61
- 1. Validate DID syntax (must be `did:orgid:bytes32`)
62
- 2. Read organization data from ORG.ID Registry
63
- 3. Fetch and validate [ORG.JSON](https://github.com/windingtree/org.json-schema):
64
- 4. Try to resolve assertions and credentials
65
-
66
- The response of the resolver contains the following information
67
-
68
- ```json
69
- {
70
- // An object that has been resolved from the given DID.
71
- // Can be equal to `null` if JSON file not passed hashes equality check
72
- // or if the file is not passed validation against the ORG.ID schema
73
- "didDocument": {...},
74
-
75
- // Organization identifier
76
- "id": "<organization_id>",
77
-
78
- "organization": {
79
- "orgId": "<organization_id>",
80
- "orgJsonHash": "<organization_json_hash>",
81
- "orgJsonUri": "<organization_json_uri>",
82
- "orgJsonUriBackup1": "<organization_json_uri>",
83
- "orgJsonUriBackup2": "<organization_json_uri>",
84
- "parentOrgId": "<parent_organization_hash_or_zero_hash>",
85
- "owner": "<owner_eth_address>",
86
- "director": "<director_eth_address>",
87
- "isActive": true,// true for `enabled` and false for `disabled`
88
- "isDirectorshipAccepted": true,// director confirmation status
89
- },
90
-
91
- // List of validation results
92
- "checks": [
93
- {
94
- "type": "DID_SYNTAX",
95
- "passed": true,
96
- "errors": [],
97
- "warnings": []
98
- },
99
- {
100
- "type": "ORGID",
101
- "passed": true,
102
- "errors": [],
103
- "warnings": []
104
- },
105
- {
106
- "type": "DID_DOCUMENT",
107
- "passed": true,
108
- "errors": [],
109
- "warnings": []
110
- },
111
- {
112
- "type": "TRUST_ASSERTIONS",
113
- "passed": true
114
- }
115
- ],
116
-
117
- // Verified trust section of the `didDocument`
118
- "trust": {
119
- "assertions": [
120
- {
121
- "type": "dns",
122
- "claim": "test.com",
123
- "proof": "TXT",
124
- "verified": true
125
- },
126
- {
127
- "type": "domain",
128
- "claim": "test2.com",
129
- "proof": "http://test2.com/orgid.txt",
130
- "verified": true,
131
- "whois": {
132
- "domainName": "TEST2.COM",
133
- "registryDomainId": "1234567_DOMAIN_COM-VRSN",
134
- "registrarWhoisServer": "whois.server.net",
135
- "registrarUrl": "http://www.whois.net",
136
- "updatedDate": "2021-03-22T05:01:08Z",
137
- "creationDate": "2011-05-09T18:58:13Z",
138
- "expiryDate": "2024-05-09T18:58:13Z",
139
- "registrar": "Cool Domain",
140
- "registrarIanaId": "345",
141
- "registrarAbuseContactEmail": "abuse@support.server.net",
142
- "registrarAbuseContactPhone": "+33.1234567",
143
- "domainStatus": "clientTransferProhibited",
144
- "nameServer": "NS.SERVER.COM",
145
- "DNSSEC": "unsigned"
146
- }
147
- },
148
- {
149
- "type": "domain",
150
- "claim": "test3.com",
151
- "proof": "http://test3.com/orgid.txt",
152
- "verified": false // Not verified
153
- },
154
- {
155
- "type": "social",
156
- "claim": "twitter.com/jack",
157
- "proof": "https://twitter.com/jack/status/123456789/",
158
- "verified": true
159
- }
160
- ]
161
- },
162
-
163
- // Resolver meta-data like version, date of result and process duration
164
- "resolverMetadata": {
165
- "version": "2.0.0",
166
- "retrieved": "2020-02-21T18:14:13.278Z",
167
- "duration": 979,
168
- "orgIdAddress": "0x2cb8dCf26830B969555E04C2EDe3fc1D1BaD504E"
169
- }
170
- }
171
- ```
172
-
173
- ## Fetching methods
174
-
175
- At least one fetching method is required to the proper working of the resolver.
176
- This library provides a simple fetching method of a file that available via http/https - `httpFetchMethod`.
177
-
178
- To use this method you can get its configuration from the package this way:
179
-
180
- ```javascript
181
- const { OrgIdResolver, httpFetchMethod } = require('@windingtree/org.id-resolver');
182
- const resolver = new OrgIdResolver({...});
183
- resolver.registerFetchMethod(httpFetchMethod);// fetching method should be registered
184
- ```
185
-
186
- Future versions of `DID resolver` library will support more fetching methods like:
187
- IPFS, Swarm and Arweave
188
-
189
- Creation of custom fetching methods is quite simple task. Look at the example of simple fetching method configuration:
190
-
191
- ```javascript
192
- module.exports = {
193
- name: 'unique_method_name',
194
-
195
- // Regexp to match your URI schema
196
- pattern: '^yourpatternrule:',
197
-
198
- fetch: async uri => {
199
- const data = await yourCustomHandler(uri);
200
- return data;
201
- }
202
- };
203
- ```
204
-
205
- ## Development
206
-
207
- ### Test
208
-
209
- ```sh
210
- npm run test
211
- npm run test ./<path_to_test_file>.js
14
+ ```bash
15
+ yarn install
212
16
  ```
213
17
 
214
- ## Test coverage
18
+ ## Build
215
19
 
216
20
  ```bash
217
- npm run coverage
21
+ yarn build
218
22
  ```
219
23
 
220
- ## Lint
24
+ ## Linting & Testing
221
25
 
222
26
  ```bash
223
- npm run lint
224
-
27
+ yarn lint
28
+ yarn test
225
29
  ```
226
-
227
- ## ORG.ID Ecosystem
228
-
229
- - [Winding Tree DAO](https://github.com/windingtree/dao) controls ORG.ID Registry smart contract and some Directories (including their rules)
230
- - [ORG.ID Registry](https://github.com/windingtree/org.id) contains records of all organizations and organizational units
231
- - [ORG.JSON Schema](https://github.com/windingtree/org.json-schema) is a data format for describing organizations
232
- - **ORG.ID Resolver (you are here)**
233
- - [ORG.ID Directories](https://github.com/windingtree/org.id-directories) are curated lists of organizations
234
- - [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.9",
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.27",
37
+ "@windingtree/org.id-core": "1.0.0-beta.27",
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.27",
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;