Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: signData return type should be DataSignature, not VkeyWitness #647

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ Future<void> _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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ abstract interface class CardanoWalletApi {
/// reward addresses.
///
/// Throws [WalletDataSignException].
Future<VkeyWitness> signData({
Future<DataSignature> signData({
required ShelleyAddress address,
required List<int> payload,
});
Expand Down Expand Up @@ -243,3 +243,21 @@ final class Paginate extends Equatable {
@override
List<Object?> 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<Object?> get props => [key, signature];
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ extension type JSCardanoWalletApi(JSObject _) implements JSObject {
]);

/// See [CardanoWalletApi.signData].
external JSPromise<JSString> signData(
external JSPromise<JSDataSignature> signData(
JSString address,
JSString payload,
);
Expand Down Expand Up @@ -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,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,18 @@ class JSCardanoWalletApiProxy implements CardanoWalletApi {
}

@override
Future<VkeyWitness> signData({
Future<DataSignature> signData({
required ShelleyAddress address,
required List<int> 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) ??
Expand Down
Loading