diff --git a/packages/did-auth-siop-op-authenticator/package.json b/packages/did-auth-siop-op-authenticator/package.json index 8589c03c6..cf340a522 100644 --- a/packages/did-auth-siop-op-authenticator/package.json +++ b/packages/did-auth-siop-op-authenticator/package.json @@ -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", diff --git a/packages/did-auth-siop-op-authenticator/src/session/OpSession.ts b/packages/did-auth-siop-op-authenticator/src/session/OpSession.ts index 299da7510..863c5ec46 100644 --- a/packages/did-auth-siop-op-authenticator/src/session/OpSession.ts +++ b/packages/did-auth-siop-op-authenticator/src/session/OpSession.ts @@ -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, diff --git a/packages/did-auth-siop-op-authenticator/tsconfig.json b/packages/did-auth-siop-op-authenticator/tsconfig.json index f1ea09b35..8690ecd3c 100644 --- a/packages/did-auth-siop-op-authenticator/tsconfig.json +++ b/packages/did-auth-siop-op-authenticator/tsconfig.json @@ -5,5 +5,5 @@ "outDir": "dist", "declarationDir": "dist" }, - "references": [{ "path": "../ssi-sdk-core" }] + "references": [{ "path": "../ssi-types" }, { "path": "../ssi-sdk-core" }] } diff --git a/packages/ssi-sdk-core/package.json b/packages/ssi-sdk-core/package.json index 7181aa07d..ff33cef07 100644 --- a/packages/ssi-sdk-core/package.json +++ b/packages/ssi-sdk-core/package.json @@ -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" diff --git a/packages/ssi-sdk-core/src/index.ts b/packages/ssi-sdk-core/src/index.ts index 0fe700b97..ca6d31495 100644 --- a/packages/ssi-sdk-core/src/index.ts +++ b/packages/ssi-sdk-core/src/index.ts @@ -1,4 +1,4 @@ -export { flattenArray, flattenMigrations, parseDid, multibaseToHex, hexToMultibase, MultibaseFormat } from './utils' +export { flattenArray, flattenMigrations, multibaseToHex, hexToMultibase, MultibaseFormat } from './utils' export { VerifiablePresentationSP, UnsignedPresentationSP, diff --git a/packages/ssi-sdk-core/src/utils/dids.ts b/packages/ssi-sdk-core/src/utils/dids.ts deleted file mode 100644 index 550abefd1..000000000 --- a/packages/ssi-sdk-core/src/utils/dids.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { IParsedDID } from '@sphereon/ssi-types' - -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 -} diff --git a/packages/ssi-sdk-core/src/utils/index.ts b/packages/ssi-sdk-core/src/utils/index.ts index df99a20c6..1072adb5d 100644 --- a/packages/ssi-sdk-core/src/utils/index.ts +++ b/packages/ssi-sdk-core/src/utils/index.ts @@ -1,3 +1,2 @@ export { hexToMultibase, multibaseToHex, MultibaseFormat } from './encoding' -export { parseDid } from './dids' export { flattenArray, flattenMigrations } from './database' diff --git a/packages/ssi-types/src/types/did.ts b/packages/ssi-types/src/types/did.ts index 0bedb7e84..fd19a5c36 100644 --- a/packages/ssi-types/src/types/did.ts +++ b/packages/ssi-types/src/types/did.ts @@ -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 +} diff --git a/packages/wellknown-did-issuer/package.json b/packages/wellknown-did-issuer/package.json index 8e92600c2..ce6135b3e 100644 --- a/packages/wellknown-did-issuer/package.json +++ b/packages/wellknown-did-issuer/package.json @@ -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" }, diff --git a/packages/wellknown-did-issuer/src/agent/WellKnownDidIssuer.ts b/packages/wellknown-did-issuer/src/agent/WellKnownDidIssuer.ts index c429788b9..6aa234f6f 100644 --- a/packages/wellknown-did-issuer/src/agent/WellKnownDidIssuer.ts +++ b/packages/wellknown-did-issuer/src/agent/WellKnownDidIssuer.ts @@ -1,4 +1,4 @@ -import { parseDid } from '@sphereon/ssi-sdk-core' +import { parseDid } from '@sphereon/ssi-types' import { DomainLinkageCredential, IDidConfigurationResource, diff --git a/packages/wellknown-did-issuer/tsconfig.json b/packages/wellknown-did-issuer/tsconfig.json index 22ccbeada..aecb9810c 100644 --- a/packages/wellknown-did-issuer/tsconfig.json +++ b/packages/wellknown-did-issuer/tsconfig.json @@ -7,5 +7,5 @@ "strictPropertyInitialization": false, "noUnusedLocals": false }, - "references": [{ "path": "../ssi-sdk-core" }] + "references": [{ "path": "../ssi-types" }] } diff --git a/yarn.lock b/yarn.lock index 968eaaca6..78dc112b8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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== @@ -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== @@ -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== @@ -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==