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

[experimental] Figure out how to write an assertion function for fully signed transactions while TypeScript does not support async assertions and typeguards #1773

Open
steveluscher opened this issue Oct 24, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@steveluscher
Copy link
Collaborator

steveluscher commented Oct 24, 2023

See microsoft/TypeScript#37681 (comment).

Essentially you can write an assertion function (playground)…

type NumberLessThanTen = number & { readonly brand: unique symbol }; 

function assertIsLessThan10(num: number): asserts num is NumberLessThanTen {
  if (num >= 10) {
    throw new Error('Too big');
  }
}
const num = 9;
assertIsLessThan10(num);
num satisfies NumberLessThanTen;

…but as soon as you make that assertion function async it stops working.

Options:

  1. We could write an assertIsFullySignedTransaction() function that just checks to see if there is a signature for each signer, without actually performing any verification
  2. We could break from the existing pattern of assertFoo/isFoo and make a function that both asserts and returns the transaction with the IFullySignedTransaction type added.

Neither of these are great, and both are really hard to take back (ie. deprecate) once we've released them.

@steveluscher steveluscher added the enhancement New feature or request label Oct 24, 2023
@lorisleiva
Copy link
Collaborator

I'd argue we don't need this assert method to be async in the first place. Since the goal is the ensure it is "fully signed", we just need to go through the account metas that are required to sign, deduplicate the addresses and ensure the amount of unique signers required matches the amount of signatures in the transaction.

I'm assuming the async part would be to also verify each of these signatures match the expected set of signers but IMO that's a bit overkill when all we want is ensure we've not missed one signature.

@mcintyre94
Copy link
Collaborator

mcintyre94 commented Oct 24, 2023

Agreed. I think it'd be okay to have the type assertion just assert there's a signature for each expected signer, and then optionally to have a separate function(s) that asserts/checks signature validity without changing the type.

Arguably those are separate operations anyway, eg you might want to check the validity of the current signatures on a partially signed transaction.

@steveluscher
Copy link
Collaborator Author

assertIsFullyButPossiblyBadlySignedTransaction()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants