@@ -9,7 +9,7 @@ import type { JWK } from '@windingtree/org.id-auth/dist/keys';
9
9
import type { OrgIdData , KnownProvider } from '@windingtree/org.id-core' ;
10
10
import { parseBlockchainAccountId , verifyVC } from '@windingtree/org.id-auth/dist/vc' ;
11
11
import { OrgIdContract } from '@windingtree/org.id-core' ;
12
- import { regexp , http , object } from '@windingtree/org.id-utils' ;
12
+ import { regexp , http , object , parsers } from '@windingtree/org.id-utils' ;
13
13
import { DateTime } from 'luxon' ;
14
14
import { version } from '../package.json' ;
15
15
@@ -95,38 +95,6 @@ export interface OrgIdResolverAPI {
95
95
resolve ( orgId : string ) : Promise < DidResolutionResponse > ;
96
96
}
97
97
98
- export interface DidGroupedCheckResult extends RegExpExecArray {
99
- groups : {
100
- did : string ;
101
- method : string ;
102
- network ?: string ;
103
- id : string ;
104
- query ?: string ;
105
- fragment ?: string ;
106
- }
107
- }
108
-
109
- export interface IpfsUriGroupedResult extends RegExpExecArray {
110
- groups : {
111
- protocol : string ;
112
- cid : string ;
113
- }
114
- }
115
-
116
- export interface ParsedDid {
117
- did : string ;
118
- method : string ;
119
- network : string ;
120
- orgId : string ;
121
- query ?: string ;
122
- fragment ?: string ;
123
- }
124
-
125
- export interface ParsedUri {
126
- uri : string ;
127
- type : string ;
128
- }
129
-
130
98
export interface ResolverCache {
131
99
[ did : string ] : DidResolutionResponse
132
100
}
@@ -165,68 +133,6 @@ export const setupFetchers = (fetchers: FetcherConfig[]): Fetchers =>
165
133
{ }
166
134
) ;
167
135
168
- // Parse raw DID and extract its parts
169
- // @todo Move `parseDid` to SDK utils
170
- export const parseDid = ( did : string ) : ParsedDid => {
171
- const groupedCheck = regexp . didGrouped . exec ( did ) as DidGroupedCheckResult ;
172
-
173
- if ( ! groupedCheck || ! groupedCheck . groups || ! groupedCheck . groups . did ) {
174
- throw new Error ( `Invalid DID format: ${ did } ` ) ;
175
- }
176
-
177
- const {
178
- method,
179
- network,
180
- id,
181
- query,
182
- fragment
183
- } = groupedCheck . groups ;
184
-
185
- return {
186
- did,
187
- method,
188
- network : network || '1' , // Mainnet is default value
189
- orgId : id ,
190
- query,
191
- fragment
192
- } ;
193
- } ;
194
-
195
- // Parse raw ORG.JSON uri and extract an uri type
196
- // @todo Move `parseUri` to SDK utils
197
- export const parseUri = ( uri : string ) : ParsedUri => {
198
- let parsedUri : string ;
199
- let type : string ;
200
-
201
- if ( regexp . uriHttp . exec ( uri ) ) {
202
- parsedUri = uri ;
203
- type = 'http' ;
204
- } else if ( regexp . ipfs . exec ( uri ) || regexp . ipfsUri . exec ( uri ) ) {
205
- type = 'ipfs' ;
206
-
207
- if ( ! regexp . ipfsUri . exec ( uri ) ) {
208
- parsedUri = uri ;
209
- } else {
210
- const ipfsGroupedResult = regexp . ipfsUriGrouped . exec ( uri ) as IpfsUriGroupedResult ;
211
-
212
- if ( ! ipfsGroupedResult ) {
213
- // should never happen because it checked twice
214
- throw new Error ( `Unable to extract CID from IPFS URI: ${ uri } ` ) ;
215
- }
216
-
217
- parsedUri = ipfsGroupedResult . groups . cid ;
218
- }
219
-
220
- } else {
221
- throw new Error ( `Invalid URI: ${ uri } ` ) ;
222
- }
223
-
224
- return {
225
- uri : parsedUri ,
226
- type
227
- }
228
- } ;
229
-
230
136
export const parseCapabilityDelegates = (
231
137
capabilityDelegate : CapabilityDelegationReference
232
138
) : string [ ] => capabilityDelegate . map (
@@ -369,7 +275,7 @@ export const OrgIdResolver = (options: ResolverOptions): OrgIdResolverAPI => {
369
275
level : number
370
276
) : Promise < VerificationMethodPublicKey > => {
371
277
372
- const { did } = parseDid ( verificationMethodId ) ;
278
+ const { did } = parsers . parseDid ( verificationMethodId ) ;
373
279
const parentDid = object . getDeepValue (
374
280
parentOrgJsonVc ,
375
281
'credentialSubject.id'
@@ -451,7 +357,7 @@ export const OrgIdResolver = (options: ResolverOptions): OrgIdResolverAPI => {
451
357
const resolutionStart = Date . now ( ) ;
452
358
453
359
try {
454
- const { did : parsedDid , network, orgId } = parseDid ( did ) ;
360
+ const { did : parsedDid , network, orgId } = parsers . parseDid ( did ) ;
455
361
did = parsedDid ;
456
362
457
363
if ( did === rootResolutionDid ) {
@@ -479,7 +385,7 @@ export const OrgIdResolver = (options: ResolverOptions): OrgIdResolverAPI => {
479
385
const {
480
386
uri,
481
387
type : uriType
482
- } = parseUri ( orgJsonUri ) ;
388
+ } = parsers . parseUri ( orgJsonUri ) ;
483
389
484
390
const selectedFetcher = fetchers [ uriType ] ;
485
391
@@ -563,7 +469,7 @@ export const OrgIdResolver = (options: ResolverOptions): OrgIdResolverAPI => {
563
469
const {
564
470
orgId : verificationOrgId ,
565
471
network : verificationNetwork
566
- } = parseDid ( vcVerificationMethod ) ;
472
+ } = parsers . parseDid ( vcVerificationMethod ) ;
567
473
568
474
if ( verificationOrgId !== orgId ) {
569
475
throw new Error (
0 commit comments