-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[TS-SDK v2] Updating the Deserializable interface and making Serializable an abstract class
#10307
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
Changes from all commits
0a3e782
9809948
d6955c4
7a7a1f4
892b770
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,14 @@ | ||
| // Copyright © Aptos Foundation | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { Deserializable, Deserializer, Serializable, Serializer } from "../bcs"; | ||
| import { Serializable, Serializer } from "../bcs"; | ||
| import { HexInput } from "../types"; | ||
|
|
||
| /** | ||
| * An abstract representation of a public key. All Asymmetric key pairs will use this to | ||
| * verify signatures and for authentication keys. | ||
| */ | ||
| export abstract class PublicKey implements Serializable, Deserializable<PublicKey> { | ||
| export abstract class PublicKey extends Serializable { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see! In this case, the implementation of the method I wonder if theres a way to just implement the deserialize method directly in abstract/base class. Then all child classes will auto inherit it
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I looked into it and there's apparently a lot of hullabaloo about static methods in abstract classes, so the support there, particularly with typescript, is lacking. I tried a few different methods to achieve a WRT what you're saying though, the problem with implementing the deserialize method in the base class (say, as an abstract factory) is that it must know ahead of time how to create the child classes. I don't know if this would be a problem, it depends on how we plan on implementing these abstract classes later. For example here is the export abstract class TransactionAuthenticator {
abstract serialize(serializer: Serializer): void;
static deserialize(deserializer: Deserializer): TransactionAuthenticator {
const index = deserializer.deserializeUleb128AsU32();
switch (index) {
case 0:
return TransactionAuthenticatorEd25519.load(deserializer);
case 1:
return TransactionAuthenticatorMultiEd25519.load(deserializer);
case 2:
return TransactionAuthenticatorMultiAgent.load(deserializer);
case 3:
return TransactionAuthenticatorFeePayer.load(deserializer);
default:
throw new Error(`Unknown variant index for TransactionAuthenticator: ${index}`);
}
}
}But with this, the child classes actually don't even implement deserialize, they specifically have a The other part to this is that these are specifically With the |
||
| /** | ||
| * Verifies that the private key associated with this public key signed the message with the given signature. | ||
| * @param args | ||
|
|
@@ -25,17 +25,14 @@ export abstract class PublicKey implements Serializable, Deserializable<PublicKe | |
| */ | ||
| abstract toString(): string; | ||
|
|
||
| // TODO: This should be a static method. | ||
| abstract deserialize(deserializer: Deserializer): PublicKey; | ||
|
|
||
| abstract serialize(serializer: Serializer): void; | ||
| } | ||
|
|
||
| /** | ||
| * An abstract representation of a private key. This is used to sign transactions and | ||
| * derive the public key associated. | ||
| */ | ||
| export abstract class PrivateKey implements Serializable, Deserializable<PrivateKey> { | ||
| export abstract class PrivateKey extends Serializable { | ||
| /** | ||
| * Sign a message with the key | ||
| * @param args | ||
|
|
@@ -52,9 +49,6 @@ export abstract class PrivateKey implements Serializable, Deserializable<Private | |
| */ | ||
| abstract toString(): string; | ||
|
|
||
| // TODO: This should be a static method. | ||
| abstract deserialize(deserializer: Deserializer): PrivateKey; | ||
|
|
||
| abstract serialize(serializer: Serializer): void; | ||
|
|
||
| /** | ||
|
|
@@ -67,7 +61,7 @@ export abstract class PrivateKey implements Serializable, Deserializable<Private | |
| * An abstract representation of a signature. This is the product of signing a | ||
| * message and can be used with the PublicKey to verify the signature. | ||
| */ | ||
| export abstract class Signature implements Serializable, Deserializable<Signature> { | ||
| export abstract class Signature extends Serializable { | ||
| /** | ||
| * Get the raw signature bytes | ||
| */ | ||
|
|
@@ -78,8 +72,5 @@ export abstract class Signature implements Serializable, Deserializable<Signatur | |
| */ | ||
| abstract toString(): string; | ||
|
|
||
| // TODO: This should be a static method. | ||
| abstract deserialize(deserializer: Deserializer): Signature; | ||
|
|
||
| abstract serialize(serializer: Serializer): void; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.