-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: SSISDK-5 refactor and additional test coverage
- Loading branch information
1 parent
342f440
commit e1c8bc2
Showing
11 changed files
with
2,533 additions
and
2,112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { | ||
decodeJsonProperties, | ||
getClientIdFromCredentialOfferPayload, | ||
getURIComponentsAsArray, | ||
PRE_AUTH_CODE_LITERAL, | ||
PRE_AUTH_GRANT_LITERAL, | ||
UniformCredentialOfferRequest | ||
} from '@sphereon/oid4vci-common' | ||
import { fetch } from 'cross-fetch' | ||
|
||
export function isUriEncoded(str: string): boolean { | ||
const pattern = /%[0-9A-F]{2}/i | ||
return pattern.test(str) | ||
} | ||
|
||
export async function handleCredentialOfferUri(uri: string) { | ||
const uriObj = getURIComponentsAsArray(uri) as unknown as Record<string, string> | ||
const credentialOfferUri = decodeURIComponent(uriObj['credential_offer_uri']) | ||
const decodedUri = isUriEncoded(credentialOfferUri) ? decodeURIComponent(credentialOfferUri) : credentialOfferUri | ||
const response = await fetch(decodedUri) | ||
|
||
if (!(response && response.status >= 200 && response.status < 400)) { | ||
return Promise.reject(`the credential offer URI endpoint call was not successful. http code ${response.status} - reason ${response.statusText}`) | ||
} | ||
|
||
if (response.headers.get('Content-Type')?.startsWith('application/json') === false) { | ||
return Promise.reject('the credential offer URI endpoint did not return content type application/json') | ||
} | ||
|
||
return { | ||
credential_offer: decodeJsonProperties(await response.json()) | ||
} | ||
} | ||
|
||
export function constructBaseResponse(request: UniformCredentialOfferRequest, scheme: string, baseUrl: string) { | ||
const clientId = getClientIdFromCredentialOfferPayload(request.credential_offer) | ||
const grants = request.credential_offer?.grants | ||
|
||
return { | ||
scheme, | ||
baseUrl, | ||
...(clientId && { clientId }), | ||
...request, | ||
...(grants?.authorization_code?.issuer_state && { issuerState: grants.authorization_code.issuer_state }), | ||
...(grants?.[PRE_AUTH_GRANT_LITERAL]?.[PRE_AUTH_CODE_LITERAL] && { | ||
preAuthorizedCode: grants[PRE_AUTH_GRANT_LITERAL][PRE_AUTH_CODE_LITERAL] | ||
}), | ||
...(request.credential_offer?.grants?.[PRE_AUTH_GRANT_LITERAL]?.tx_code && { | ||
txCode: request.credential_offer.grants[PRE_AUTH_GRANT_LITERAL].tx_code | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.