@ Egge
2025-02-02 13:09:27
We’re thrilled to announce the stable release of Cashu-TS v2.2! Although this update is a minor version bump, it brings significant improvements under the hood that enhance the overall developer experience. We’ve spent several weeks testing and refining these changes.
---
## What’s New in v2.2?
While there are no breaking changes in this release, there are many internal changes. If you spot any regressions or unexpected behavior, please [let us know](https://github.com/cashubtc/cashu-ts/issues). Here’s a rundown of the major updates:
- **Enhanced Proof Creation**: The way proofs are created internally has been revamped.
- **User-Controlled Outputs**: You now have full control over how outputs are created.
- **Improved Bundling**: We’ve switched our bundling tool to [vite](https://vitejs.dev) for faster and more modern builds.
- **Updated Testing Tools**: Our testing framework has migrated to [vitest](https://vitest.dev) and [msw](https://mswjs.io), with added browser testing via Playwright.
---
## New Flexibility with OutputData
In previous versions of Cashu-TS, the creation of outputs (or *BlindedMessages*) was hidden away. Even though there were options to tweak the process (like deterministic secrets or P2PK), you were always limited to the built-in logic.
### What’s Changed?
In v2.2, we’ve introduced a public interface that not only streamlines output creation but also lets you plug in your own custom logic when needed. With the new `outputData` option available on all output-creating methods, you can now bypass the automatic process and provide your own outputs.
For example, you can create two proofs tied to different public keys in a single mint operation:
```ts
const data1 = OutputData.createP2PKData({ pubkey: "key1" }, 10, keys);
const data2 = OutputData.createP2PKData({ pubkey: "key2" }, 10, keys);
const { keep, send } = await wallet.send(20, proofs, {
outputData: { send: [...data1, ...data2] },
});
```
### Customization Made Easy
The `outputData` option now accepts anything that conforms to the `OutputDataLike` interface. This means you can introduce your own output creation logic—even if it’s not natively supported by Cashu-TS yet. Here’s what the interface looks like:
```ts
export interface OutputDataLike {
blindedMessage: SerializedBlindedMessage;
blindingFactor: bigint;
secret: Uint8Array;
toProof: (signature: SerializedBlindedSignature, keyset: MintKeys) => Proof;
}
```
### Introducing OutputData Factories
While having full control is empowering, it also means you’ll need to handle tasks like fee calculation and amount selection manually. To strike a balance between control and convenience, we now support **OutputData Factories**.
A factory is simply a function that takes an amount and `MintKeys` as input and returns an `OutputDataLike` object. This way, you can define a blueprint for your output data without worrying about the nitty-gritty details. For instance, you can create separate factories for amounts you keep versus those you send:
```ts
function keepFactory(a: number, k: MintKeys) {
return OutputData.createSingleP2PKData({ pubkey: "keepPk" }, a, k.id);
}
function sendFactory(a: number, k: MintKeys) {
return OutputData.createSingleP2PKData({ pubkey: "sendPk" }, a, k.id);
}
const { send, keep } = await wallet.send(amount, proofs, {
outputData: { send: createFactory("send"), keep: createFactory("keep") },
});
```
Plus, you can now instantiate a `CashuWallet` with a default `keepFactory`, ensuring that all change amounts automatically lock to your key—streamlining your workflow even further.
---
## Bundling Improvements with Vite
Starting with v2.2, we’ve transitioned from using `tsc` to [vite](https://vitejs.dev) for transpiling and bundling the library code. Although this change is mostly behind the scenes, it brings several benefits:
- **Modern Build Target**: We’ve updated our build target to ES6.
- **Updated Exports**: The package exports now reflect the latest JavaScript standards.
- **Standalone Build Soon**: We’re working on a standalone build that bundles Cashu-TS along with all its dependencies. This will let you import Cashu-TS directly into your HTML.
If you encounter any issues with the new bundling setup, please [let us know](https://github.com/cashubtc/cashu-ts/issues).
### A Nod to Vitest
In addition to our bundling improvements, we’ve migrated our testing framework from Jest (with nock) to [vitest](https://vitest.dev) combined with [msw](https://mswjs.io). This switch gives us more flexibility in testing and mocking, plus we’ve added browser testing based on Playwright—thanks to the tip from nostr:npub16anjdksmvn5x08vtden04n64rw5k7fsjmedpw8avsx8wsh8ruhlq076pfx!
---
## In Conclusion
Although Cashu-TS v2.2 is a minor version update, it comes packed with improvements that enhance both the developer experience and the flexibility of the library. We’re excited to see how you’ll use these new features in your projects! Thanks to all the amazing contributors that add to this library.
Thank you for being a part of the Cashu-TS community. As always, if you have any questions, suggestions, or issues, don’t hesitate to [reach out to us](https://github.com/cashubtc/cashu-ts/issues).