Skip to content

Commit 1127fdd

Browse files
authored
feat(cat-voices): enable browser crypto api in wasm (#3640)
* chore: enable browser crypto api in wasm * chore: use official dart cryptography * chore: workaround for browser crypto api * chore: docs
1 parent bd6230a commit 1127fdd

File tree

13 files changed

+48
-15
lines changed

13 files changed

+48
-15
lines changed

catalyst_voices/packages/internal/catalyst_voices_shared/lib/src/crypto/local_crypto_service.dart

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import 'dart:math';
33

44
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
55
import 'package:catalyst_voices_shared/catalyst_voices_shared.dart';
6-
import 'package:cryptography/cryptography.dart';
6+
import 'package:cryptography_plus/cryptography_plus.dart';
7+
// TODO(dt-iohk): It will no longer be necessary to import this after that PR is merged:
8+
// https://github.com/emz-hanauer/dart-cryptography/pull/17
9+
// ignore: implementation_imports
10+
import 'package:cryptography_plus/src/browser/browser_cryptography_when_not_browser.dart'
11+
if (dart.library.js_interop) 'package:cryptography_plus/src/browser/browser_cryptography.dart'
12+
as br;
713
import 'package:flutter/foundation.dart';
814

915
final _logger = Logger('LocalCryptoService');
@@ -19,6 +25,9 @@ final _logger = Logger('LocalCryptoService');
1925
///
2026
/// Supports version for future changes.
2127
final class LocalCryptoService implements CryptoService {
28+
/// The length for the aes secret in bytes.
29+
static const int _aesSecretLength = 32;
30+
2231
/// Salt length for key derivation.
2332
static const int _saltLength = 16;
2433

@@ -63,7 +72,8 @@ final class LocalCryptoService implements CryptoService {
6372
throw CryptoAlgorithmUnsupported('Algorithm $version');
6473
}
6574

66-
final algorithm = AesGcm.with256bits();
75+
// ignore: avoid_redundant_argument_values
76+
final algorithm = br.BrowserCryptography().aesGcm(secretKeyLength: _aesSecretLength);
6777
final secretKey = SecretKey(key.sublist(_saltLength));
6878

6979
final encryptedData = data.sublist(2);
@@ -146,7 +156,8 @@ final class LocalCryptoService implements CryptoService {
146156
required Uint8List key,
147157
}) {
148158
Future<Uint8List> run() async {
149-
final algorithm = AesGcm.with256bits();
159+
// ignore: avoid_redundant_argument_values
160+
final algorithm = br.BrowserCryptography().aesGcm(secretKeyLength: _aesSecretLength);
150161
final secretKey = SecretKey(key.sublist(_saltLength));
151162

152163
final checksum = _checksum;

catalyst_voices/packages/internal/catalyst_voices_shared/pubspec.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ dependencies:
1515
path: ../catalyst_voices_models
1616
collection: ^1.19.1
1717
convert: ^3.1.2
18-
cryptography: ^2.7.0
18+
# TODO(dt-iohk): revert to pub.dev version once this is merged and released: https://github.com/emz-hanauer/dart-cryptography/pull/17
19+
cryptography_plus:
20+
git:
21+
url: https://github.com/emz-hanauer/dart-cryptography
22+
ref: 2eae39aa0f469cf065e67b760c9493b2628d3f8e
23+
path: cryptography/
1924
equatable: ^2.0.7
2025
fake_async: ^1.3.3
2126
flutter:

catalyst_voices/packages/libs/catalyst_cardano_serialization/lib/src/signature.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'package:catalyst_cardano_serialization/src/types.dart';
22
import 'package:catalyst_cardano_serialization/src/utils/hex.dart';
33
import 'package:cbor/cbor.dart';
44
import 'package:convert/convert.dart';
5-
import 'package:cryptography/cryptography.dart';
5+
import 'package:cryptography_plus/cryptography_plus.dart';
66
import 'package:equatable/equatable.dart';
77

88
/// The public and private Ed25519 key pair.

catalyst_voices/packages/libs/catalyst_cardano_serialization/pubspec.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ issue_tracker: https://github.com/input-output-hk/catalyst-voices/issues
55
topics: [blockchain, cardano, cryptocurrency, wallet]
66
version: 1.0.0
77
resolution: workspace
8+
publish_to: none
89

910
environment:
1011
sdk: ">=3.9.0 <4.0.0"
@@ -19,7 +20,12 @@ dependencies:
1920
cbor: 6.3.7
2021
collection: ^1.19.1
2122
convert: ^3.1.2
22-
cryptography: ^2.7.0
23+
# TODO(dt-iohk): revert to pub.dev version once this is merged and released: https://github.com/emz-hanauer/dart-cryptography/pull/17
24+
cryptography_plus:
25+
git:
26+
url: https://github.com/emz-hanauer/dart-cryptography
27+
ref: 2eae39aa0f469cf065e67b760c9493b2628d3f8e
28+
path: cryptography/
2329
equatable: ^2.0.7
2430
logging: ^1.3.0
2531
meta: ^1.16.0

catalyst_voices/packages/libs/catalyst_cose/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import 'dart:typed_data';
3737
import 'package:catalyst_cose/catalyst_cose.dart';
3838
import 'package:cbor/cbor.dart';
3939
import 'package:convert/convert.dart';
40-
import 'package:cryptography/cryptography.dart';
40+
import 'package:cryptography_plus/cryptography_plus.dart';
4141

4242
Future<void> main() async {
4343
await _coseSign1();

catalyst_voices/packages/libs/catalyst_cose/example/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'dart:typed_data';
66
import 'package:catalyst_cose/catalyst_cose.dart';
77
import 'package:cbor/cbor.dart';
88
import 'package:convert/convert.dart';
9-
import 'package:cryptography/cryptography.dart';
9+
import 'package:cryptography_plus/cryptography_plus.dart';
1010

1111
Future<void> main() async {
1212
await _coseSign1();

catalyst_voices/packages/libs/catalyst_cose/pubspec.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ issue_tracker: https://github.com/input-output-hk/catalyst-voices/issues
55
topics: [cryptography, encryption, codec]
66
version: 1.0.0
77
resolution: workspace
8+
publish_to: none
89

910
environment:
1011
sdk: ">=3.9.0 <4.0.0"
@@ -13,7 +14,12 @@ dependencies:
1314
cbor: 6.3.7
1415
collection: ^1.19.1
1516
convert: ^3.1.2
16-
cryptography: ^2.7.0
17+
# TODO(dt-iohk): revert to pub.dev version once this is merged and released: https://github.com/emz-hanauer/dart-cryptography/pull/17
18+
cryptography_plus:
19+
git:
20+
url: https://github.com/emz-hanauer/dart-cryptography
21+
ref: 2eae39aa0f469cf065e67b760c9493b2628d3f8e
22+
path: cryptography/
1723
equatable: ^2.0.7
1824
uuid_plus: ^0.1.0
1925

catalyst_voices/packages/libs/catalyst_cose/test/cose_sign1_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'dart:convert';
22
import 'dart:typed_data';
33

44
import 'package:catalyst_cose/catalyst_cose.dart';
5-
import 'package:cryptography/cryptography.dart';
5+
import 'package:cryptography_plus/cryptography_plus.dart';
66
import 'package:test/test.dart';
77

88
void main() {

catalyst_voices/packages/libs/catalyst_cose/test/cose_sign_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'dart:convert';
22
import 'dart:typed_data';
33

44
import 'package:catalyst_cose/catalyst_cose.dart';
5-
import 'package:cryptography/cryptography.dart';
5+
import 'package:cryptography_plus/cryptography_plus.dart';
66
import 'package:test/test.dart';
77

88
void main() {

catalyst_voices/packages/libs/catalyst_key_derivation/lib/src/ed25519/ed25519_key_pair.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:catalyst_key_derivation/src/ed25519/ed25519_private_key.dart';
22
import 'package:catalyst_key_derivation/src/ed25519/ed25519_public_key.dart';
3-
import 'package:cryptography/cryptography.dart';
3+
import 'package:cryptography_plus/cryptography_plus.dart';
44
import 'package:equatable/equatable.dart';
55

66
/// The public and private Ed25519 key pair.

0 commit comments

Comments
 (0)