Skip to content

Commit

Permalink
feat: Grab types and format from openId response
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Aug 24, 2023
1 parent 30f63bf commit 7d2a4a0
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 322 deletions.
214 changes: 1 addition & 213 deletions lib/app/shared/enum/type/oidc4vc_type.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:credential_manifest/credential_manifest.dart';
import 'package:dio/dio.dart';
import 'package:oidc4vc/oidc4vc.dart';

Expand All @@ -8,277 +7,72 @@ enum OIDC4VCType {
verifierVpType: 'ldp_vp',
offerPrefix: 'openid-credential-offer://',
presentationPrefix: 'openid-vc://',
cryptographicBindingMethodsSupported: ['DID'],
credentialSupported: [
'EmployeeCredential',
'VerifiableId',
'EmailPass',
'PhoneProof',
'GreencypherPass',
],
grantTypesSupported: [
'authorization_code',
'urn:ietf:params:oauth:grant-type:pre-authorized_code',
],
cryptographicSuitesSupported: [
'ES256K',
'ES256',
'ES384',
'ES512',
'RS256',
],
subjectSyntaxTypesSupported: ['did:key', 'did:pkh'],
schemaForType: false,
publicJWKNeeded: false,
serviceDocumentation:
'''We use JSON-LD VC and VP and last release of the specs.\n'''
'''oidc4vci_draft : https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html\n'''
'''siopv2_draft : https://openid.net/specs/openid-connect-self-issued-v2-1_0.html\n'''
'''oidc4vp_draft : https://openid.net/specs/openid-4-verifiable-presentations-1_0.html\n''',
walletMetaData: {
'response_types_supported': ['vp_token', 'id_token'],
'scopes_supported': ['openid'],
'subject_types_supported': ['pairwise'],
'id_token_signing_alg_values_supported': ['ES256K'],
'request_object_signing_alg_values_supported': ['ES256K'],
'subject_syntax_types_supported': ['did:key'],
'id_token_types_supported': ['subject_signed_id_token'],
},
),

EBSIV2(
issuerVcType: 'jwt_vc', // jwt_vc_json, jwt_vc_json-ld, ldp_vc
verifierVpType: 'jwt_vp',
offerPrefix: 'openid://initiate_issuance',
presentationPrefix: 'openid://',
cryptographicBindingMethodsSupported: ['DID'],
cryptographicSuitesSupported: [
'ES256K',
'ES256',
'ES384',
'ES512',
'RS256',
],
subjectSyntaxTypesSupported: ['did:ebsi'],
grantTypesSupported: [
'authorization_code',
'urn:ietf:params:oauth:grant-type:pre-authorized_code',
],
credentialSupported: ['VerifiableDiploma', 'VerifiableId'],
schemaForType: true,
publicJWKNeeded: true,
serviceDocumentation:
'''THIS PROFILE OF OIDC4VCI IS DEPRECATED. EBSI V2 COMPLIANCE. It is the profile of the EBSI V2 compliant test. DID for natural person is did:ebsi.\n'''
'''The schema url is used as the VC type in the credential offer QR code.\n'''
'''The prefix openid_initiate_issuance://\n'''
'''oidc4vci_draft : https://openid.net/specs/openid-connect-4-verifiable-credential-issuance-1_0-05.html#abstract''',
),

GAIAX(
issuerVcType: 'ldp_vc',
verifierVpType: 'ldp_vp',
offerPrefix: 'openid-initiate-issuance://',
presentationPrefix: 'openid://',
cryptographicBindingMethodsSupported: ['DID'],
credentialSupported: [
'EmployeeCredential',
'VerifiableId',
'GreencypherPass',
'EmailPass',
],
grantTypesSupported: [
'authorization_code',
'urn:ietf:params:oauth:grant-type:pre-authorized_code',
],
cryptographicSuitesSupported: [
'ES256K',
'ES256',
'ES384',
'ES512',
'RS256',
],
subjectSyntaxTypesSupported: ['did:key'],
schemaForType: false,
publicJWKNeeded: false,
serviceDocumentation: '''THIS PROFILE OF OIDC4VCI IS DEPRECATED.\n'''
'''oidc4vci_draft : https://openid.net/specs/openid-connect-4-verifiable-credential-issuance-1_0-05.html#name-credential-endpoint\n'''
'''siopv2_draft : https://openid.net/specs/openid-connect-self-issued-v2-1_0.html\n'''
'''oidc4vp_draft : https://openid.net/specs/openid-4-verifiable-presentations-1_0.html''',
),

HEDERA(
issuerVcType: 'jwt_vc',
verifierVpType: 'jwt_vp',
offerPrefix: 'openid-credential-offer-hedera://',
presentationPrefix: 'openid-hedera://',
cryptographicBindingMethodsSupported: ['DID'],
credentialSupported: [
'EmployeeCredential',
'VerifiableId',
'GreencypherPass',
'ListOfProjects',
'PhoneProof',
'EmailPass',
'Over18',
],
grantTypesSupported: [
'authorization_code',
'urn:ietf:params:oauth:grant-type:pre-authorized_code',
],
cryptographicSuitesSupported: [
'ES256K',
'ES256',
'ES384',
'ES512',
'RS256',
],
subjectSyntaxTypesSupported: [
'did:key',
'did:pkh',
'did:web',
'did;hedera',
],
schemaForType: false,
publicJWKNeeded: false,
serviceDocumentation:
'''WORK IN PROGRESS EON project. last release of the specs.\n'''
'''oidc4vci_draft : https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html\n'''
'''siopv2_draft : https://openid.net/specs/openid-connect-self-issued-v2-1_0.html\n'''
'''oidc4vp_draft : https://openid.net/specs/openid-4-verifiable-presentations-1_0.html\n'''
'''Issuer and verifier for marjetplace and WCM\n''',
),

EBSIV3(
issuerVcType: 'jwt_vc',
verifierVpType: 'jwt_vp',
offerPrefix: 'openid://initiate_issuance',
presentationPrefix: 'openid-vc://',
cryptographicBindingMethodsSupported: ['DID'],
credentialSupported: [
'VerifiableDiploma',
'VerifiableId',
'GreencypherPass',
'ListOfProjects',
],
grantTypesSupported: [
'authorization_code',
'urn:ietf:params:oauth:grant-type:pre-authorized_code',
],
cryptographicSuitesSupported: [
'ES256K',
'ES256',
'ES384',
'ES512',
'RS256',
],
trustFramework: {
'name': 'ebsi',
'type': 'Accreditation',
'uri': 'TIR link towards accreditation',
},
subjectSyntaxTypesSupported: ['did:key'],
schemaForType: false,
publicJWKNeeded: false,
serviceDocumentation:
'New environment for V3 compliance test, use specific did:key',
walletMetaData: {
'authorization_endpoint': 'openid:',
'response_types_supported': ['vp_token', 'id_token'],
'vp_formats_supported': {
'jwt_vp': {
'alg_values_supported': ['ES256'],
},
'jwt_vc': {
'alg_values_supported': ['ES256'],
},
},
'scopes_supported': ['openid'],
'subject_types_supported': ['public'],
'id_token_signing_alg_values_supported': ['ES256'],
'request_object_signing_alg_values_supported': ['ES256'],
'subject_syntax_types_supported': [
'urn:ietf:params:oauth:jwk-thumbprint',
'did:key:jwk_jcs-pub',
],
'id_token_types_supported': ['subject_signed_id_token'],
},
),

JWTVC(
issuerVcType: 'jwt_vc',
offerPrefix: '',
verifierVpType: 'jwt_vp',
presentationPrefix: 'openid-vc://',
cryptographicBindingMethodsSupported: ['DID'],
credentialSupported: [],
grantTypesSupported: [],
cryptographicSuitesSupported: [
'ES256K',
'ES256',
'ES384',
'ES512',
'RS256',
],
subjectSyntaxTypesSupported: ['did:ion', 'did:web'],
schemaForType: false,
publicJWKNeeded: false,
serviceDocumentation:
'https://identity.foundation/jwt-vc-presentation-profile/',
);

const OIDC4VCType({
required this.issuerVcType,
required this.verifierVpType,
required this.offerPrefix,
required this.presentationPrefix,
required this.cryptographicBindingMethodsSupported,
required this.cryptographicSuitesSupported,
required this.subjectSyntaxTypesSupported,
required this.grantTypesSupported,
required this.credentialSupported,
required this.schemaForType,
required this.publicJWKNeeded,
required this.serviceDocumentation,
this.walletMetaData,
this.trustFramework,
});

final String issuerVcType;
final String verifierVpType;
final String offerPrefix;
final String presentationPrefix;
final List<String> cryptographicBindingMethodsSupported;
final List<String> cryptographicSuitesSupported;
final List<String> subjectSyntaxTypesSupported;
final Map<String, dynamic>? trustFramework;
final List<String> grantTypesSupported;
final List<String> credentialSupported;
final bool schemaForType;
final bool publicJWKNeeded;
final String serviceDocumentation;
final Map<String, dynamic>? walletMetaData;
}

extension OIDC4VCTypeX on OIDC4VCType {
OIDC4VC get getOIDC4VC {
return OIDC4VC(
client: Dio(),
oidc4vcModel: OIDC4VCModel(
issuerVcType: issuerVcType,
verifierVpType: verifierVpType,
offerPrefix: offerPrefix,
presentationPrefix: presentationPrefix,
cryptographicBindingMethodsSupported:
cryptographicBindingMethodsSupported,
cryptographicSuitesSupported: cryptographicSuitesSupported,
subjectSyntaxTypesSupported: subjectSyntaxTypesSupported,
grantTypesSupported: grantTypesSupported,
credentialSupported: credentialSupported,
schemaForType: schemaForType,
publicJWKNeeded: publicJWKNeeded,
serviceDocumentation: serviceDocumentation,
trustFramework: trustFramework,
walletMetaData: walletMetaData,
),
);
}
Expand Down Expand Up @@ -327,11 +121,5 @@ extension OIDC4VCTypeX on OIDC4VCType {
}
}

bool isJwtVpInJwtVCRequired(PresentationDefinition presentationDefinition) {
if (presentationDefinition.format != null) {
return presentationDefinition.format!.jwtVp != null;
}

return verifierVpType == 'jwt_vp';
}
bool get schemaForType => this == OIDC4VCType.EBSIV2;
}
29 changes: 16 additions & 13 deletions lib/app/shared/helper_functions/helper_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,19 @@ bool isPolygonIdUrl(String url) =>
url.startsWith('{"typ":') ||
url.startsWith('{"type":');

bool isOIDC4VCIUrl(Uri uri) {
return uri.toString().startsWith('openid');
}

bool isSIOPV2OROIDC4VPUrl(Uri uri) {
final isOID4VCUrl = uri.toString().startsWith('openid');

return isOID4VCUrl &&
(uri.toString().startsWith('openid://?') ||
uri.toString().startsWith('openid-vc://?') ||
uri.toString().startsWith('openid-hedera://?'));
}

OIDC4VCType? getOIDC4VCTypeForIssuance(String url) {
for (final oidc4vcType in OIDC4VCType.values) {
if (oidc4vcType.isEnabled && url.startsWith(oidc4vcType.offerPrefix)) {
Expand All @@ -458,29 +471,19 @@ OIDC4VCType? getOIDC4VCTypeForIssuance(String url) {
return null;
}

(String, List<String>?, String?) getCredentialData({
required dynamic credential,
OIDC4VCType? oidc4vcType,
}) {
String getCredentialData(dynamic credential) {
late String cred;
List<String>? credentialSupported;
String? format;

if (credential is String) {
cred = credential;
if (oidc4vcType != null) {
credentialSupported = oidc4vcType.credentialSupported;
format = oidc4vcType.issuerVcType;
}
} else if (credential is Map<String, dynamic>) {
credentialSupported = (credential['types'] as List<dynamic>)
final credentialSupported = (credential['types'] as List<dynamic>)
.map((e) => e.toString())
.toList();
cred = credentialSupported.last;
format = credential['format'].toString();
} else {
throw Exception();
}

return (cred, credentialSupported, format);
return cred;
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ class Oidc4vcCredentialPickView extends StatelessWidget {
...List.generate(
credentials.length,
(index) {
final (credential, _, _) = getCredentialData(
credential: credentials[index],
final credential = getCredentialData(
credentials[index],
);

final CredentialSubjectType credentialSubjectType =
Expand Down
Loading

0 comments on commit 7d2a4a0

Please sign in to comment.