
Security News
Ruby's Bundler 4.0.18 Extends Cooldown to bundle lock and bundle cache
The supply chain control that delays freshly published gems now covers lockfile generation and gem vendoring in Ruby projects.
@lightsparkdev/js-sdk
Advanced tools
This is the Lightspark Typescript SDK, which can be used either from a node or browser environment. See the examples directory for some examples of how to use it!
To use the SDK, you'll need to install it from npm:
$ npm install @lightsparkdev/js-sdk
The entry-point to the SDK is the LightsparkClient class, which can be imported from the root package.
To create and authenticate a client from a server-environment, you'll need to provide your API token ID and secret. You can create these from the Lightspark API Tokens page.
import { LightsparkClient } from "@lightsparkdev/js-sdk";
import { AccountTokenAuthProvider } from "@lightsparkdev/js-sdk/auth";
const TOKEN_ID = <your api token id>;
// NOTE: This should be stored securely, e.g. in an environment variable and shouldn't be present in client-side code.
const TOKEN_SECRET = <your api token secret>;
const lightsparkClient = new LightsparkClient(
new AccountTokenAuthProvider(TOKEN_ID, TOKEN_SECRET)
);
If you want to use the client in a browser environment, you'll need to use a different authentication provider. The OAuthProvider can be used to authenticate with the user's Lightspark account. It will open a popup window to the Lightspark login page, and then exchange the authorization code for an access token.
You can then use the client to make API calls. For example, to create an invoice:
const encodedInvoice = await lightsparkClient.createInvoice({
amount: { value: 100, unit: CurrencyUnit.SATOSHI },
memo: "Whasssupppp",
type: InvoiceType.AMP,
});
const invoiceDetails = await lightsparkClient.decodeInvoice(encodedInvoice);
console.log(invoiceDetails);
To complete sensitive operations like paying an invoice, you'll need to unlock the paying node using its node ID and password:
const nodeID = <the node ID of a node to unlock>;
const nodePassword = <the password used to unlock the node>;
try {
await lightsparkClient.unlockNode(nodeID, nodePassword);
} catch (e) {
console.error("Failed to unlock node", e);
}
// Now we can pay the invoice.
const payment = await lightsparkClient.payInvoice(nodeID, encodedInvoice, 1000);
console.log(`Payment details: ${payment}`);
You can also use the SDK to subscribe to events from the node, such as transaction updates. For example, to subscribe to transaction updates for a node:
const nodeID = <the node ID of a node to subscribe to>;
let subscription;
function startListening(nodeId: string) {
if (subscription) {
return;
}
console.log("Starting to listen for transactions...");
subscription = lightsparkClient.listenToTransactions([nodeID]).subscribe({
next: (transaction) => {
if (transaction) {
console.log(`Transaction updated! ${JSON.stringify(transaction)}`);
}
},
});
}
function stopListening() {
if (!subscription) {
return;
}
console.log("Stopping listening for transactions...");
subscription.unsubscribe();
subscription = undefined;
}
Several examples of SDK usage are included in the top-level examples directory.
Try the node script examples using ts-node!
You'll need to set the following environment variables:
$ export LIGHTSPARK_API_TOKEN_CLIENT_ID=<your api token id>
$ export LIGHTSPARK_API_TOKEN_CLIENT_SECRET=<your api token secret>
$ export LIGHTSPARK_WALLET_NODE_ID=<the node ID of a node you can use as your default wallet>
# If you want to run full_example.ts, you'll also need to set these:
$ export LIGHTSPARK_EXAMPLE_NODE_1_NAME=<the display name of a node to use in the example>
$ export LIGHTSPARK_EXAMPLE_NODE_1_PASSWORD=<the password used to unlock node 1>
$ export LIGHTSPARK_EXAMPLE_NODE_2_NAME=<the display name of a node to use in the example>
$ export LIGHTSPARK_EXAMPLE_NODE_2_PASSWORD=<the password used to unlock node 2>
Then, run the examples:
$ cd examples/node-scripts
$ npm install
$ ts-node getWalletDashboard.ts
$ ts-node createInvoice.ts -a "100" -m "Whasssupppp"
This example is meant to be used in conjunction with the Lightspark streaming sats demo. It can be built and installed as a Chrome extension by running:
$ cd examples/streaming-wallet-extension
$ npm install
$ npm run build
Then, go to chrome://extensions and click "Load unpacked" and select the streaming-wallet-extension/build directory.
When the extension is installed, it will automatically open the streaming sats demo page. You can then click extension icon to open the extension popup, which will give you the ability to create a test account with 2 nodes - a viewer node (which acts as your wallet for the demo), and a creator node, which simulates the wallet of the creator of the streaming content. The page will reload and you'll be able to start streaming sats as the video plays!
To see how it works, check out the background directory in the extension code. It uses the SDK to create an invoice on behalf of the creator node, then uses the SDK to pay the invoice on behalf of the viewer node. It also uses the SDK to get the current balance of both nodes and listen for transaction updates, which it broadcasts to the webpage.
FAQs
Lightspark JS SDK
We found that @lightsparkdev/js-sdk demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
The supply chain control that delays freshly published gems now covers lockfile generation and gem vendoring in Ruby projects.

Security News
During a UK cyber test, a Mythos 5 agent used sockpuppets, social engineering, and prompt injection to try to get a maintainer to merge malware.

Company News
Socket is now in the AWS Security Hub Extended plan. Adopt it through AWS, apply committed spend, and block malicious open source packages.