[experimental] Figure out how to write an assertion function for fully signed transactions while TypeScript does not support async assertions and typeguards
See https://github.com/microsoft/TypeScript/issues/37681#issuecomment-1650605236.
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:
- We could write an
assertIsFullySignedTransaction()function that just checks to see if there is a signature for each signer, without actually performing any verification - We could break from the existing pattern of
assertFoo/isFooand make a function that both asserts and returns the transaction with theIFullySignedTransactiontype added.
Neither of these are great, and both are really hard to take back (ie. deprecate) once we've released them.
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.
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.
assertIsFullyButPossiblyBadlySignedTransaction()
Because there has been no activity on this issue for 7 days since it was closed, it has been automatically locked. Please open a new issue if it requires a follow up.