Skip to content

Commit

Permalink
AVM-26 | Prepare API client for device pairing
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 2c5b012
Author: Matej Hlatký <hlatky@freevision.sk>
Date:   Fri May 31 15:51:11 2024 +0200

    Update API client; add getDocumentParameters method

commit 84134bc
Author: Matej Hlatký <hlatky@freevision.sk>
Date:   Fri May 17 21:51:19 2024 +0200

    Add new "registerDeviceIntegration" operation

commit 89e33c1
Author: Matej Hlatký <hlatky@freevision.sk>
Date:   Fri May 17 20:34:22 2024 +0200

    Update method signature

commit 9c4cb10
Author: Matej Hlatký <hlatky@freevision.sk>
Date:   Fri May 17 17:43:08 2024 +0200

    Update changelog

commit f949146
Author: Matej Hlatký <hlatky@freevision.sk>
Date:   Fri May 17 17:35:02 2024 +0200

    Update scripts in readme

commit 1755d7e
Author: Matej Hlatký <hlatky@freevision.sk>
Date:   Fri May 17 17:29:33 2024 +0200

    Using existing functions from basic_utils

commit 56d346b
Author: Matej Hlatký <hlatky@freevision.sk>
Date:   Fri May 17 16:04:26 2024 +0200

    Add tests

commit a3d30c2
Author: Matej Hlatký <hlatky@freevision.sk>
Date:   Fri May 17 16:03:51 2024 +0200

    Cleanup

commit 82651d6
Author: Matej Hlatký <hlatky@freevision.sk>
Date:   Fri May 17 16:01:17 2024 +0200

    Regenerate REST client

commit 426ed90
Author: Matej Hlatký <hlatky@freevision.sk>
Date:   Fri May 17 16:00:50 2024 +0200

    Prepare functions to generate encryption key and asymmetric key pair

commit 84bf6b4
Author: Matej Hlatký <hlatky@freevision.sk>
Date:   Thu May 16 18:14:54 2024 +0200

    Limit chopper version
  • Loading branch information
Matej-Hlatky committed May 31, 2024
1 parent 810fec8 commit 674cba5
Show file tree
Hide file tree
Showing 13 changed files with 405 additions and 19 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 0.4.1

* Implement `generateEncryptionKey()` and `generateAsymmetricKeyPair()` helpers
* Update API client - prepare functions:
* to get Document signing parameters
* to register Device
* to register Device integration
* Limit `chopper` version and increase `json_annotation` version

## 0.4.0

* Allow dynamic "Encryption Key" value.
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ A Dart library that provides REST API client - [`IAutogramService`](lib/src/iaut

See [Swagger UI](https://generator3.swagger.io/index.html?url=https://autogram.slovensko.digital/openapi.yaml)

## Code generation
## Scripts

To generate code, run this command:
To generate code:

```shell
fvm dart run build_runner build --delete-conflicting-outputs
```

Run all tests:

```shell
fvm dart run test
```
1 change: 1 addition & 0 deletions lib/autogram_sign.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ library autogram_sign;
export 'generated/autogram.swagger.dart';
export 'src/autogram_authenticator.dart';
export 'src/autogram_service.dart';
export 'src/keys.dart';
export 'src/service_exception.dart';
22 changes: 22 additions & 0 deletions lib/generated/autogram.enums.swagger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@ enum GetDocumentResponseBodyMimeType {
const GetDocumentResponseBodyMimeType(this.value);
}

enum SignatureLevelResponseLevel {
@JsonValue(null)
swaggerGeneratedUnknown(null),

@JsonValue('PAdES_BASELINE_B')
padesBaselineB('PAdES_BASELINE_B'),
@JsonValue('PAdES_BASELINE_T')
padesBaselineT('PAdES_BASELINE_T'),
@JsonValue('XAdES_BASELINE_B')
xadesBaselineB('XAdES_BASELINE_B'),
@JsonValue('XAdES_BASELINE_T')
xadesBaselineT('XAdES_BASELINE_T'),
@JsonValue('CAdES_BASELINE_B')
cadesBaselineB('CAdES_BASELINE_B'),
@JsonValue('CAdES_BASELINE_T')
cadesBaselineT('CAdES_BASELINE_T');

final String? value;

const SignatureLevelResponseLevel(this.value);
}

enum SigningParametersLevel {
@JsonValue(null)
swaggerGeneratedUnknown(null),
Expand Down
18 changes: 18 additions & 0 deletions lib/generated/autogram.swagger.chopper.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

143 changes: 143 additions & 0 deletions lib/generated/autogram.swagger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,28 @@ abstract class Autogram extends ChopperService {
@Header('Accept') String? accept,
});

///Client app gets the signature parameters of the doucment
///@param guid
///@param Accept
Future<chopper.Response<SigningParameters>> documentsGuidParametersGet({
required String? guid,
String? accept,
}) {
generatedMapping.putIfAbsent(
SigningParameters, () => SigningParameters.fromJsonFactory);

return _documentsGuidParametersGet(guid: guid, accept: accept?.toString());
}

///Client app gets the signature parameters of the doucment
///@param guid
///@param Accept
@Get(path: '/documents/{guid}/parameters')
Future<chopper.Response<SigningParameters>> _documentsGuidParametersGet({
@Path('guid') required String? guid,
@Header('Accept') String? accept,
});

///Client app requests a signature validation report of the document.
///@param guid
///@param Accept
Expand Down Expand Up @@ -1384,6 +1406,54 @@ extension $DocumentExtension on Document {
}
}

@JsonSerializable(explicitToJson: true)
class SignatureLevelResponse {
const SignatureLevelResponse({
this.level,
});

factory SignatureLevelResponse.fromJson(Map<String, dynamic> json) =>
_$SignatureLevelResponseFromJson(json);

static const toJsonFactory = _$SignatureLevelResponseToJson;
Map<String, dynamic> toJson() => _$SignatureLevelResponseToJson(this);

@JsonKey(
name: 'level',
toJson: signatureLevelResponseLevelNullableToJson,
fromJson: signatureLevelResponseLevelNullableFromJson,
)
final enums.SignatureLevelResponseLevel? level;
static const fromJsonFactory = _$SignatureLevelResponseFromJson;

@override
bool operator ==(Object other) {
return identical(this, other) ||
(other is SignatureLevelResponse &&
(identical(other.level, level) ||
const DeepCollectionEquality().equals(other.level, level)));
}

@override
String toString() => jsonEncode(this);

@override
int get hashCode =>
const DeepCollectionEquality().hash(level) ^ runtimeType.hashCode;
}

extension $SignatureLevelResponseExtension on SignatureLevelResponse {
SignatureLevelResponse copyWith({enums.SignatureLevelResponseLevel? level}) {
return SignatureLevelResponse(level: level ?? this.level);
}

SignatureLevelResponse copyWithWrapped(
{Wrapped<enums.SignatureLevelResponseLevel?>? level}) {
return SignatureLevelResponse(
level: (level != null ? level.value : this.level));
}
}

@JsonSerializable(explicitToJson: true)
class SigningParameters {
const SigningParameters({
Expand Down Expand Up @@ -3562,6 +3632,79 @@ List<enums.GetDocumentResponseBodyMimeType>?
.toList();
}

String? signatureLevelResponseLevelNullableToJson(
enums.SignatureLevelResponseLevel? signatureLevelResponseLevel) {
return signatureLevelResponseLevel?.value;
}

String? signatureLevelResponseLevelToJson(
enums.SignatureLevelResponseLevel signatureLevelResponseLevel) {
return signatureLevelResponseLevel.value;
}

enums.SignatureLevelResponseLevel signatureLevelResponseLevelFromJson(
Object? signatureLevelResponseLevel, [
enums.SignatureLevelResponseLevel? defaultValue,
]) {
return enums.SignatureLevelResponseLevel.values
.firstWhereOrNull((e) => e.value == signatureLevelResponseLevel) ??
defaultValue ??
enums.SignatureLevelResponseLevel.swaggerGeneratedUnknown;
}

enums.SignatureLevelResponseLevel? signatureLevelResponseLevelNullableFromJson(
Object? signatureLevelResponseLevel, [
enums.SignatureLevelResponseLevel? defaultValue,
]) {
if (signatureLevelResponseLevel == null) {
return null;
}
return enums.SignatureLevelResponseLevel.values
.firstWhereOrNull((e) => e.value == signatureLevelResponseLevel) ??
defaultValue;
}

String signatureLevelResponseLevelExplodedListToJson(
List<enums.SignatureLevelResponseLevel>? signatureLevelResponseLevel) {
return signatureLevelResponseLevel?.map((e) => e.value!).join(',') ?? '';
}

List<String> signatureLevelResponseLevelListToJson(
List<enums.SignatureLevelResponseLevel>? signatureLevelResponseLevel) {
if (signatureLevelResponseLevel == null) {
return [];
}

return signatureLevelResponseLevel.map((e) => e.value!).toList();
}

List<enums.SignatureLevelResponseLevel> signatureLevelResponseLevelListFromJson(
List? signatureLevelResponseLevel, [
List<enums.SignatureLevelResponseLevel>? defaultValue,
]) {
if (signatureLevelResponseLevel == null) {
return defaultValue ?? [];
}

return signatureLevelResponseLevel
.map((e) => signatureLevelResponseLevelFromJson(e.toString()))
.toList();
}

List<enums.SignatureLevelResponseLevel>?
signatureLevelResponseLevelNullableListFromJson(
List? signatureLevelResponseLevel, [
List<enums.SignatureLevelResponseLevel>? defaultValue,
]) {
if (signatureLevelResponseLevel == null) {
return defaultValue;
}

return signatureLevelResponseLevel
.map((e) => signatureLevelResponseLevelFromJson(e.toString()))
.toList();
}

String? signingParametersLevelNullableToJson(
enums.SigningParametersLevel? signingParametersLevel) {
return signingParametersLevel?.value;
Expand Down
20 changes: 16 additions & 4 deletions lib/generated/autogram.swagger.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 33 additions & 1 deletion lib/src/autogram_service.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:intl/intl.dart';

import '../generated/autogram.swagger.dart';
Expand Down Expand Up @@ -35,6 +37,13 @@ class AutogramService implements IAutogramService {
.then((value) => value.guid);
}

@override
Future<SigningParameters> getDocumentParameters(
String documentId,
) {
return _autogram.documentsGuidParametersGet(guid: documentId).then(unwrap);
}

@override
Future<void> deleteDocument(
String documentId,
Expand Down Expand Up @@ -97,10 +106,33 @@ class AutogramService implements IAutogramService {
}

@override
Future<PostDeviceResponse> registerDevice(PostDeviceRequestBody body) {
Future<PostDeviceResponse> registerDevice({
required String registrationId,
required String displayName,
}) {
// TODO Get public key
final body = PostDeviceRequestBody(
platform: Platform.operatingSystem,
registrationId: registrationId,
displayName: displayName,
publicKey: "",
);

return _autogram.devicesPost(body: body).then(unwrap);
}

@override
Future<void> registerDeviceIntegration(
String integrationPairingToken,
) {
// TODO Set JWT in header
final body = PostDeviceIntegrationsRequestBody(
integrationPairingToken: integrationPairingToken,
);

return _autogram.deviceIntegrationsPost(body: body).then(unwrap);
}

@override
Future<GetDeviceIntegrationsResponseBody> listIntegrations() {
return _autogram.deviceIntegrationsGet().then(unwrap);
Expand Down
19 changes: 18 additions & 1 deletion lib/src/iautogram_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ abstract class IAutogramService {
DocumentPostRequestBody body,
);

/// Gets the signature parameters of the document.
///
/// See <https://generator3.swagger.io/index.html?url=https://autogram.slovensko.digital/openapi.yaml#/Desktop2App%20-%20Client/get_documents__guid__parameters>
Future<SigningParameters> getDocumentParameters(
String documentId,
);

/// Deletes existing Document by its [documentId].
///
/// See <https://generator3.swagger.io/index.html?url=https://autogram.slovensko.digital/openapi.yaml#/Desktop2App%20-%20Extension/delete_documents__guid_>
Expand Down Expand Up @@ -58,7 +65,17 @@ abstract class IAutogramService {
/// Registers itself at the server.
///
/// See: <https://generator3.swagger.io/index.html?url=https://autogram.slovensko.digital/openapi.yaml#/Minimal%20Integration/post_devices>
Future<PostDeviceResponse> registerDevice(PostDeviceRequestBody body);
Future<PostDeviceResponse> registerDevice({
required String registrationId,
required String displayName,
});

/// Registers itself for receiving sign requests (push notification) from given integration
///
/// See: <https://generator3.swagger.io/index.html?url=https://autogram.slovensko.digital/openapi.yaml#/Minimal%20Integration/post_device_integrations>
Future<void> registerDeviceIntegration(
String integrationPairingToken,
);

/// Retrieves a list of paired integrations.
///
Expand Down
Loading

0 comments on commit 674cba5

Please sign in to comment.