Skip to content

Conversation

@spencerstock
Copy link
Collaborator

@spencerstock spencerstock commented Nov 25, 2025

What changed? Why?

Adds EphemeralBaseAccountProvider and EphemeralSigner for single-use payment flows (pay() and subscribe()).

Problem: When multiple payment flows execute concurrently or sequentially, they share global state which causes race conditions and cleanup of one flow affects others.

Solution:

  • EphemeralBaseAccountProvider: Provider with isolated state that only supports payment methods (wallet_sendCalls, wallet_sign, wallet_getCallsStatus)
  • EphemeralSigner: Signer that maintains instance-local state and cleans up without affecting global store
  • Request queuing in sdkManager.ts to prevent concurrent payment operations from interfering
  • One-time initialization in createBaseAccountSDK.ts to avoid redundant setup calls
  • Updated Signer.cleanup() to preserve store.chains since chain clients are shared infrastructure

How was this tested?

Existing test coverage for createBaseAccountSDK.test.ts updated to reset global initialization state between tests.

How can reviewers manually test these changes?

  1. Call pay() or subscribe() multiple times in sequence
  2. Verify each payment flow completes without affecting subsequent flows
  3. Verify chain clients remain available after payment completion

Demo/screenshots

@cb-heimdall
Copy link
Collaborator

cb-heimdall commented Nov 25, 2025

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

…o enable it

Separates telemetry initialization from global initialization so that:
- First SDK call with telemetry: false doesn't prevent later calls from enabling telemetry
- Telemetry is only loaded when at least one SDK instance requests it
@spencerstock spencerstock marked this pull request as ready for review November 25, 2025 17:43
Copy link
Collaborator

@fan-zhang-sv fan-zhang-sv left a comment

Choose a reason for hiding this comment

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

hmmm i think there might still be some issues with this approach.

i wonder if we could

  • switch to dependency injection, so we inject store upon creating sdk instance
  • and have ephemeral sdk use its own store instance upon creation
  • and have ephemeral sdk removing this instance store upon clear()
  • this way, there might be a chance we dont need to duplicate Provider/Signer code (not 100% sure)


async handshake(args: RequestArguments) {
const correlationId = correlationIds.get(args);
logHandshakeStarted({ method: args.method, correlationId });
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we add an additional param isEphemeral to measure success for each component?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added!

*/
export class EphemeralSigner {
private readonly communicator: Communicator;
private readonly keyManager: SCWKeyManager;
Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm i think keyManager could still be an issue

  • keyManager is still reading and writing to global state in localStorage
  • keyManager.clear() rotate the global key pair, which may intervene with concurrent operation

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good call. Added createStoreInstance() that can create either persistent (localStorage) or ephemeral (in-memory) store instances.

Now Signer/EphemeralSigner: Both accept a storeInstance parameter and pass it down to KeyManager

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