New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@thru/embedded-provider

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thru/embedded-provider

Client-side provider for embedding the Thru wallet into any web application. Manages an iframe that hosts the wallet UI, communicates with it over `postMessage`, and exposes a simple API for connecting, signing transactions, and managing accounts.

latest
npmnpm
Version
0.2.14
Version published
Weekly downloads
787
5521.43%
Maintainers
1
Weekly downloads
 
Created
Source

@thru/embedded-provider

Client-side provider for embedding the Thru wallet into any web application. Manages an iframe that hosts the wallet UI, communicates with it over postMessage, and exposes a simple API for connecting, signing transactions, and managing accounts.

Installation

npm install @thru/embedded-provider

Basic Usage

import { EmbeddedProvider } from "@thru/embedded-provider";

const provider = new EmbeddedProvider({
  iframeUrl: "https://wallet.thru.org",
});

// Initialize iframe (must be called before any other operation)
await provider.initialize();

// Connect to wallet (opens modal)
const result = await provider.connect();
console.log(result.accounts);

// Inspect the signing contract before building a transaction
const signingContext = await provider.thru.getSigningContext();

// Build your Thru transaction using signingContext.feePayerPublicKey, then sign it
const signed = await provider.thru.signTransaction(base64EncodedTx);

// Disconnect
await provider.disconnect();

// Cleanup when done
provider.destroy();

API

EmbeddedProvider

Main entry point. Creates and manages the wallet iframe.

Constructor

new EmbeddedProvider(config: EmbeddedProviderConfig)
OptionTypeDefaultDescription
iframeUrlstringDEFAULT_IFRAME_URLURL of the hosted wallet application
addressTypesAddressType[][AddressType.THRU]Chain types to enable

Methods

MethodReturnsDescription
initialize()Promise<void>Create the iframe and wait for it to signal readiness
connect(options?)Promise<ConnectResult>Open the wallet modal and request a connection
disconnect()Promise<void>Disconnect the current session
isConnected()booleanWhether a wallet session is active
getAccounts()WalletAccount[]List of connected accounts
getSelectedAccount()WalletAccount | nullCurrently selected account
selectAccount(publicKey)Promise<WalletAccount>Switch the active account
mountInline(container)Promise<void>Mount the wallet inline inside a DOM element instead of as a modal
on(event, callback)voidSubscribe to provider events
off(event, callback)voidUnsubscribe from provider events
destroy()voidRemove the iframe and clean up all listeners

Properties

PropertyTypeDescription
thruIThruChainChain-specific interface for signing transactions on the Thru network

EmbeddedThruChain

Implements IThruChain. Accessed via provider.thru.

MethodReturnsDescription
connect()Promise<{ publicKey: string }>Connect and return the Thru address
disconnect()Promise<void>Disconnect
getSigningContext()Promise<ThruSigningContext>Return the current selected account plus the actual fee payer/signer contract used by the embedded wallet
signTransaction(serializedTransaction)Promise<string>Accept a base64 signing payload or raw transaction and return canonical raw transaction bytes ready for submission

Events

Subscribe with provider.on(event, callback):

  • connect -- Wallet connected successfully
  • connect:start -- Connection flow initiated
  • connect:error -- Connection attempt failed
  • disconnect -- Wallet disconnected
  • lock -- Wallet locked by the user
  • account:changed -- Active account switched
  • ui:show -- Wallet UI requested to be shown

Display Modes

The provider supports two display modes:

  • Modal (default) -- The iframe is appended to document.body as a full-screen overlay.
  • Inline -- The iframe is mounted inside a container element you provide, useful for embedding a connect button directly in your page layout.
// Inline mode
const container = document.getElementById("wallet-mount");
await provider.mountInline(container);

Security

The IframeManager validates that the iframe URL belongs to a set of trusted origins before loading it. Allowed origins:

  • https://wallet.thru.org
  • http://localhost (any port, for development)

Messages are sent with a strict targetOrigin and each iframe instance is tagged with a unique frame ID to prevent cross-talk.

Key Capabilities

  • Iframe lifecycle management with automatic readiness detection
  • Request/response correlation over postMessage with per-request timeouts
  • Origin validation to prevent unauthorized wallet iframes
  • Modal and inline display modes
  • Event-driven architecture for connection state changes
  • WebAuthn (passkey) support via iframe allow policy
  • Chain-specific interfaces via the IThruChain abstraction

Thru Signing Contract

For the embedded passkey wallet, the selected wallet account shown in the UI can differ from the network fee payer / signer that actually authorizes the Thru transaction. Call provider.thru.getSigningContext() before building a transaction to retrieve:

  • selectedAccountPublicKey - the managed account currently selected in the wallet
  • feePayerPublicKey - the address that must be used as the transaction fee payer
  • signerPublicKey - the cryptographic signer used by the wallet

signTransaction() always returns canonical Transaction.toWire() bytes encoded as base64, so apps can decode and submit the result directly without reordering signature bytes.

Dependencies

  • @thru/chain-interfaces -- Shared chain interface types (IThruChain, WalletAccount)
  • @thru/protocol -- Message type constants, request/response schemas, and helper utilities

FAQs

Package last updated on 01 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts