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

Introduce Single Sender transaction authenticator #84

Merged
merged 10 commits into from
Oct 25, 2023
Merged

Introduce Single Sender transaction authenticator #84

merged 10 commits into from
Oct 25, 2023

Conversation

0xmaayan
Copy link
Collaborator

@0xmaayan 0xmaayan commented Oct 17, 2023

Description

This PR adds support to the new Single Sender introduced in AIP-55
We mostly have things represented in a way that reflects the rust code.

We introduce 2 new modules

  • AnyPublicKey that holds a reference to a PublicKey, we use it to represent any Single Sender key.
  • AnySignature that holds a reference to a Signature, we use it to represent any Single Sender signature.

When generating new keys (i.e creating an Account) we default to generate the new keys as SingleSigner but also support an optional legacy argument to generate keys based on the legacy ED25519 scheme.

When want to get the account from an existing and known private key, i.e await aptos.deriveAccountFromPrivateKey, we derive the public and auth keys from the provided private key and then generating an Account based on the Account configured signing scheme - Legacy ED25519 or Single Sender. Note that this function is now an async function since we need to make api calls to chain.

The transaction builder resolves to the correct signing scheme.

  • When a single signer transaction is being simulated, it checks for the provided public key instance, if it is an instance of AnyPublicKey we create a AccountAuthenticatorSingleKey based on the PublicKey the class holds reference to.
  • When a single signer transaction is being signed, it checks for the account signing scheme and, if it is SingleKey we create a AccountAuthenticatorSingleKey based on the PublicKey the account uses.
  • When a single signer transaction is being submitted, it checks for the provided account authenticator, if it is an instance of a SingleKeyAuthenticator we create a SingleSenderTransactionAuthenticator to create a SignedTransaction with.

Also not, we remove fromPrivateKeyAndAddress static method as fromPrivateKey basically does it now

Test Plan

Indexer doesnt support the new Single Sender yet, so tests are breaking. Was able to successfully run it locally without indexer

 PASS  tests/e2e/transaction/transactionSimulation.test.ts (8.032 s)
 PASS  tests/e2e/transaction/transactionArguments.test.ts (10.768 s)
 PASS  tests/e2e/transaction/generateTransaction.test.ts
 PASS  tests/e2e/transaction/signTransaction.test.ts (5.155 s)
 PASS  tests/e2e/transaction/transactionBuilder.test.ts (15.517 s)
 PASS  tests/e2e/transaction/transactionSubmission.test.ts (17.563 s)

Related Links

AIP-55

src/core/crypto/ed25519.ts Outdated Show resolved Hide resolved
src/core/crypto/ed25519.ts Outdated Show resolved Hide resolved
src/core/crypto/ed25519.ts Outdated Show resolved Hide resolved
src/core/crypto/ed25519.ts Outdated Show resolved Hide resolved
src/core/account.ts Outdated Show resolved Hide resolved
@0xmaayan 0xmaayan marked this pull request as ready for review October 20, 2023 17:50
@0xmaayan 0xmaayan changed the title secpk Introduce Single Sender transaction authenticator Oct 20, 2023
src/api/transaction.ts Outdated Show resolved Hide resolved
src/core/account.ts Show resolved Hide resolved
src/core/account.ts Outdated Show resolved Hide resolved
src/core/account.ts Outdated Show resolved Hide resolved
src/core/account.ts Outdated Show resolved Hide resolved
src/core/authenticationKey.ts Outdated Show resolved Hide resolved
src/core/authenticationKey.ts Outdated Show resolved Hide resolved
src/core/crypto/anyPublicKey.ts Outdated Show resolved Hide resolved
src/core/crypto/singleKey.ts Outdated Show resolved Hide resolved
src/core/crypto/singleKey.ts Outdated Show resolved Hide resolved
src/internal/transaction.ts Outdated Show resolved Hide resolved
src/core/account.ts Show resolved Hide resolved
src/core/account.ts Show resolved Hide resolved
src/api/account.ts Outdated Show resolved Hide resolved
src/core/account.ts Outdated Show resolved Hide resolved
src/core/account.ts Outdated Show resolved Hide resolved
@0xmaayan 0xmaayan merged commit ffce986 into main Oct 25, 2023
4 checks passed
@0xmaayan 0xmaayan deleted the secpk branch October 25, 2023 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants