Skip to content

Commit

Permalink
feat!: COSE_SIGN1 signatures and verification (#669)
Browse files Browse the repository at this point in the history
* feat: add catalyst_cose plugin structure

* chore: docs how to contribute to JS layer from catalyst_cose, ignore generated files from linter

* chore: update license

* docs: spelling

* feat: update sample cert

* chore!: remove federated plugin structure from catalyst_cose

* refactor!: prevent extending plugin classes

* feat: implement COSE_SIGN1 signatures and verification

* chore: make tests repeatable

* docs: markdown fixes

* refactor: lints

* feat: add kid

* chore: add tests validating cose_sign1 is a valid cbor
  • Loading branch information
dtscalac authored Aug 12, 2024
1 parent f83462c commit f5a910e
Show file tree
Hide file tree
Showing 41 changed files with 412 additions and 42,864 deletions.
3 changes: 2 additions & 1 deletion .config/dictionaries/project.dic
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,5 @@ xcworkspace
yoroi
unchunk
EUTXO
toggleable
eddsa
toggleable
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ E61E8EE7D77E9F7F9804E03EBC31B458

final _c509Cert = C509Certificate.fromHex(
'''
8B004301F50D6B524643207465737420
004301F50D6B524643207465737420
43411A63B0CD001A6955B90047010123
456789AB01582102B1216AB96E5B3B33
40F5BDF02E693F16213A04525ED44450
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:catalyst_cardano_platform_interface/catalyst_cardano_platform_in

/// A Flutter plugin exposing the [CIP-30](https://cips.cardano.org/cip/CIP-30)
/// and [CIP-95](https://cips.cardano.org/cip/CIP-95) APIs.
class CatalystCardano {
final class CatalystCardano {
/// The default instance of [CatalystCardano] to use.
static final CatalystCardano instance = CatalystCardano._();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:flutter_web_plugins/flutter_web_plugins.dart' show Registrar;
///
/// This class implements the `package:catalyst_cardano` functionality
/// for the web.
class CatalystCardanoWeb extends CatalystCardanoPlatform {
final class CatalystCardanoWeb extends CatalystCardanoPlatform {
/// A constructor that allows tests to override the window object used by the
/// plugin.
CatalystCardanoWeb();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:catalyst_compression/catalyst_compression.dart';
import 'package:catalyst_compression_platform_interface/catalyst_compression_platform_interface.dart';

/// A Flutter plugin exposing brotli and zstd compression/decompression algorithms.
class CatalystCompression {
final class CatalystCompression {
/// The default instance of [CatalystCompression] to use.
static final CatalystCompression instance = CatalystCompression._();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:flutter_web_plugins/flutter_web_plugins.dart' show Registrar;
///
/// This class implements the `package:catalyst_compression` functionality
/// for the web.
class CatalystCompressionWeb extends CatalystCompressionPlatform {
final class CatalystCompressionWeb extends CatalystCompressionPlatform {
/// A constructor that allows tests to override the window object used by the
/// plugin.
CatalystCompressionWeb();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* [Features](#features)
* [Requirements](#requirements)
* [Install](#install)
* [Web setup](#web-setup)
* [Example](#example)
* [Limitations](#limitations)
* [Support](#support)
Expand All @@ -13,52 +12,75 @@
## Features

This package exposes a CBOR Object Signing and Encryption
[RFC-8152](https://datatracker.ietf.org/doc/html/rfc8152) implementation of cose-js npm module.

* [cose-js](https://www.npmjs.com/package/cose-js)
[RFC-9052](https://datatracker.ietf.org/doc/html/rfc9052),
[RFC-9053](https://datatracker.ietf.org/doc/html/rfc9053) implementation.

## Requirements

* Dart: 3.3.4+
* Flutter: 3.22.1+

## Install

```yaml
dependencies:
catalyst_cose: any # or the latest version on Pub
catalyst_cose_web: any # or the latest version on Pub
```
## Web setup
Add the following line at the end of `<head>` section in web/index.html:

```html
<script type="module" src="/assets/packages/catalyst_cose_web/assets/js/catalyst_cose.js"></script>
```
## Example
```dart
// ignore_for_file: avoid_print

import 'dart:convert';

import 'package:catalyst_cose/catalyst_cose.dart';
import 'package:cbor/cbor.dart';
import 'package:convert/convert.dart';
import 'package:cryptography/cryptography.dart';

Future<void> main() async {
final message = hex.decode(
'6c1382765aec5358f117733d281c1c7bdc39884d04a45a1e6c67c858bc206c19',
final algorithm = Ed25519();
final keyPair = await algorithm.newKeyPairFromSeed(List.filled(32, 0));
final privateKey = await keyPair.extractPrivateKeyBytes();
final publicKey = await keyPair.extractPublicKey().then((e) => e.bytes);

final payload = utf8.encode('This is the content.');

final coseSign1 = await CatalystCose.sign1(
privateKey: privateKey,
payload: payload,
kid: CborBytes(publicKey),
);

final coseSignature = await CatalystCose.instance.signMessage(message);
print(coseSignature);
final verified = await CatalystCose.verifyCoseSign1(
coseSign1: coseSign1,
publicKey: publicKey,
);

print('COSE_SIGN1:');
print(hex.encode(cbor.encode(coseSign1)));
print('verified: $verified');

assert(
verified,
'The signature proves that given COSE_SIGN1 structure has been '
'signed by the owner of the given public key',
);
}
```

## Limitations

This package supports only web platform at the moment but it's intended that other platforms are supported in the future.
This package supports only a subset of COSE features and algorithms.
More features and algorithms are supposed to be added in the feature.

Supported features:

* COSE_SIGN_1: signature + verification

Supported algorithms:

* EdDSA: Ed25519

## Support

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

31 changes: 0 additions & 31 deletions catalyst_voices_packages/catalyst_cose/catalyst_cose/pubspec.yaml

This file was deleted.

This file was deleted.

Loading

0 comments on commit f5a910e

Please sign in to comment.