mpay@0.2.0
Minor Changes
-
04df8d5: Breaking: Renamed
clientparameter togetClient.- tempo.charge({ client: (chainId) => createClient({ ... }) }) + tempo.charge({ getClient: (chainId) => createClient({ ... }) })
-
b72b6cd: Added framework middleware adapters for Hono, Express, Next.js, and Elysia.
import { Mpay, tempo } from "mpay/hono"; const mpay = Mpay.create({ methods: [tempo.charge()] }); app.get("/premium", mpay.charge({ amount: "1" }), (c) => c.json({ data: "paid content" }) );
-
1f31b79: Breaking: Changed
getClientinterface to accept an object parameter.- getClient: (chainId: number) => Client + getClient: ({ chainId }: { chainId?: number | undefined }) => Client
-
3db4245: Breaking: Renamed
methodtomethodsonChallenge.from(),Challenge.deserialize(),Challenge.fromHeaders(), andChallenge.fromResponse().- const challenge = Challenge.fromResponse(response, { method }) + const challenge = Challenge.fromResponse(response, { methods }) - const challenge = Challenge.deserialize(value, { method }) + const challenge = Challenge.deserialize(value, { methods })
-
9d079e5: Added support for passing an
Accountasrecipientto server-sidetempo.charge()andtempo.stream(). When anAccountis passed, itsaddressis used as the payment recipient. SettingfeePayer: truemakes the recipient account also sponsor transaction fees.import { Mpay, tempo } from "mpay/server"; const mpay = Mpay.create({ methods: [ tempo.charge({ recipient: account, feePayer: true, currency: "0x...", }), ], });
-
e773992: Breaking: Removed
Fetchfrom the public API ofmpay/client.Mpay.create()now returns afetchfunction and polyfillsglobalThis.fetchby default.- import { Fetch, tempo } from 'mpay/client' + import { Mpay, tempo } from 'mpay/client' - Fetch.polyfill({ + Mpay.create({ methods: [tempo.charge({ account })], }) // globalThis.fetch now handles 402 automatically const res = await fetch('/resource') - Fetch.restore() + Mpay.restore()
To opt out of polyfilling, set
polyfill: falseand use the returnedfetch:const mpay = Mpay.create({ polyfill: false, methods: [tempo.charge({ account })], }); const res = await mpay.fetch("/resource");
-
3db4245: Breaking: Removed
Methodmodule. UseMethodIntentinstead.- import { Method } from 'mpay' + import { MethodIntent } from 'mpay' - const server = Method.toServer(method, { verify }) + const server = MethodIntent.toServer(methodIntent, { verify }) - const client = Method.toClient(method, { createCredential }) + const client = MethodIntent.toClient(methodIntent, { createCredential })
-
a335fda: Breaking: Renamed
recipientparameter toaccount. Therecipientparameter now only accepts anAddressstring (in cases where you want a separate recipient address).tempo.charge({ - recipient: account, + account, feePayer: true, // or with different recipient address recipient: '0x...', }) -
1e47a09: Breaking: Refactored tempo method exports to use
tempo.charge()namespace.import { Mpay, tempo } from 'mpay/server' const mpay = Mpay.create({ - methods: [tempo()], + methods: [tempo.charge()], }) -
df400e3: Added composed
tempo()client factory that returns bothchargeandstreammethod intents.import { Mpay, tempo } from "mpay/client"; const mpay = Mpay.create({ methods: [tempo({ account, deposit: 10_000_000n })], });
tempo.charge()andtempo.stream()continue to work for individual use.Mpay.createnow accepts nested tuples inmethodsand flattens them automatically. -
6c41693: Added
tempo.streamintent.
Patch Changes
- 10e9204: Added
Channel.computeIdto compute stream channel IDs locally, eliminating a network round-trip to the contract. - aea84a3: Supported nested method tuples in server
Mpay.create, matching the client-sideMethodspattern. Methods are automatically flattened viaFlattenMethods. - a630f09: Added support for multiple
Authorizationschemes.Credential.fromRequestand the HTTP server transport now correctly extract thePaymentscheme from headers containing multiple authorization values (e.g.,BeareralongsidePayment).