Skip to content

Migrated transaction.js file to TS#924

Merged
quietbits merged 1 commit intotypescript-migrationfrom
tsm-transaction
Mar 10, 2026
Merged

Migrated transaction.js file to TS#924
quietbits merged 1 commit intotypescript-migrationfrom
tsm-transaction

Conversation

@quietbits
Copy link
Contributor

Tests will be updated in a separate PR because they need TransactionBuilder: #923

@quietbits quietbits linked an issue Mar 10, 2026 that may be closed by this pull request
5 tasks
Comment on lines +44 to +47
// TODO: types/index.d.ts declares this as `number`, but the XDR type is
// Duration = Uint64 (64-bit), which can exceed Number.MAX_SAFE_INTEGER.
// This is a breaking type change that should be surfaced when types/index.d.ts is updated.
_minAccountSequenceAge?: xdr.Uint64;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is sort of a breaking change, so we might want to document it.

@github-actions
Copy link

Size Change: +2.52 kB (+0.07%)

Total Size: 3.61 MB

Filename Size Change
dist/stellar-base.js 2.66 MB +1.89 kB (+0.07%)
dist/stellar-base.min.js 948 kB +636 B (+0.07%)

compressed-size-action

Comment on lines +8 to +11
export class TransactionBase<
TTx extends xdr.FeeBumpTransaction | xdr.Transaction | xdr.TransactionV0
> {
_tx: TTx;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to make this update to get the types properly working in Transaction (and FeeBumpTransaction later).

*/
export function isValidDate(d) {
// isnan is okay here because it correctly checks for invalid date objects
// eslint-disable-next-line no-restricted-globals
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ESLint was complaining about it.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Migrates the core Transaction implementation from JavaScript to TypeScript, aligning it with the repo’s ongoing TS migration and improving type-safety around transaction envelopes and preconditions.

Changes:

  • Converted src/transaction implementation to TypeScript with explicit XDR/operation typings.
  • Generalized TransactionBase to be generic over transaction XDR types (TransactionV0/Transaction/FeeBumpTransaction).
  • Added generated type validation declarations for Transaction / updated TransactionBase declarations.

Reviewed changes

Copilot reviewed 3 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
type_validation/transaction_base.d.ts Updates TransactionBase declarations to be generic over supported XDR transaction types.
type_validation/transaction.d.ts Adds generated type declarations for the migrated Transaction class.
src/transaction_builder.js Removes an ESLint disable comment in isValidDate.
src/transaction_base.ts Makes TransactionBase generic over XDR transaction variants.
src/transaction.ts New TS implementation of Transaction, including signature base, envelope conversion, and claimable balance ID logic.
Comments suppressed due to low confidence (3)

src/transaction.ts:294

  • In signatureBase(), the AccountID discriminant is hard-coded as Buffer.alloc(4). This relies on PUBLIC_KEY_TYPE_ED25519 always being 0 and encoded as 4 zero bytes; using the XDR enum to generate the discriminant (as was done previously) avoids baking in that assumption and is clearer about intent.
    src/transaction.ts:393
  • HashIdPreimageOperationId expects AccountId sourceAccount and SequenceNumber seqNum in XDR. Even though these are currently typedefs of PublicKey and Int64, constructing them via xdr.AccountId / xdr.SequenceNumber would better match the schema and existing code patterns (e.g., TransactionBuilder) and reduces the risk of subtle type/behavior drift if the typedefs change.
    src/transaction.ts:200
  • The JSDoc for minAccountSequenceAge still states @type {number}, but the implementation stores/returns an XDR Uint64 (Duration) and the generated .d.ts reflects that. Please update the JSDoc (and any related docs) to match the actual return type to avoid misleading consumers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@quietbits quietbits requested a review from Ryang-21 March 10, 2026 17:04
@quietbits quietbits merged commit a2b7f03 into typescript-migration Mar 10, 2026
10 checks passed
@quietbits quietbits deleted the tsm-transaction branch March 10, 2026 18:18
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.

Migrate transaction.js file to TS

3 participants