Skip to content

Commit

Permalink
Merge pull request #394 from 0xPolygonID/feature/credentials-proposal
Browse files Browse the repository at this point in the history
credential proposal object
  • Loading branch information
Emanuel Muroni authored Apr 16, 2024
2 parents 220f8f5 + 4fb475c commit ea8104d
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ enum Iden3MessageType {
proofContractInvokeRequest,
credentialRefresh,
credentialProposalRequest,
credentialProposal,
credentialStatusUpdate;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
import 'package:polygonid_flutter_sdk/iden3comm/domain/entities/common/iden3_message_entity.dart';

/*
https://iden3-communication.io/credentials/0.1/proposal
{
"id": "45f13336-80e3-41b6-8430-f80cc7e32979",
"typ": "application/iden3comm-plain-json",
"type": "https://iden3-communication.io/credentials/0.1/proposal",
"thid": "45f13336-80e3-41b6-8430-f80cc7e32979",
"body": {
"proposals": [{
"credentials": [{
"type": "AnimaProofOfLife",
"context": "https://raw.githubusercontent.com/anima-protocol/claims-polygonid/main/schemas/json-ld/pol-v1.json-ld"
}],
"type": "SynapsCredentialProposal",
"url": "https://synaps-backend-test.polygonid.me/verification?session={{sessionID}}&did={{holderDid}}",
"description": "Synaps credential proposal"
}]
},
"from": "did:polygonid:polygon:amoy:2qTyfBq71SK1BLycaHT7GZ1vSdsY2HveczioQcYMXC",
"to": "did:polygonid:polygon:amoy:2qRHzfG7yvULahKDg9eRNX4kTBJb6EZcCBLQoUKx8x"
}
*/
class CredentialProposal extends Iden3MessageEntity<CredentialProposalBody> {
CredentialProposal({
required String id,
required String typ,
required String type,
required String thid,
required CredentialProposalBody body,
required String from,
required String to,
}) : super(
id: id,
typ: typ,
type: type,
thid: thid,
body: body,
from: from,
to: to,
);

factory CredentialProposal.fromJson(Map<String, dynamic> json) {
return CredentialProposal(
id: json['id'],
typ: json['typ'],
type: json['type'],
thid: json['thid'],
body: CredentialProposalBody.fromJson(json['body']),
from: json['from'],
to: json['to'],
);
}

Map<String, dynamic> toJson() {
return {
"id": id,
"typ": typ,
"type": type,
"thid": thid,
"body": body.toJson(),
"from": from,
"to": to,
};
}
}

class CredentialProposalBody {
final List<CredentialProposalProposal> proposals;

CredentialProposalBody({
required this.proposals,
});

factory CredentialProposalBody.fromJson(Map<String, dynamic> json) {
return CredentialProposalBody(
proposals: List<CredentialProposalProposal>.from(
json['proposals'].map((x) => CredentialProposalProposal.fromJson(x))),
);
}

Map<String, dynamic> toJson() {
return {
"proposals": List<dynamic>.from(
proposals.map((CredentialProposalProposal x) => x.toJson())),
};
}
}

/*
"proposals": [{
"credentials": [{
"type": "AnimaProofOfLife",
"context": "https://raw.githubusercontent.com/anima-protocol/claims-polygonid/main/schemas/json-ld/pol-v1.json-ld"
}],
"type": "SynapsCredentialProposal",
"url": "https://synaps-backend-test.polygonid.me/verification?session={{sessionID}}&did={{holderDid}}",
"description": "Synaps credential proposal"
}]
*/
class CredentialProposalProposal {
final List<CredentialProposalProposalCredential> credentials;
final String type;
final String url;
final String description;

CredentialProposalProposal({
required this.credentials,
required this.type,
required this.url,
required this.description,
});

factory CredentialProposalProposal.fromJson(Map<String, dynamic> json) {
return CredentialProposalProposal(
credentials: List<CredentialProposalProposalCredential>.from(
json['credentials']
.map((x) => CredentialProposalProposalCredential.fromJson(x))),
type: json['type'],
url: json['url'],
description: json['description'],
);
}

Map<String, dynamic> toJson() {
return {
"credentials": List<dynamic>.from(credentials
.map((CredentialProposalProposalCredential x) => x.toJson())),
"type": type,
"url": url,
"description": description,
};
}
}

/*
"credentials": [{
"type": "AnimaProofOfLife",
"context": "https://raw.githubusercontent.com/anima-protocol/claims-polygonid/main/schemas/json-ld/pol-v1.json-ld"
}],
*/
class CredentialProposalProposalCredential {
final String type;
final String context;

CredentialProposalProposalCredential({
required this.type,
required this.context,
});

factory CredentialProposalProposalCredential.fromJson(
Map<String, dynamic> json) {
return CredentialProposalProposalCredential(
type: json['type'],
context: json['context'],
);
}

Map<String, dynamic> toJson() {
return {
"type": type,
"context": context,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class GetIden3MessageTypeUseCase
case "https://iden3-communication.io/credentials/0.1/proposal-request":
type = Iden3MessageType.credentialProposalRequest;
break;
case "https://iden3-communication.io/credentials/0.1/proposal":
type = Iden3MessageType.credentialProposal;
break;
}

return Future.value(type);
Expand Down
3 changes: 3 additions & 0 deletions lib/iden3comm/domain/use_cases/get_iden3message_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:polygonid_flutter_sdk/iden3comm/domain/entities/credential/reque
import 'package:polygonid_flutter_sdk/iden3comm/domain/entities/credential/request/credential_refresh_iden3_message_entity.dart';
import 'package:polygonid_flutter_sdk/iden3comm/domain/entities/credential/request/offer_iden3_message_entity.dart';
import 'package:polygonid_flutter_sdk/iden3comm/domain/entities/credential/request/onchain_offer_iden3_message_entity.dart';
import 'package:polygonid_flutter_sdk/iden3comm/domain/entities/credential/response/credential_proposal_message_entity.dart';
import 'package:polygonid_flutter_sdk/iden3comm/domain/entities/credential/response/credential_status_update_message_entity.dart';
import 'package:polygonid_flutter_sdk/iden3comm/domain/entities/credential/response/fetch_iden3_message_entity.dart';
import 'package:polygonid_flutter_sdk/iden3comm/domain/entities/proof/request/contract_iden3_message_entity.dart';
Expand Down Expand Up @@ -51,6 +52,8 @@ class GetIden3MessageUseCase extends FutureUseCase<String, Iden3MessageEntity> {
return CredentialStatusUpdateMessageEntity.fromJson(json);
case Iden3MessageType.credentialProposalRequest:
return CredentialProposalRequest.fromJson(json);
case Iden3MessageType.credentialProposal:
return CredentialProposal.fromJson(json);
case Iden3MessageType.unknown:
throw UnsupportedIden3MsgTypeException(type);
}
Expand Down

0 comments on commit ea8104d

Please sign in to comment.