Skip to content

Commit

Permalink
feat: Add new profile ebsi 4.0 #2897
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Sep 20, 2024
1 parent 9df8559 commit 3d52c20
Show file tree
Hide file tree
Showing 18 changed files with 194 additions and 64 deletions.
1 change: 1 addition & 0 deletions lib/app/shared/constants/parameters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class Parameters {
static const String walletName = 'altme_wallet';

static const DidKeyType didKeyTypeForEbsiV3 = DidKeyType.ebsiv3;
static const DidKeyType didKeyTypeForEbsiV4 = DidKeyType.ebsiv4;
static const DidKeyType didKeyTypeForDefault = DidKeyType.edDSA;
static const DidKeyType didKeyTypeForDutch = DidKeyType.jwkP256;
static const DidKeyType didKeyTypeForOwfBaselineProfile = DidKeyType.jwkP256;
Expand Down
4 changes: 2 additions & 2 deletions lib/app/shared/enum/type/oidc4vc_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ enum OIDC4VCType {
presentationPrefix: 'openid-hedera://',
),

EBSIV3(
EBSI(
offerPrefix: 'openid-credential-offer://',
presentationPrefix: 'openid-vc://',
),
Expand Down Expand Up @@ -44,7 +44,7 @@ extension OIDC4VCTypeX on OIDC4VCType {
case OIDC4VCType.DEFAULT:
case OIDC4VCType.GAIAX:
case OIDC4VCType.GREENCYPHER:
case OIDC4VCType.EBSIV3:
case OIDC4VCType.EBSI:
case OIDC4VCType.HAIP:
return true;
case OIDC4VCType.JWTVC:
Expand Down
6 changes: 6 additions & 0 deletions lib/app/shared/enum/type/profile/did_key_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ enum DidKeyType {
p256,
@JsonValue('did:key:ebsi')
ebsiv3,
ebsiv4,
@JsonValue('did:jwk:p-256')
jwkP256,
@JsonValue(
Expand All @@ -29,6 +30,8 @@ extension DidKeyTypeX on DidKeyType {
return 'did:key P-256';
case DidKeyType.ebsiv3:
return 'did:key EBSI-V3';
case DidKeyType.ebsiv4:
return 'did:key EBSI-V4';
case DidKeyType.jwkP256:
return 'did:jwk P-256';
case DidKeyType.jwtClientAttestation:
Expand All @@ -46,6 +49,8 @@ extension DidKeyTypeX on DidKeyType {
return l10n.keyDecentralizedIDP256;
case DidKeyType.ebsiv3:
return l10n.ebsiV3DecentralizedId;
case DidKeyType.ebsiv4:
return l10n.ebsiV4DecentralizedId;
case DidKeyType.jwkP256:
return l10n.jwkDecentralizedIDP256;
case DidKeyType.jwtClientAttestation:
Expand All @@ -62,6 +67,7 @@ extension DidKeyTypeX on DidKeyType {
case DidKeyType.edDSA:
return true;
case DidKeyType.ebsiv3:
case DidKeyType.ebsiv4:
return false;
}
}
Expand Down
4 changes: 4 additions & 0 deletions lib/app/shared/enum/type/profile/profile_type.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
enum ProfileType {
defaultOne,
ebsiV3,
ebsiV4,
diipv2point1,
diipv3,
custom,
Expand All @@ -14,6 +15,8 @@ extension ProfileTypeX on ProfileType {
return 'Custom';
case ProfileType.ebsiV3:
return 'European Blockchain Services Infrastructure (EBSI v3.x)';
case ProfileType.ebsiV4:
return 'European Blockchain Services Infrastructure (EBSI v4.x)';
case ProfileType.diipv2point1:
return 'Decentralized Identity Interop Profile (DIIP v2.1)';
case ProfileType.enterprise:
Expand All @@ -32,6 +35,7 @@ extension ProfileTypeX on ProfileType {
case ProfileType.diipv2point1:
return false;
case ProfileType.ebsiV3:
case ProfileType.ebsiV4:
case ProfileType.enterprise:
case ProfileType.diipv3:
return true;
Expand Down
33 changes: 18 additions & 15 deletions lib/app/shared/helper_functions/helper_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,12 @@ String getDateTimeWithoutSpace({DateTime? dateTime}) {
}

int getIndexValue({
required bool isEBSIV3,
required bool isEBSI,
required DidKeyType didKeyType,
}) {
switch (didKeyType) {
case DidKeyType.secp256k1:
if (isEBSIV3) {
if (isEBSI) {
return 3;
} else {
return 1;
Expand All @@ -250,7 +250,8 @@ int getIndexValue({
return 5;
case DidKeyType.jwkP256:
return 6;

case DidKeyType.ebsiv4:
return 7;
case DidKeyType.edDSA:
case DidKeyType.jwtClientAttestation:
return 0; // it is not needed, just assigned
Expand Down Expand Up @@ -282,7 +283,7 @@ Future<String> getPrivateKey({

case DidKeyType.secp256k1:
final index = getIndexValue(
isEBSIV3: true,
isEBSI: true,
didKeyType: didKeyType,
);
final key = profileCubit.oidc4vc.privateKeyFromMnemonic(
Expand All @@ -293,9 +294,10 @@ Future<String> getPrivateKey({

case DidKeyType.p256:
case DidKeyType.ebsiv3:
case DidKeyType.ebsiv4:
case DidKeyType.jwkP256:
final indexValue = getIndexValue(
isEBSIV3: false,
isEBSI: false,
didKeyType: didKeyType,
);

Expand Down Expand Up @@ -398,9 +400,9 @@ DidKeyType? getDidKeyFromString(String? didKeyTypeString) {
Future<String> fetchPrivateKey({
required ProfileCubit profileCubit,
required DidKeyType didKeyType,
bool? isEBSIV3,
bool? isEBSI,
}) async {
if (isEBSIV3 != null && isEBSIV3) {
if (isEBSI != null && isEBSI) {
final privateKey = await getPrivateKey(
profileCubit: profileCubit,
didKeyType: DidKeyType.ebsiv3,
Expand Down Expand Up @@ -533,6 +535,7 @@ Future<(String, String)> getDidAndKid({

switch (didKeyType) {
case DidKeyType.ebsiv3:
case DidKeyType.ebsiv4:

//b'\xd1\xd6\x03' in python
final List<int> prefixByteList = [0xd1, 0xd6, 0x03];
Expand Down Expand Up @@ -592,11 +595,11 @@ Future<(String, String)> getDidAndKid({

Future<(String, String)> fetchDidAndKid({
required String privateKey,
bool? isEBSIV3,
bool? isEBSI,
required ProfileCubit profileCubit,
required DidKeyType didKeyType,
}) async {
if (isEBSIV3 != null && isEBSIV3) {
if (isEBSI != null && isEBSI) {
final (did, kid) = await getDidAndKid(
didKeyType: DidKeyType.ebsiv3,
privateKey: privateKey,
Expand Down Expand Up @@ -785,7 +788,7 @@ Future<
for (final oidc4vcType in OIDC4VCType.values) {
if (oidc4vcType.isEnabled && url.startsWith(oidc4vcType.offerPrefix)) {
if (oidc4vcType == OIDC4VCType.DEFAULT ||
oidc4vcType == OIDC4VCType.EBSIV3) {
oidc4vcType == OIDC4VCType.EBSI) {
if (credSupported?.trustFramework != null &&
credSupported == credSupported?.trustFramework) {
return (
Expand All @@ -801,7 +804,7 @@ Future<
if (credSupported?.trustFramework?.name != null &&
credSupported?.trustFramework?.name == 'ebsi') {
return (
OIDC4VCType.EBSIV3,
OIDC4VCType.EBSI,
openIdConfiguration,
authorizationServerConfiguration,
credentialOfferJson,
Expand Down Expand Up @@ -997,7 +1000,7 @@ Future<Map<String, dynamic>?> getClientMetada({
}
}

Future<bool?> isEBSIV3ForVerifiers({
Future<bool?> isEBSIForVerifiers({
required Uri uri,
required OIDC4VC oidc4vc,
required OIDC4VCIDraftType oidc4vciDraftType,
Expand Down Expand Up @@ -1595,7 +1598,7 @@ bool supportCryptoCredential(ProfileModel profileModel) {
// oAuthClientAttestationPop
Future<(String?, String?, String?, String?, String?)> getClientDetails({
required ProfileCubit profileCubit,
required bool isEBSIV3,
required bool isEBSI,
required String issuer,
}) async {
try {
Expand All @@ -1612,13 +1615,13 @@ Future<(String?, String?, String?, String?, String?)> getClientDetails({

final String privateKey = await fetchPrivateKey(
profileCubit: profileCubit,
isEBSIV3: isEBSIV3,
isEBSI: isEBSI,
didKeyType: didKeyType,
);

final (did, _) = await fetchDidAndKid(
privateKey: privateKey,
isEBSIV3: isEBSIV3,
isEBSI: isEBSI,
profileCubit: profileCubit,
didKeyType: didKeyType,
);
Expand Down
1 change: 1 addition & 0 deletions lib/app/shared/widget/wallet_logo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class WalletLogo extends StatelessWidget {
? ImageStrings.appLogoStage
: ImageStrings.appLogo;
case ProfileType.ebsiV3:
case ProfileType.ebsiV4:
image = ImageStrings.ebsiLogo;
case ProfileType.enterprise:
final isLightTheme =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class DidKeyTypeWidget extends StatelessWidget {
VCFormatType.ldpVc;

final isUnmatchedDid = didKeyType == DidKeyType.ebsiv3 ||
didKeyType == DidKeyType.ebsiv4 ||
didKeyType == DidKeyType.jwkP256;

if (isldpVc && isUnmatchedDid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Oidc4vcCredentialPickPage extends StatelessWidget {
required this.userPin,
required this.preAuthorizedCode,
required this.issuer,
required this.isEBSIV3,
required this.isEBSI,
required this.credentialOfferJson,
required this.openIdConfiguration,
});
Expand All @@ -22,7 +22,7 @@ class Oidc4vcCredentialPickPage extends StatelessWidget {
final String? userPin;
final String? preAuthorizedCode;
final String issuer;
final bool isEBSIV3;
final bool isEBSI;
final dynamic credentialOfferJson;
final OpenIdConfiguration openIdConfiguration;

Expand All @@ -31,7 +31,7 @@ class Oidc4vcCredentialPickPage extends StatelessWidget {
required String? userPin,
required String? preAuthorizedCode,
required String issuer,
required bool isEBSIV3,
required bool isEBSI,
required dynamic credentialOfferJson,
required OpenIdConfiguration openIdConfiguration,
}) =>
Expand All @@ -41,7 +41,7 @@ class Oidc4vcCredentialPickPage extends StatelessWidget {
userPin: userPin,
issuer: issuer,
preAuthorizedCode: preAuthorizedCode,
isEBSIV3: isEBSIV3,
isEBSI: isEBSI,
credentialOfferJson: credentialOfferJson,
openIdConfiguration: openIdConfiguration,
),
Expand All @@ -57,7 +57,7 @@ class Oidc4vcCredentialPickPage extends StatelessWidget {
userPin: userPin,
issuer: issuer,
preAuthorizedCode: preAuthorizedCode,
isEBSIV3: isEBSIV3,
isEBSI: isEBSI,
credentialOfferJson: credentialOfferJson,
openIdConfiguration: openIdConfiguration,
),
Expand All @@ -72,7 +72,7 @@ class Oidc4vcCredentialPickView extends StatelessWidget {
required this.userPin,
required this.preAuthorizedCode,
required this.issuer,
required this.isEBSIV3,
required this.isEBSI,
required this.credentialOfferJson,
required this.openIdConfiguration,
});
Expand All @@ -81,7 +81,7 @@ class Oidc4vcCredentialPickView extends StatelessWidget {
final String? userPin;
final String? preAuthorizedCode;
final String issuer;
final bool isEBSIV3;
final bool isEBSI;
final dynamic credentialOfferJson;
final OpenIdConfiguration openIdConfiguration;

Expand Down Expand Up @@ -198,7 +198,7 @@ class Oidc4vcCredentialPickView extends StatelessWidget {
userPin: userPin,
issuer: issuer,
preAuthorizedCode: preAuthorizedCode,
isEBSIV3: isEBSIV3,
isEBSI: isEBSI,
credentialOfferJson: credentialOfferJson,
qrCodeScanCubit:
context.read<QRCodeScanCubit>(),
Expand Down
36 changes: 36 additions & 0 deletions lib/dashboard/profile/cubit/profile_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,28 @@ class ProfileCubit extends Cubit<ProfileState> {
enterpriseWalletName: enterpriseWalletName,
);

case ProfileType.ebsiV4:
final privateKey = await getPrivateKey(
didKeyType: Parameters.didKeyTypeForEbsiV4,
profileCubit: this,
);

final (did, _) = await getDidAndKid(
didKeyType: Parameters.didKeyTypeForEbsiV4,
privateKey: privateKey,
profileCubit: this,
);

profileModel = ProfileModel.ebsiV4(
polygonIdNetwork: polygonIdNetwork,
walletType: walletType,
walletProtectionType: walletProtectionType,
isDeveloperMode: isDeveloperMode,
clientId: did,
clientSecret: randomString(12),
enterpriseWalletName: enterpriseWalletName,
);

case ProfileType.diipv2point1:
final privateKey = await getPrivateKey(
didKeyType: Parameters.didKeyTypeForDutch,
Expand Down Expand Up @@ -599,6 +621,20 @@ class ProfileCubit extends Cubit<ProfileState> {
.selfSovereignIdentityOptions.customOidc4vcProfile.clientSecret,
),
);
case ProfileType.ebsiV4:
await update(
ProfileModel.ebsiV4(
polygonIdNetwork: state.model.polygonIdNetwork,
walletProtectionType: state.model.walletProtectionType,
isDeveloperMode: state.model.isDeveloperMode,
walletType: state.model.walletType,
enterpriseWalletName: state.model.enterpriseWalletName,
clientId: state.model.profileSetting.selfSovereignIdentityOptions
.customOidc4vcProfile.clientId,
clientSecret: state.model.profileSetting
.selfSovereignIdentityOptions.customOidc4vcProfile.clientSecret,
),
);
case ProfileType.defaultOne:
await update(
ProfileModel.defaultOne(
Expand Down
Loading

0 comments on commit 3d52c20

Please sign in to comment.