Skip to content

Commit

Permalink
improve public key getter
Browse files Browse the repository at this point in the history
  • Loading branch information
justkawal committed Dec 14, 2023
1 parent 442f3bb commit 16ee314
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/polkadart_keyring/lib/polkadart_keyring.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ part 'src/extensions.dart';
part 'src/ed25519.dart';
part 'src/sr25519.dart';
part 'src/constants.dart';
part 'src/public_key.dart';
2 changes: 1 addition & 1 deletion packages/polkadart_keyring/lib/src/ed25519.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Ed25519KeyPair extends KeyPair {
}

@override
ed.PublicKey get publicKey => _publicKey;
PublicKey get publicKey => PublicKey(_publicKey.bytes);

@override
void lock() {
Expand Down
2 changes: 1 addition & 1 deletion packages/polkadart_keyring/lib/src/keypair.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ abstract class KeyPair {
/// final keyPair = KeyPair.sr25519.fromSeed(seed); // Replace with your actual seed
/// print('Public Key: ${keyPair.publicKey}');
/// ```
dynamic get publicKey;
PublicKey get publicKey;

///
///
Expand Down
9 changes: 9 additions & 0 deletions packages/polkadart_keyring/lib/src/public_key.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
part of polkadart_keyring;

class PublicKey {
final List<int> _bytes;
const PublicKey(this._bytes);

/// Returns the bytes of the public key
List<int> get bytes => List<int>.from(_bytes);
}
2 changes: 1 addition & 1 deletion packages/polkadart_keyring/lib/src/sr25519.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class Sr25519KeyPair extends KeyPair {
}

@override
sr25519.PublicKey get publicKey => _publicKey;
PublicKey get publicKey => PublicKey(_publicKey.encode());

@override
Uint8List sign(Uint8List message) {
Expand Down
2 changes: 1 addition & 1 deletion packages/polkadart_keyring/test/suri_sr25519_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void main() {
for (final (seed, address, uri) in testVectors) {
final keypair = await KeyPair.sr25519.fromUri(uri);
expect(keypair.address, address);
expect('0x${hex.encode(keypair.publicKey.encode())}', seed);
expect('0x${hex.encode(keypair.publicKey.bytes)}', seed);
}
});
});
Expand Down

0 comments on commit 16ee314

Please sign in to comment.