This package builds a wrapper around the messaging system used to interact with the LOBSTR browser extension. Client applications will be able to install this package from npm and then integrate it with the LOBSTR signer extension using dev-friendly methods.
To ensure consistency of styles with the LOBSTR wallet, please use the assets in the assets folder for your integration and always write the LOBSTR wallet brand name in all capital letters only.
To get started, you’ll need both the LOBSTR signer extension and the API needed to integrate with it.
- Head over to the Chrome Web Store and install the LOBSTR signer extension into your browser.
Now, you need a way to communicate with the LOBSTR signer extension. To facilitate this, we created a Javascript library called @lobstrco/signer-extension-api that will let you send and receive messages from the extension.
- Install the module using npm:
npm install @lobstrco/signer-extension-api
or
- Install the module using yarn:
yarn add @lobstrco/signer-extension-api
Install the packaged library via script tag, swapping in the desired version number for {version}:
<script src="https://cdn.jsdelivr.net/npm/@lobstrco/signer-extension-api@{version}/build/index.min.js"></script>unpkg serves the same file, if you prefer it:
<script src="https://unpkg.com/@lobstrco/signer-extension-api@{version}/build/index.min.js"></script>The package ships three builds and picks the right one for you:
| Your setup | What you get |
|---|---|
import (native ESM, bundlers, Node ESM) |
build/index.mjs |
require (CommonJS) |
build/index.cjs |
<script src="..."> |
build/index.min.js (defines window.lobstrExtensionApi) |
Named imports work in all three, including native ESM in Node. The <script> file opens with its
own "use strict" directive, so load it as its own script rather than concatenating it ahead of
others.
@lobstrco/signer-extension-api/protocol is a second entry point holding the vocabulary the
SDK and the extension share on the wire: the message type names, the API version, the
dApp-visible error strings and the request/response types. A dApp does not need it — the
functions below speak the protocol for you. It exists for the extension itself and for anyone
implementing the same protocol.
| Your setup | What you get |
|---|---|
import { ... } from "@lobstrco/signer-extension-api/protocol" |
build/protocol.mjs |
require("@lobstrco/signer-extension-api/protocol") |
build/protocol.cjs |
You now have an extension installed on your machine and a library to interact with it. This library will provide methods to send and receive data from a user’s extension on your website or application.
The default export carries every function in an ES2023 application:
import lobstrApi from "@lobstrco/signer-extension-api";NETWORK and isBrowser are named exports only — the default export holds the
functions, not the constants.
or import just the modules you require:
import {
isConnected,
getPublicKey,
getConnectedWallet,
getSupportedNetworks,
supportsNetwork,
signTransaction,
signMessage,
NETWORK,
} from "@lobstrco/signer-extension-api";Now let's dig into what functionality is available to you:
The extension can hold wallets on more than one network. Every function that touches a
wallet takes an optional network, and leaving it out always means Stellar — code written
before networks existed keeps working, permanently and by design.
import { NETWORK, getPublicKey } from "@lobstrco/signer-extension-api";
await getPublicKey(); // Stellar, same as it ever was
await getPublicKey({ network: NETWORK.ripple }); // the XRP Ledger walletConnections are kept per network: asking for a Stellar wallet and asking for an XRP Ledger wallet are two separate approvals, and each is remembered on its own.
Ask the extension what it supports rather than assuming — an older build will not know a network your code was written for:
import { getSupportedNetworks, supportsNetwork, NETWORK } from "@lobstrco/signer-extension-api";
if (await supportsNetwork(NETWORK.ripple)) {
// safe to offer XRP Ledger in your UI
}
for (const entry of await getSupportedNetworks()) {
console.log(entry.network, entry.displayName, entry.available);
}available: false means the extension knows the network but cannot use it right now. That is
different from the network being absent from the list, which means this build has never heard
of it. Treat an unknown string as unknown — do not fall back to Stellar.
NETWORK is an enum of the networks this SDK version knows (stellar, ripple), but the
network parameter accepts any string, so a page written today can name a network a later
extension adds.
isConnected() -> <Promise<boolean>>
This function is used to determine whether a user has the LOBSTR signer extension installed in your application.
import { isConnected } from "@lobstrco/signer-extension-api";
if (await isConnected()) {
alert("User has LOBSTR extension installed!");
}getPublicKey(options?: { network?: string }) -> <Promise<string>>
Returns the address of the connected wallet on the requested network, prompting the user to
approve the connection if they have not already. Omit options for Stellar.
It throws rather than returning an empty string when there is nothing to return — see
Errors. Outside a browser it resolves to "".
import { getPublicKey } from "@lobstrco/signer-extension-api";
const retrievePublicKey = async (): Promise<string> => {
let publicKey = "";
let error = "";
try {
publicKey = await getPublicKey();
} catch (e) {
error = e instanceof Error ? e.message : String(e);
}
if (error) {
return error;
}
return publicKey;
};getConnectedWallet(options?: { network?: string }) -> <Promise<{ publicKey: string, network: string } | null>>
The same connection as getPublicKey, but it also tells you which network the wallet is on.
Use it when you support more than one network and need to keep track of which is which.
import { getConnectedWallet, NETWORK } from "@lobstrco/signer-extension-api";
const wallet = await getConnectedWallet({ network: NETWORK.ripple });
// { publicKey: "r...", network: "ripple" }Resolves to null outside a browser.
getSupportedNetworks() -> <Promise<SupportedNetwork[]>>
What this extension build can do. Each entry describes one network:
| Field | Meaning |
|---|---|
network |
The id you pass as options.network |
displayName |
Name to show a user, e.g. "XRP Ledger" |
nativeCode / nativeDecimals |
The native asset, e.g. "XRP" and 6 |
explorerAccountUrl |
Account page prefix; append an address |
signTypes |
Which of "transaction" / "message" this network accepts |
broadcaster |
"dapp" — signing gives you the signed transaction to submit; "wallet" — it gives you the id of one the wallet already sent |
available |
false means known but currently unusable |
Resolves to [] outside a browser. An older extension returns only what it knows, so treat
the list as the source of truth rather than hard-coding networks.
supportsNetwork(network: string) -> <Promise<boolean>>
Shorthand for looking one network up in getSupportedNetworks().
signTransaction(transaction: string, options?: { network?: string }) -> <Promise<string>>
Signs a transaction as the user and returns the result to your application.
transaction is a string in the network's own grammar — a base64 XDR envelope on Stellar,
transaction JSON on the XRP Ledger. What comes back follows that network's broadcaster: with
"dapp" (both networks today) you get the signed transaction and submit it yourself.
The signed transaction comes back in the network's own grammar too:
| Network | You send | You get back |
|---|---|---|
| Stellar | base64 XDR envelope | the signed envelope, base64 XDR |
| XRP Ledger | transaction JSON | the signed transaction as a hex-encoded binary blob (tx_blob), ready for submit |
On the XRP Ledger, LOBSTR sets Fee, Sequence and LastLedgerSequence when it signs, so read
the final values — and the transaction hash — from the returned blob, not from the JSON you sent.
LOBSTR does not submit the transaction.
NOTE: The payload must be valid for the network you name, or the call is refused before the user is ever prompted.
import { signTransaction } from "@lobstrco/signer-extension-api";
const userSignTransaction = async (xdr: string): Promise<string> => {
let signedTransaction = "";
let error = "";
try {
signedTransaction = await signTransaction(xdr);
} catch (e) {
error = e instanceof Error ? e.message : String(e);
}
if (error) {
return error;
}
return signedTransaction;
};On the XRP Ledger, with xrpl.js:
import { NETWORK, signTransaction } from "@lobstrco/signer-extension-api";
import { Client, decode, hashes } from "xrpl";
const txBlob = await signTransaction(JSON.stringify(txJson), { network: NETWORK.ripple });
const signed = decode(txBlob); // the transaction as signed, with LOBSTR's Fee and Sequence
const hash = hashes.hashSignedTx(txBlob);
const client = new Client("wss://xrplcluster.com");
await client.connect();
await client.submit(txBlob);signMessage(message: string, options?: { network?: string }) -> <Promise<{signedMessage: string, signerAddress: string} | null>>
This function accepts a message string, which it will sign and return an object containing the signed message and the signer's address to your application.
Not every network signs arbitrary messages — the XRP Ledger has no scheme for it, and asking
is refused with SIGN_TYPE_NOT_SUPPORTED. Check signTypes in getSupportedNetworks() before
offering it.
import { signMessage } from "@lobstrco/signer-extension-api";
const userSignMessage = async (message: string): Promise<{signedMessage: string, signerAddress: string} | null> => {
let result = null;
let error = "";
try {
result = await signMessage(message);
} catch (e) {
error = e instanceof Error ? e.message : String(e);
}
if (error) {
console.error("Error signing message:", error);
return null;
}
return result;
};You now have the LOBSTR signer extension installed on our machine and a library to interact with it. This library will provide you methods to send and receive data from a user’s extension in your website or application.
First import the library in the <head> tag of your page.
- Install the packaged library via script tag, swapping in the desired version number for
{version}
<head>
<script src="https://cdn.jsdelivr.net/npm/@lobstrco/signer-extension-api@{version}/build/index.min.js"></script>
</head>This exposes a global called window.lobstrExtensionApi holding the library. The call
signatures are exactly the same as the node version:
if (await window.lobstrExtensionApi.isConnected()) {
alert("User has LOBSTR extension installed!");
}
const publicKey = await window.lobstrExtensionApi.getPublicKey({
network: window.lobstrExtensionApi.NETWORK.ripple,
});Failures reject with an Error whose message is one of the strings below. They are stable
values — compare error.message against them rather than parsing it:
error.message |
What happened |
|---|---|
"User declined access" |
The user closed the prompt or rejected it in the app |
"Network is not supported" |
This extension build does not know the network you named |
"The connected wallet belongs to a different network" |
The wallet answered on a network other than the one you asked for |
"The connection key is missing" |
signTransaction or signMessage was called before getPublicKey connected a wallet on that network |
"The data to sign is missing" |
The payload was empty or not a string |
"A wallet cannot be connected from this page" |
The page has no origin to bind a connection to — a file:// document or a sandboxed frame |
"Reconnect the wallet to continue" |
The extension does not recognise the reference this page holds — it was revoked, it belongs to another origin, or it predates the current extension. Call getPublicKey again |
"Associated account not found" |
The wallet was removed from the extension while the access prompt stood open |
"This type of signing is not supported on this network" |
e.g. signMessage on the XRP Ledger |
"The transaction payload is not valid for this network" |
The payload is not in that network's grammar |
"The transaction payload is too large" |
Over the size the network's signing path accepts |
"Couldn't open access prompt" |
The extension could not open its confirmation window |
"Unable to send message to extension" |
The page could not reach the extension — typically after the extension was updated; reload the page |
"This request type is not supported" |
The installed extension predates this SDK and does not know the request |
"Sign failed" |
Deliberately vague — the signing did not complete |
"Signing request timed out" |
The user never answered in the app |
No call changes meaning: a call with no network is a Stellar call, permanently. Only
the shape of a rejection changed (below).
Three things to know:
- Entry points. The package now declares
exports, so deep paths such as@lobstrco/signer-extension-api/build/index.min.jsno longer resolve. Import the package itself. In exchange, named imports now work in native ESM, where they previously existed only in the type definitions. - New surface.
getConnectedWallet,getSupportedNetworks,supportsNetwork, theNETWORKenum, and an optionalnetworkongetPublicKey,signTransactionandsignMessage. - Errors. Rejections are
Errorobjects; v2 rejected with the bare string. The strings are unchanged, so compareerror.messagewhere you compared the value itself.
Node 22.13 or newer.
npm ci
npm test # builds first: the Node suite reads the built output in build/
npm run verify:types
npm run build bundles with esbuild and emits the declarations with tsc; npm run lint,
npm run format:check and npm run typecheck are what CI runs, and npm run test:watch
keeps the tests running.
Apache-2.0. See LICENSE.