Skip to content

Commit 5a2ae7a

Browse files
authored
Merge pull request #345 from 0xPolygonID/develop
Pre release PR
2 parents 2a994fa + 79e6da3 commit 5a2ae7a

File tree

20 files changed

+184
-67
lines changed

20 files changed

+184
-67
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 2.2.8+2
2+
- Fixed protocol library method for revocation status check
3+
14
## 2.2.8+1
25
- Fixed protocol libraries that caused issues with iOS devices
36

IDEN3MESSAGE_PARSER.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Iden3Message Parser
2+
3+
## Introduction
4+
5+
With the latest update, the content of the QR code provided by the Issuer or Verifier could be in three different formats:
6+
- Url (iden3comm://?request_uri=)
7+
- Base64 encoded (iden3comm://?i_m=)
8+
- RAW Json format (json)
9+
10+
## Code Snippet
11+
to parse the qr code content, you can use the following code snippet as an example:
12+
13+
```dart
14+
class QrcodeParserUtils {
15+
final PolygonIdSdk _polygonIdSdk;
16+
17+
QrcodeParserUtils(this._polygonIdSdk);
18+
19+
Future<Iden3MessageEntity> getIden3MessageFromQrCode(String message) async {
20+
try {
21+
String rawMessage = message;
22+
if (message.startsWith("iden3comm://?i_m")) {
23+
rawMessage = await _getMessageFromBase64(message);
24+
}
25+
26+
if (message.startsWith("iden3comm://?request_uri")) {
27+
rawMessage = await _getMessageFromRemote(message);
28+
}
29+
30+
Iden3MessageEntity? _iden3Message =
31+
await _polygonIdSdk.iden3comm.getIden3Message(message: rawMessage);
32+
return _iden3Message;
33+
} catch (error) {
34+
throw Exception("Error while processing the QR code");
35+
}
36+
}
37+
38+
Future<String> _getMessageFromRemote(String message) async {
39+
try {
40+
message = message.replaceAll("iden3comm://?request_uri=", "");
41+
http.Response response = await http.get(Uri.parse(message));
42+
if (response.statusCode != 200) {
43+
throw Exception("Error while getting the message from the remote");
44+
}
45+
return response.body;
46+
} catch (error) {
47+
throw Exception("Error while getting the message from the remote");
48+
}
49+
}
50+
51+
Future<String> _getMessageFromBase64(String message) async {
52+
try {
53+
message = message.replaceAll("iden3comm://?i_m=", "");
54+
String decodedMessage = String.fromCharCodes(base64.decode(message));
55+
return decodedMessage;
56+
} catch (error) {
57+
throw Exception("Error while getting the message from the base64");
58+
}
59+
}
60+
}
61+
```

0 commit comments

Comments
 (0)