From 8282cbf66c197e2dbc68409e642acf6343d91323 Mon Sep 17 00:00:00 2001 From: Dominik Toton Date: Wed, 31 Jul 2024 10:24:14 +0200 Subject: [PATCH] fix!: signData return type should be DataSignature, not VkeyWitness --- .../example/lib/sign_data.dart | 10 +++++----- .../lib/src/cardano_wallet.dart | 20 ++++++++++++++++++- .../src/interop/catalyst_cardano_interop.dart | 20 ++++++++++++++++++- .../catalyst_cardano_wallet_proxy.dart | 6 +++--- 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/catalyst_voices_packages/catalyst_cardano/catalyst_cardano/example/lib/sign_data.dart b/catalyst_voices_packages/catalyst_cardano/catalyst_cardano/example/lib/sign_data.dart index 0b77b45522c..c2464f4e69c 100644 --- a/catalyst_voices_packages/catalyst_cardano/catalyst_cardano/example/lib/sign_data.dart +++ b/catalyst_voices_packages/catalyst_cardano/catalyst_cardano/example/lib/sign_data.dart @@ -7,13 +7,13 @@ Future _signData({ var result = ''; try { - final rewardAddress = await api.getRewardAddresses(); - final signer = await api.signData( - address: rewardAddress.first, - payload: [1, 2, 3], + final addresses = await api.getUsedAddresses(); + final signature = await api.signData( + address: addresses.first, + payload: 'hello world!'.codeUnits, ); - result = 'Signature: ${hex.encode(cbor.encode(signer.toCbor()))}'; + result = 'Signature: $signature'; } catch (error) { result = error.toString(); } diff --git a/catalyst_voices_packages/catalyst_cardano/catalyst_cardano_platform_interface/lib/src/cardano_wallet.dart b/catalyst_voices_packages/catalyst_cardano/catalyst_cardano_platform_interface/lib/src/cardano_wallet.dart index 6a69c21fe96..7e5aeaa854b 100644 --- a/catalyst_voices_packages/catalyst_cardano/catalyst_cardano_platform_interface/lib/src/cardano_wallet.dart +++ b/catalyst_voices_packages/catalyst_cardano/catalyst_cardano_platform_interface/lib/src/cardano_wallet.dart @@ -130,7 +130,7 @@ abstract interface class CardanoWalletApi { /// reward addresses. /// /// Throws [WalletDataSignException]. - Future signData({ + Future signData({ required ShelleyAddress address, required List payload, }); @@ -243,3 +243,21 @@ final class Paginate extends Equatable { @override List get props => [page, limit]; } + +/// The data signature as returned by CIP-30 signData. +final class DataSignature extends Equatable { + /// The public key. + final String key; + + /// The signature. + final String signature; + + /// The default constructor for [DataSignature]. + const DataSignature({ + required this.key, + required this.signature, + }); + + @override + List get props => [key, signature]; +} diff --git a/catalyst_voices_packages/catalyst_cardano/catalyst_cardano_web/lib/src/interop/catalyst_cardano_interop.dart b/catalyst_voices_packages/catalyst_cardano/catalyst_cardano_web/lib/src/interop/catalyst_cardano_interop.dart index 742fe793b94..835fceff1d9 100644 --- a/catalyst_voices_packages/catalyst_cardano/catalyst_cardano_web/lib/src/interop/catalyst_cardano_interop.dart +++ b/catalyst_voices_packages/catalyst_cardano/catalyst_cardano_web/lib/src/interop/catalyst_cardano_interop.dart @@ -79,7 +79,7 @@ extension type JSCardanoWalletApi(JSObject _) implements JSObject { ]); /// See [CardanoWalletApi.signData]. - external JSPromise signData( + external JSPromise signData( JSString address, JSString payload, ); @@ -174,3 +174,21 @@ extension type JSPaginate._(JSObject _) implements JSObject { /// See [JSPaginate.limit]. external JSNumber get limit; } + +/// The JS representation of the [DataSignature]. +extension type JSDataSignature._(JSObject _) implements JSObject { + /// The default constructor for [JSDataSignature]. + external factory JSDataSignature({JSString key, JSString signature}); + + /// See [DataSignature.key]. + external JSString get key; + + /// See [DataSignature.signature]. + external JSString get signature; + + /// Converts JS representation to pure dart representation. + DataSignature get toDart => DataSignature( + key: key.toDart, + signature: signature.toDart, + ); +} diff --git a/catalyst_voices_packages/catalyst_cardano/catalyst_cardano_web/lib/src/interop/catalyst_cardano_wallet_proxy.dart b/catalyst_voices_packages/catalyst_cardano/catalyst_cardano_web/lib/src/interop/catalyst_cardano_wallet_proxy.dart index c09ae6b56a2..ce14d5775c2 100644 --- a/catalyst_voices_packages/catalyst_cardano/catalyst_cardano_web/lib/src/interop/catalyst_cardano_wallet_proxy.dart +++ b/catalyst_voices_packages/catalyst_cardano/catalyst_cardano_web/lib/src/interop/catalyst_cardano_wallet_proxy.dart @@ -201,18 +201,18 @@ class JSCardanoWalletApiProxy implements CardanoWalletApi { } @override - Future signData({ + Future signData({ required ShelleyAddress address, required List payload, }) async { try { return await _delegate .signData( - hex.encode(cbor.encode(address.toCbor())).toJS, + address.toBech32().toJS, hex.encode(payload).toJS, ) .toDart - .then((e) => VkeyWitness.fromCbor(cbor.decode(hex.decode(e.toDart)))); + .then((e) => e.toDart); } catch (ex) { throw _mapApiException(ex) ?? _mapDataSignException(ex) ??