Skip to content

Consolidating frames code#112

Merged
leeland-turnkey merged 15 commits intomainfrom
leeland/eng-2786-tob-53-frames-shared-code-should-be-consolidated
Feb 4, 2026
Merged

Consolidating frames code#112
leeland-turnkey merged 15 commits intomainfrom
leeland/eng-2786-tob-53-frames-shared-code-should-be-consolidated

Conversation

@leeland-turnkey
Copy link
Contributor

Consolidate Shared Code into shared/ Folder

Problem

There was significant code duplication between export-and-sign, import, and other frames. This led to:

  • Maintenance overhead: Security patches and improvements needed to be applied in multiple places
  • Inconsistent implementations: Subtle differences between frames could lead to bugs

Solution

Created a new shared/ folder containing common utilities used across all frames, following the recommendation to "unify the code between all frames by extracting shared code into reusable libraries."

Changes

Updated Frames to Use Shared Code

  1. export-and-sign:

    • Updated turnkey-core.js to import from shared and keep frame-specific code (Ed25519, verifyEnclaveSignature using @turnkey/crypto)
    • Updated crypto-utils.js to re-export from shared
    • Updated webpack config to resolve @shared alias
  2. import:

    • Updated turnkey-core.js to import from shared and keep frame-specific applySettings logic
    • Updated index.js and standalone.js to use shared HpkeEncrypt
    • Updated webpack config to resolve @shared alias

Added CI for Shared Folder

  • Added shared to CI matrix for tests, linting, and formatting
  • Shared code is now validated on every push/PR

@socket-security
Copy link

socket-security bot commented Jan 9, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​babel/​preset-env@​7.28.5971007797100
Added@​testing-library/​jest-dom@​6.9.19810010089100

View full report

@leeland-turnkey leeland-turnkey force-pushed the leeland/eng-2786-tob-53-frames-shared-code-should-be-consolidated branch from b1f4eaa to 3f55871 Compare January 27, 2026 22:34
@leeland-turnkey leeland-turnkey force-pushed the leeland/eng-2786-tob-53-frames-shared-code-should-be-consolidated branch from 0a0c51a to 1ce6c90 Compare February 3, 2026 17:31

This page is hosted at https://oauth-redirect.turnkey.com/

# Subfolders and build status
Copy link
Contributor Author

@leeland-turnkey leeland-turnkey Feb 3, 2026

Choose a reason for hiding this comment

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

AI helped with this @andrewkmin

context: #112 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Nonblocking, and not related to this PR but just some additional documentation suggestions: we could add to the verifyEnclaveSignature function signature in line ~44 or ~61:

// Read environment from meta tag (templated at deploy time), fall back to window variable (for testing)

-->

// Read environment from meta tag, fall back to window variable (for testing).
// Additional context: this iframe uses SRI (the browser verifies JS bundle hashes at load time).
// If we templated the environment variable directly in JS (like the shared module does), the
// `sed` replacement at deploy time would change the bundle content, invalidating the SRI hash
// and causing the browser to block the script. By reading from a meta tag, we can template
// the HTML without touching the JS bundle, preserving SRI integrity.

@leeland-turnkey leeland-turnkey merged commit b4a71d9 into main Feb 4, 2026
26 checks passed
@leeland-turnkey leeland-turnkey deleted the leeland/eng-2786-tob-53-frames-shared-code-should-be-consolidated branch February 4, 2026 00:24
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.

2 participants