Skip to content

Commit

Permalink
fix: Move parseDid method to ssi-types
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Sep 3, 2022
1 parent 21a8341 commit 0b28de3
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 61 deletions.
1 change: 1 addition & 0 deletions packages/did-auth-siop-op-authenticator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"dependencies": {
"@sphereon/did-auth-siop": "0.2.13",
"@sphereon/pex": "1.1.3",
"@sphereon/ssi-types": "^0.8.0",
"@sphereon/ssi-sdk-core": "^0.8.0",
"@veramo/core": "3.1.2-next.84",
"@veramo/utils": "3.1.2-next.84",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DIDDocumentSection, IIdentifier, IKey, TKeyType } from '@veramo/core'
import { _ExtendedIKey, mapIdentifierKeysToDoc } from '@veramo/utils'
import { OP, PresentationExchange, SIOP } from '@sphereon/did-auth-siop'
import { SubmissionRequirementMatch, IVerifiableCredential } from '@sphereon/pex'
import { parseDid } from '@sphereon/ssi-sdk-core'
import { parseDid } from '@sphereon/ssi-types'
import { SuppliedSigner } from '@sphereon/ssi-sdk-core'
import {
IOpSessionArgs,
Expand Down
2 changes: 1 addition & 1 deletion packages/did-auth-siop-op-authenticator/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"outDir": "dist",
"declarationDir": "dist"
},
"references": [{ "path": "../ssi-sdk-core" }]
"references": [{ "path": "../ssi-types" }, { "path": "../ssi-sdk-core" }]
}
1 change: 1 addition & 0 deletions packages/ssi-sdk-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"build": "tsc --build"
},
"dependencies": {
"typeorm": "0.2.45",
"@scure/base": "^1.1.1",
"@sphereon/ssi-types": "^0.8.0",
"@veramo/core": "3.1.2-next.84"
Expand Down
2 changes: 1 addition & 1 deletion packages/ssi-sdk-core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { flattenArray, flattenMigrations, parseDid, multibaseToHex, hexToMultibase, MultibaseFormat } from './utils'
export { flattenArray, flattenMigrations, multibaseToHex, hexToMultibase, MultibaseFormat } from './utils'
export {
VerifiablePresentationSP,
UnsignedPresentationSP,
Expand Down
49 changes: 0 additions & 49 deletions packages/ssi-sdk-core/src/utils/dids.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/ssi-sdk-core/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { hexToMultibase, multibaseToHex, MultibaseFormat } from './encoding'
export { parseDid } from './dids'
export { flattenArray, flattenMigrations } from './database'
48 changes: 48 additions & 0 deletions packages/ssi-types/src/types/did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,51 @@ export interface IParsedDID {
[index: string]: string
}
}

export const parseDid = (did: string): IParsedDID => {
const parsedDid = parse(did)
if (parsedDid === null) {
throw new Error('invalid did')
}

return parsedDid
}

const parse = (didUrl: string): IParsedDID | null => {
const PCT_ENCODED = '(?:%[0-9a-fA-F]{2})'
const ID_CHAR = `(?:[a-zA-Z0-9._-]|${PCT_ENCODED})`
const METHOD = '([a-z0-9]+)'
const METHOD_ID = `((?:${ID_CHAR}*:)*(${ID_CHAR}+))`
const PARAM_CHAR = '[a-zA-Z0-9_.:%-]'
const PARAM = `;${PARAM_CHAR}+=${PARAM_CHAR}*`
const PARAMS = `((${PARAM})*)`
const PATH = `(/[^#?]*)?`
const QUERY = `([?][^#]*)?`
const FRAGMENT = `(#.*)?`
const DID_MATCHER = new RegExp(`^did:${METHOD}:${METHOD_ID}${PARAMS}${PATH}${QUERY}${FRAGMENT}$`)

if (didUrl === '' || !didUrl) return null
const sections = didUrl.match(DID_MATCHER)
if (sections) {
const parts: IParsedDID = {
did: `did:${sections[1]}:${sections[2]}`,
method: sections[1],
id: sections[2],
didUrl,
}
if (sections[4]) {
const params = sections[4].slice(1).split(';')
parts.params = {}
for (const p of params) {
const kv = p.split('=')
parts.params[kv[0]] = kv[1]
}
}
if (sections[6]) parts.path = sections[6]
if (sections[7]) parts.query = sections[7].slice(1)
if (sections[8]) parts.fragment = sections[8].slice(1)
return parts
}

return null
}
5 changes: 3 additions & 2 deletions packages/wellknown-did-issuer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
"build": "tsc --build"
},
"dependencies": {
"@sphereon/wellknown-dids-client": "^0.1.1",
"did-jwt-vc": "^2.1.9",
"@sphereon/ssi-types": "^0.8.0",
"@sphereon/wellknown-dids-client": "^0.1.2",
"did-jwt-vc": "2.1.14",
"typeorm": "0.2.45",
"uuid": "^8.3.2"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseDid } from '@sphereon/ssi-sdk-core'
import { parseDid } from '@sphereon/ssi-types'
import {
DomainLinkageCredential,
IDidConfigurationResource,
Expand Down
2 changes: 1 addition & 1 deletion packages/wellknown-did-issuer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"strictPropertyInitialization": false,
"noUnusedLocals": false
},
"references": [{ "path": "../ssi-sdk-core" }]
"references": [{ "path": "../ssi-types" }]
}
23 changes: 19 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3113,7 +3113,7 @@
colors "~1.2.1"
string-argv "~0.3.1"

"@scure/base@^1.1.1":
"@scure/base@^1.0.0-rc1", "@scure/base@^1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.1.1.tgz#ebb651ee52ff84f420097055f4bf46cfba403938"
integrity sha512-ZxOhsSyxYwLJj3pLZCefNitxsj093tb2vq90mp2txoYeBqbcjDjqFhyM8eUjq/uFm6zJ+mUuqxlS2FkuSY1MTA==
Expand Down Expand Up @@ -3224,7 +3224,7 @@
dependencies:
"@sinonjs/commons" "^1.7.0"

"@sphereon/did-auth-siop@0.2.13":
"@sphereon/did-auth-siop@0.2.13", "@sphereon/did-auth-siop@^0.2.12":
version "0.2.13"
resolved "https://registry.yarnpkg.com/@sphereon/did-auth-siop/-/did-auth-siop-0.2.13.tgz#270d80d1e1d86cc12271961fda281ff4400a95cd"
integrity sha512-ZFT+CoFGXsWcEnBvnagMuREtWI70P0MNTclYwCMHXlUgDYscJBu84RDXV3g0ONX0N4X3KFPCZHgtLXceg1dQGw==
Expand Down Expand Up @@ -3323,7 +3323,22 @@
nanoid "^3.3.4"
string.prototype.matchall "^4.0.7"

"@sphereon/wellknown-dids-client@^0.1.1":
"@sphereon/ssi-sdk-core@^0.7.0":
version "0.7.0"
resolved "https://registry.yarnpkg.com/@sphereon/ssi-sdk-core/-/ssi-sdk-core-0.7.0.tgz#6ab10610a6afcbcf801f9fa25201ca84b74bd06f"
integrity sha512-H3iN+mnU9eP8ztQGUX8V8hbAAgtiSVj2eJqFOddFp/xNYW0K2jBiuuJWV7QvIGata7zwVXt93UEa+XqRmum1kw==
dependencies:
"@scure/base" "^1.0.0-rc1"
"@sphereon/did-auth-siop" "^0.2.12"
"@sphereon/did-uni-client" "^0.4.0"
"@veramo/core" "3.1.2-next.84"
"@veramo/did-manager" "3.1.2-next.84"
debug "^4.1.1"
did-jwt-vc "^2.1.7"
events "^3.3.0"
z-schema "^5.0.2"

"@sphereon/wellknown-dids-client@^0.1.1", "@sphereon/wellknown-dids-client@^0.1.2":
version "0.1.2"
resolved "https://registry.yarnpkg.com/@sphereon/wellknown-dids-client/-/wellknown-dids-client-0.1.2.tgz#b10e41533624e74515d39caffafa90f12e9279b7"
integrity sha512-svj/awJqgAyYwFXpK54V8xXqZvuadlBjDwar3LCNjLCanL9146P3LXwKn0aw9Ep6ZFvtatrdIulpWRKvQ3c9Ag==
Expand Down Expand Up @@ -6762,7 +6777,7 @@ did-context@^3.1.1:
resolved "https://registry.yarnpkg.com/did-context/-/did-context-3.1.1.tgz#a7991b6b3b983f66760a9fc209af5794e5302a30"
integrity sha512-iFpszgSxc7d1kNBJWC+PAzNTpe5LPalzsIunTMIpbG3O37Q7Zi7u4iIaedaM7UhziBhT+Agr9DyvAiXSUyfepQ==

did-jwt-vc@^2.1.7, did-jwt-vc@^2.1.8, did-jwt-vc@^2.1.9:
did-jwt-vc@2.1.14, did-jwt-vc@^2.1.7, did-jwt-vc@^2.1.8, did-jwt-vc@^2.1.9:
version "2.1.14"
resolved "https://registry.yarnpkg.com/did-jwt-vc/-/did-jwt-vc-2.1.14.tgz#0668354d986da7577b830e866bec961584df3c01"
integrity sha512-z3y1sVXi4jdgomK6ZAtAjfkWiRUeMHFfQQ+RMozWdpOW8ECvQlFJE95NmF3E6fpLEyafPthEBAsb1hm4uNcY2g==
Expand Down

0 comments on commit 0b28de3

Please sign in to comment.