@solana/mpp 0.0.0 → 0.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +227 -0
- package/dist/Methods.d.ts +272 -0
- package/dist/Methods.d.ts.map +1 -0
- package/dist/Methods.js +217 -0
- package/dist/Methods.js.map +1 -0
- package/dist/client/Charge.d.ts +112 -0
- package/dist/client/Charge.d.ts.map +1 -0
- package/dist/client/Charge.js +216 -0
- package/dist/client/Charge.js.map +1 -0
- package/dist/client/Methods.d.ts +27 -0
- package/dist/client/Methods.d.ts.map +1 -0
- package/dist/client/Methods.js +23 -0
- package/dist/client/Methods.js.map +1 -0
- package/dist/client/Session.d.ts +195 -0
- package/dist/client/Session.d.ts.map +1 -0
- package/dist/client/Session.js +411 -0
- package/dist/client/Session.js.map +1 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +6 -0
- package/dist/client/index.js.map +1 -0
- package/dist/constants.d.ts +7 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +14 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/server/Charge.d.ts +103 -0
- package/dist/server/Charge.d.ts.map +1 -0
- package/dist/server/Charge.js +318 -0
- package/dist/server/Charge.js.map +1 -0
- package/dist/server/Methods.d.ts +23 -0
- package/dist/server/Methods.d.ts.map +1 -0
- package/dist/server/Methods.js +19 -0
- package/dist/server/Methods.js.map +1 -0
- package/dist/server/Session.d.ts +171 -0
- package/dist/server/Session.d.ts.map +1 -0
- package/dist/server/Session.js +430 -0
- package/dist/server/Session.js.map +1 -0
- package/dist/server/index.d.ts +5 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +6 -0
- package/dist/server/index.js.map +1 -0
- package/dist/session/ChannelStore.d.ts +12 -0
- package/dist/session/ChannelStore.d.ts.map +1 -0
- package/dist/session/ChannelStore.js +88 -0
- package/dist/session/ChannelStore.js.map +1 -0
- package/dist/session/Types.d.ts +179 -0
- package/dist/session/Types.d.ts.map +1 -0
- package/dist/session/Types.js +2 -0
- package/dist/session/Types.js.map +1 -0
- package/dist/session/Voucher.d.ts +7 -0
- package/dist/session/Voucher.d.ts.map +1 -0
- package/dist/session/Voucher.js +118 -0
- package/dist/session/Voucher.js.map +1 -0
- package/dist/session/authorizers/BudgetAuthorizer.d.ts +90 -0
- package/dist/session/authorizers/BudgetAuthorizer.d.ts.map +1 -0
- package/dist/session/authorizers/BudgetAuthorizer.js +398 -0
- package/dist/session/authorizers/BudgetAuthorizer.js.map +1 -0
- package/dist/session/authorizers/SwigSessionAuthorizer.d.ts +104 -0
- package/dist/session/authorizers/SwigSessionAuthorizer.d.ts.map +1 -0
- package/dist/session/authorizers/SwigSessionAuthorizer.js +522 -0
- package/dist/session/authorizers/SwigSessionAuthorizer.js.map +1 -0
- package/dist/session/authorizers/UnboundedAuthorizer.d.ts +36 -0
- package/dist/session/authorizers/UnboundedAuthorizer.d.ts.map +1 -0
- package/dist/session/authorizers/UnboundedAuthorizer.js +204 -0
- package/dist/session/authorizers/UnboundedAuthorizer.js.map +1 -0
- package/dist/session/authorizers/index.d.ts +5 -0
- package/dist/session/authorizers/index.d.ts.map +1 -0
- package/dist/session/authorizers/index.js +5 -0
- package/dist/session/authorizers/index.js.map +1 -0
- package/dist/session/authorizers/makeSessionAuthorizer.d.ts +19 -0
- package/dist/session/authorizers/makeSessionAuthorizer.d.ts.map +1 -0
- package/dist/session/authorizers/makeSessionAuthorizer.js +72 -0
- package/dist/session/authorizers/makeSessionAuthorizer.js.map +1 -0
- package/dist/session/index.d.ts +5 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +5 -0
- package/dist/session/index.js.map +1 -0
- package/dist/utils/transactions.d.ts +11 -0
- package/dist/utils/transactions.d.ts.map +1 -0
- package/dist/utils/transactions.js +16 -0
- package/dist/utils/transactions.js.map +1 -0
- package/package.json +75 -8
- package/sdk/src/Methods.ts +230 -0
- package/sdk/src/client/Charge.ts +353 -0
- package/sdk/src/client/Methods.ts +31 -0
- package/sdk/src/client/Session.ts +630 -0
- package/sdk/src/client/index.ts +5 -0
- package/sdk/src/constants.ts +15 -0
- package/sdk/src/index.ts +35 -0
- package/sdk/src/server/Charge.ts +484 -0
- package/sdk/src/server/Methods.ts +27 -0
- package/sdk/src/server/Session.ts +687 -0
- package/sdk/src/server/index.ts +5 -0
- package/sdk/src/session/ChannelStore.ts +128 -0
- package/sdk/src/session/Types.ts +189 -0
- package/sdk/src/session/Voucher.ts +158 -0
- package/sdk/src/session/authorizers/BudgetAuthorizer.ts +574 -0
- package/sdk/src/session/authorizers/SwigSessionAuthorizer.ts +767 -0
- package/sdk/src/session/authorizers/UnboundedAuthorizer.ts +284 -0
- package/sdk/src/session/authorizers/index.ts +4 -0
- package/sdk/src/session/authorizers/makeSessionAuthorizer.ts +104 -0
- package/sdk/src/session/index.ts +4 -0
- package/sdk/src/utils/transactions.ts +26 -0
package/dist/Methods.js
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { Method, z } from 'mppx';
|
|
2
|
+
/**
|
|
3
|
+
* Solana charge method — shared schema used by both server and client.
|
|
4
|
+
*
|
|
5
|
+
* Supports two settlement modes:
|
|
6
|
+
*
|
|
7
|
+
* - **Pull mode** (`type="transaction"`, default): Client signs the
|
|
8
|
+
* transaction and sends the bytes to the server. The server broadcasts,
|
|
9
|
+
* confirms, and verifies the transfer on-chain.
|
|
10
|
+
*
|
|
11
|
+
* - **Push mode** (`type="signature"`): Client broadcasts the transaction
|
|
12
|
+
* itself and sends the confirmed signature. The server verifies on-chain.
|
|
13
|
+
*/
|
|
14
|
+
export const charge = Method.from({
|
|
15
|
+
intent: 'charge',
|
|
16
|
+
name: 'solana',
|
|
17
|
+
schema: {
|
|
18
|
+
credential: {
|
|
19
|
+
payload: z.object({
|
|
20
|
+
/** Base58-encoded transaction signature (when type="signature"). */
|
|
21
|
+
signature: z.optional(z.string()),
|
|
22
|
+
/** Base64-encoded serialized signed transaction (when type="transaction"). */
|
|
23
|
+
transaction: z.optional(z.string()),
|
|
24
|
+
/** Payload type: "transaction" (server broadcasts) or "signature" (client already broadcast). */
|
|
25
|
+
type: z.string(),
|
|
26
|
+
}),
|
|
27
|
+
},
|
|
28
|
+
request: z.object({
|
|
29
|
+
/** Amount in smallest unit (lamports for SOL, base units for SPL tokens). */
|
|
30
|
+
amount: z.string(),
|
|
31
|
+
/** Identifies the unit for amount. "SOL" for native, or token symbol/mint (e.g. "USDC"). */
|
|
32
|
+
currency: z.string(),
|
|
33
|
+
/** Human-readable memo describing the resource or service being paid for. */
|
|
34
|
+
description: z.optional(z.string()),
|
|
35
|
+
/** Merchant's reference (e.g., order ID, invoice number) for reconciliation. */
|
|
36
|
+
externalId: z.optional(z.string()),
|
|
37
|
+
methodDetails: z.object({
|
|
38
|
+
/** Token decimals (required for SPL token transfers). */
|
|
39
|
+
decimals: z.optional(z.number()),
|
|
40
|
+
/** If true, server pays transaction fees. Client must use the server's feePayerKey. */
|
|
41
|
+
feePayer: z.optional(z.boolean()),
|
|
42
|
+
/** Server's base58-encoded public key for fee payment. Present when feePayer is true. */
|
|
43
|
+
feePayerKey: z.optional(z.string()),
|
|
44
|
+
/** Solana network: mainnet-beta, devnet, or localnet. */
|
|
45
|
+
network: z.optional(z.string()),
|
|
46
|
+
/** Server-provided base58-encoded recent blockhash. Saves the client an RPC round-trip. */
|
|
47
|
+
recentBlockhash: z.optional(z.string()),
|
|
48
|
+
/** Unique reference ID for this charge (server-generated, used for tracking). */
|
|
49
|
+
reference: z.string(),
|
|
50
|
+
/** SPL token mint address. If absent, payment is in native SOL. */
|
|
51
|
+
splToken: z.optional(z.string()),
|
|
52
|
+
/** Token program address (TOKEN_PROGRAM or TOKEN_2022_PROGRAM). Defaults to TOKEN_PROGRAM. */
|
|
53
|
+
tokenProgram: z.optional(z.string()),
|
|
54
|
+
}),
|
|
55
|
+
/** Base58-encoded recipient public key. */
|
|
56
|
+
recipient: z.string(),
|
|
57
|
+
}),
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
const voucherSchema = z.object({
|
|
61
|
+
/** Chain identifier, for example `solana:mainnet-beta`. */
|
|
62
|
+
chainId: z.string(),
|
|
63
|
+
/** Channel identifier bound to this voucher. */
|
|
64
|
+
channelId: z.string(),
|
|
65
|
+
/** Channel program address expected by server verifier. */
|
|
66
|
+
channelProgram: z.string(),
|
|
67
|
+
/** Monotonic cumulative authorized amount. */
|
|
68
|
+
cumulativeAmount: z.string(),
|
|
69
|
+
/** Optional voucher expiration timestamp in ISO-8601 format. */
|
|
70
|
+
expiresAt: z.optional(z.string()),
|
|
71
|
+
/** Meter name for priced usage tracking. */
|
|
72
|
+
meter: z.string(),
|
|
73
|
+
/** Wallet payer bound to this voucher. */
|
|
74
|
+
payer: z.string(),
|
|
75
|
+
/** Channel recipient service wallet. */
|
|
76
|
+
recipient: z.string(),
|
|
77
|
+
/** Monotonic sequence number for replay protection. */
|
|
78
|
+
sequence: z.number(),
|
|
79
|
+
/** Server-provided nonce for challenge binding. */
|
|
80
|
+
serverNonce: z.string(),
|
|
81
|
+
/** Meter units associated with this authorization update. */
|
|
82
|
+
units: z.string(),
|
|
83
|
+
});
|
|
84
|
+
const signedVoucherSchema = z.object({
|
|
85
|
+
/** Base58/encoded signature over canonical voucher bytes. */
|
|
86
|
+
signature: z.string(),
|
|
87
|
+
/** Signature scheme discriminator (`ed25519` or `swig-session`). */
|
|
88
|
+
signatureType: z.string(),
|
|
89
|
+
/** Voucher signer public key. */
|
|
90
|
+
signer: z.string(),
|
|
91
|
+
voucher: voucherSchema,
|
|
92
|
+
});
|
|
93
|
+
/**
|
|
94
|
+
* Solana session method shared schema used by both server and client.
|
|
95
|
+
*
|
|
96
|
+
* Supports four credential actions:
|
|
97
|
+
*
|
|
98
|
+
* - **open**: opens a payment channel, records deposit, and anchors setup tx.
|
|
99
|
+
* - **update**: submits a new monotonic voucher for cumulative usage.
|
|
100
|
+
* - **topup**: increases channel escrow using a separate topup transaction.
|
|
101
|
+
* - **close**: final voucher update used to finalize channel settlement.
|
|
102
|
+
*/
|
|
103
|
+
export const session = Method.from({
|
|
104
|
+
intent: 'session',
|
|
105
|
+
name: 'solana',
|
|
106
|
+
schema: {
|
|
107
|
+
credential: {
|
|
108
|
+
payload: z.discriminatedUnion('action', [
|
|
109
|
+
z.object({
|
|
110
|
+
/** Session lifecycle action. */
|
|
111
|
+
action: z.literal('open'),
|
|
112
|
+
/** Authorization mode selected by the authorizer implementation. */
|
|
113
|
+
authorizationMode: z.string(),
|
|
114
|
+
/** Optional advertised authorizer capabilities for client hints. */
|
|
115
|
+
capabilities: z.optional(z.object({
|
|
116
|
+
/** Allowed action subset advertised by the authorizer. */
|
|
117
|
+
allowedActions: z.optional(z.array(z.string())),
|
|
118
|
+
/** Maximum cumulative authorized amount for this channel. */
|
|
119
|
+
maxCumulativeAmount: z.optional(z.string()),
|
|
120
|
+
})),
|
|
121
|
+
/** Unique channel identifier generated by the client authorizer. */
|
|
122
|
+
channelId: z.string(),
|
|
123
|
+
/** Initial escrow amount committed for this channel. */
|
|
124
|
+
depositAmount: z.string(),
|
|
125
|
+
/** Optional voucher expiration timestamp in ISO-8601 format. */
|
|
126
|
+
expiresAt: z.optional(z.string()),
|
|
127
|
+
/** On-chain transaction reference proving open/setup step. */
|
|
128
|
+
openTx: z.string(),
|
|
129
|
+
/** Wallet payer for this channel (base58 public key). */
|
|
130
|
+
payer: z.string(),
|
|
131
|
+
/** Signed session voucher payload for open action. */
|
|
132
|
+
voucher: signedVoucherSchema,
|
|
133
|
+
}),
|
|
134
|
+
z.object({
|
|
135
|
+
/** Session lifecycle action. */
|
|
136
|
+
action: z.literal('update'),
|
|
137
|
+
/** Existing channel identifier targeted by this update. */
|
|
138
|
+
channelId: z.string(),
|
|
139
|
+
/** Signed session voucher payload for usage update. */
|
|
140
|
+
voucher: signedVoucherSchema,
|
|
141
|
+
}),
|
|
142
|
+
z.object({
|
|
143
|
+
/** Session lifecycle action. */
|
|
144
|
+
action: z.literal('topup'),
|
|
145
|
+
/** Additional escrow amount to add to channel deposit. */
|
|
146
|
+
additionalAmount: z.string(),
|
|
147
|
+
/** Existing channel identifier targeted by this topup. */
|
|
148
|
+
channelId: z.string(),
|
|
149
|
+
/** On-chain transaction reference proving topup execution. */
|
|
150
|
+
topupTx: z.string(),
|
|
151
|
+
}),
|
|
152
|
+
z.object({
|
|
153
|
+
/** Session lifecycle action. */
|
|
154
|
+
action: z.literal('close'),
|
|
155
|
+
/** Existing channel identifier targeted by this close. */
|
|
156
|
+
channelId: z.string(),
|
|
157
|
+
/** Optional on-chain settlement transaction reference for this close. */
|
|
158
|
+
closeTx: z.optional(z.string()),
|
|
159
|
+
/** Signed final voucher payload for close action. */
|
|
160
|
+
voucher: signedVoucherSchema,
|
|
161
|
+
}),
|
|
162
|
+
]),
|
|
163
|
+
},
|
|
164
|
+
request: z.object({
|
|
165
|
+
asset: z.object({
|
|
166
|
+
/** Token decimals for amount normalization. */
|
|
167
|
+
decimals: z.number(),
|
|
168
|
+
/** Asset kind: native SOL or SPL token. */
|
|
169
|
+
kind: z.string(),
|
|
170
|
+
/** SPL mint address when kind is `spl`. */
|
|
171
|
+
mint: z.optional(z.string()),
|
|
172
|
+
/** Optional ticker/symbol used for display. */
|
|
173
|
+
symbol: z.optional(z.string()),
|
|
174
|
+
}),
|
|
175
|
+
/** Channel program address used to verify vouchers and actions. */
|
|
176
|
+
channelProgram: z.string(),
|
|
177
|
+
/** Solana network name, for example mainnet-beta, devnet, localnet. */
|
|
178
|
+
network: z.optional(z.string()),
|
|
179
|
+
/** Optional pricing contract used to derive debit increments. */
|
|
180
|
+
pricing: z.optional(z.object({
|
|
181
|
+
/** Price per unit in asset base units. */
|
|
182
|
+
amountPerUnit: z.string(),
|
|
183
|
+
/** Meter identifier for usage accounting. */
|
|
184
|
+
meter: z.string(),
|
|
185
|
+
/** Optional minimum debit to apply per request. */
|
|
186
|
+
minDebit: z.optional(z.string()),
|
|
187
|
+
/** Logical unit name charged by the service. */
|
|
188
|
+
unit: z.string(),
|
|
189
|
+
})),
|
|
190
|
+
/** Service recipient wallet that receives settlement funds. */
|
|
191
|
+
recipient: z.string(),
|
|
192
|
+
/** Optional server hints for default session behavior. */
|
|
193
|
+
sessionDefaults: z.optional(z.object({
|
|
194
|
+
/** Optional close behavior hint for client UX. */
|
|
195
|
+
closeBehavior: z.optional(z.string()),
|
|
196
|
+
/** Optional settlement cadence policy hints. */
|
|
197
|
+
settleInterval: z.optional(z.object({
|
|
198
|
+
kind: z.string(),
|
|
199
|
+
minIncrement: z.optional(z.string()),
|
|
200
|
+
seconds: z.optional(z.number()),
|
|
201
|
+
})),
|
|
202
|
+
/** Suggested channel deposit to use on auto-open. */
|
|
203
|
+
suggestedDeposit: z.optional(z.string()),
|
|
204
|
+
/** Suggested time-to-live for channel/session in seconds. */
|
|
205
|
+
ttlSeconds: z.optional(z.number()),
|
|
206
|
+
})),
|
|
207
|
+
/** Optional server-side verifier policy hints. */
|
|
208
|
+
verifier: z.optional(z.object({
|
|
209
|
+
/** Supported authorization modes for this endpoint. */
|
|
210
|
+
acceptAuthorizationModes: z.optional(z.array(z.string())),
|
|
211
|
+
/** Maximum allowable client/server clock skew in seconds. */
|
|
212
|
+
maxClockSkewSeconds: z.optional(z.number()),
|
|
213
|
+
})),
|
|
214
|
+
}),
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
//# sourceMappingURL=Methods.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Methods.js","sourceRoot":"","sources":["../sdk/src/Methods.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,MAAM,CAAC;AAEjC;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,MAAM,GA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AkD;YAClD,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAChB,CAAC,CAAC,MAAM,CAAC;gBACL,uDAAuD;gBACvD,wBAAwB,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;gBACzD,6DAA6D;gBAC7D,mBAAmB,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;aAC9C,CAAC,CACL;SACJ,CAAC;KACL;CACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { type TransactionSigner } from '@solana/kit';
|
|
2
|
+
import { Method } from 'mppx';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a Solana `charge` method for usage on the client.
|
|
5
|
+
*
|
|
6
|
+
* Supports two modes controlled by the `broadcast` option:
|
|
7
|
+
*
|
|
8
|
+
* - **Pull mode** (`broadcast: false`, default): Signs the transaction
|
|
9
|
+
* and sends the serialized bytes as a `type="transaction"` credential.
|
|
10
|
+
* The server broadcasts it to the Solana network.
|
|
11
|
+
*
|
|
12
|
+
* - **Push mode** (`broadcast: true`): Signs, broadcasts, confirms
|
|
13
|
+
* the transaction on-chain, and sends the signature as a `type="signature"`
|
|
14
|
+
* credential. Cannot be used with fee sponsorship.
|
|
15
|
+
*
|
|
16
|
+
* When the server advertises `feePayer: true` in the challenge, the client
|
|
17
|
+
* sets the server's `feePayerKey` as the transaction fee payer and partially
|
|
18
|
+
* signs (transfer authority only). The server adds its fee payer signature
|
|
19
|
+
* before broadcasting.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { Mppx, solana } from 'solana-mpp-sdk/client'
|
|
24
|
+
*
|
|
25
|
+
* const method = solana.charge({ signer, rpcUrl: 'https://api.devnet.solana.com' })
|
|
26
|
+
* const mppx = Mppx.create({ methods: [method] })
|
|
27
|
+
*
|
|
28
|
+
* const response = await mppx.fetch('https://api.example.com/paid-content')
|
|
29
|
+
* console.log(await response.json())
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function charge(parameters: charge.Parameters): Method.Client<{
|
|
33
|
+
readonly intent: "charge";
|
|
34
|
+
readonly name: "solana";
|
|
35
|
+
readonly schema: {
|
|
36
|
+
readonly credential: {
|
|
37
|
+
readonly payload: import("zod/mini").ZodMiniObject<{
|
|
38
|
+
signature: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
|
|
39
|
+
transaction: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
|
|
40
|
+
type: import("zod/mini").ZodMiniString<string>;
|
|
41
|
+
}, import("zod/v4/core").$strip>;
|
|
42
|
+
};
|
|
43
|
+
readonly request: import("zod/mini").ZodMiniObject<{
|
|
44
|
+
amount: import("zod/mini").ZodMiniString<string>;
|
|
45
|
+
currency: import("zod/mini").ZodMiniString<string>;
|
|
46
|
+
description: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
|
|
47
|
+
externalId: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
|
|
48
|
+
methodDetails: import("zod/mini").ZodMiniObject<{
|
|
49
|
+
decimals: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniNumber<number>>;
|
|
50
|
+
feePayer: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniBoolean<boolean>>;
|
|
51
|
+
feePayerKey: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
|
|
52
|
+
network: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
|
|
53
|
+
recentBlockhash: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
|
|
54
|
+
reference: import("zod/mini").ZodMiniString<string>;
|
|
55
|
+
splToken: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
|
|
56
|
+
tokenProgram: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
|
|
57
|
+
}, import("zod/v4/core").$strip>;
|
|
58
|
+
recipient: import("zod/mini").ZodMiniString<string>;
|
|
59
|
+
}, import("zod/v4/core").$strip>;
|
|
60
|
+
};
|
|
61
|
+
}, undefined>;
|
|
62
|
+
export declare namespace charge {
|
|
63
|
+
type Parameters = {
|
|
64
|
+
/**
|
|
65
|
+
* If true, the client broadcasts the transaction and sends the signature
|
|
66
|
+
* as a `type="signature"` credential. If false (default), the client sends
|
|
67
|
+
* the signed transaction bytes as a `type="transaction"` credential and the
|
|
68
|
+
* server broadcasts it.
|
|
69
|
+
*
|
|
70
|
+
* Cannot be used with server fee sponsorship (feePayer mode).
|
|
71
|
+
*/
|
|
72
|
+
broadcast?: boolean;
|
|
73
|
+
/** Compute unit limit. Defaults to 50,000. */
|
|
74
|
+
computeUnitLimit?: number;
|
|
75
|
+
/** Compute unit price in micro-lamports for priority fees. Defaults to 1. */
|
|
76
|
+
computeUnitPrice?: bigint;
|
|
77
|
+
/** Called at each step of the payment process. */
|
|
78
|
+
onProgress?: (event: ProgressEvent) => void;
|
|
79
|
+
/** Custom RPC URL. If not set, inferred from the challenge's network field. */
|
|
80
|
+
rpcUrl?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Solana transaction signer. Compatible with:
|
|
83
|
+
* - ConnectorKit's `useTransactionSigner()` hook
|
|
84
|
+
* - `createKeyPairSignerFromBytes()` from `@solana/kit` for headless usage
|
|
85
|
+
* - Solana Keychain's `SolanaSigner` for remote signers
|
|
86
|
+
* - Any `TransactionSigner` implementation
|
|
87
|
+
*/
|
|
88
|
+
signer: TransactionSigner;
|
|
89
|
+
};
|
|
90
|
+
type ProgressEvent = {
|
|
91
|
+
amount: string;
|
|
92
|
+
currency: string;
|
|
93
|
+
feePayerKey?: string;
|
|
94
|
+
recipient: string;
|
|
95
|
+
splToken?: string;
|
|
96
|
+
type: 'challenge';
|
|
97
|
+
} | {
|
|
98
|
+
signature: string;
|
|
99
|
+
type: 'confirming';
|
|
100
|
+
} | {
|
|
101
|
+
signature: string;
|
|
102
|
+
type: 'paid';
|
|
103
|
+
} | {
|
|
104
|
+
transaction: string;
|
|
105
|
+
type: 'signed';
|
|
106
|
+
} | {
|
|
107
|
+
type: 'paying';
|
|
108
|
+
} | {
|
|
109
|
+
type: 'signing';
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=Charge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Charge.d.ts","sourceRoot":"","sources":["../../sdk/src/client/Charge.ts"],"names":[],"mappings":"AAAA,OAAO,EAkBH,KAAK,iBAAiB,EACzB,MAAM,aAAa,CAAC;AAQrB,OAAO,EAAc,MAAM,EAAE,MAAM,MAAM,CAAC;AAQ1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAmLnD;AAkED,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC5B,KAAK,UAAU,GAAG;QACd;;;;;;;WAOG;QACH,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,8CAA8C;QAC9C,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,6EAA6E;QAC7E,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,kDAAkD;QAClD,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;QAC5C,+EAA+E;QAC/E,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB;;;;;;WAMG;QACH,MAAM,EAAE,iBAAiB,CAAC;KAC7B,CAAC;IAEF,KAAK,aAAa,GACZ;QACI,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,IAAI,EAAE,WAAW,CAAC;KACrB,GACD;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,YAAY,CAAA;KAAE,GACzC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GACnC;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,QAAQ,CAAA;KAAE,GACvC;QAAE,IAAI,EAAE,QAAQ,CAAA;KAAE,GAClB;QAAE,IAAI,EAAE,SAAS,CAAA;KAAE,CAAC;CAC7B"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { AccountRole, address, appendTransactionMessageInstructions, createSolanaRpc, createTransactionMessage, getBase64EncodedWireTransaction, partiallySignTransactionMessageWithSigners, pipe, prependTransactionMessageInstructions, setTransactionMessageFeePayer, setTransactionMessageFeePayerSigner, setTransactionMessageLifetimeUsingBlockhash, signature as toSignature, signTransactionMessageWithSigners, } from '@solana/kit';
|
|
2
|
+
import { getSetComputeUnitLimitInstruction, getSetComputeUnitPriceInstruction } from '@solana-program/compute-budget';
|
|
3
|
+
import { getTransferSolInstruction } from '@solana-program/system';
|
|
4
|
+
import { findAssociatedTokenPda, getCreateAssociatedTokenIdempotentInstruction, getTransferCheckedInstruction, } from '@solana-program/token';
|
|
5
|
+
import { Credential, Method } from 'mppx';
|
|
6
|
+
import { ASSOCIATED_TOKEN_PROGRAM, DEFAULT_RPC_URLS, TOKEN_PROGRAM } from '../constants.js';
|
|
7
|
+
import * as Methods from '../Methods.js';
|
|
8
|
+
const MEMO_PROGRAM = 'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr';
|
|
9
|
+
const textEncoder = new TextEncoder();
|
|
10
|
+
/**
|
|
11
|
+
* Creates a Solana `charge` method for usage on the client.
|
|
12
|
+
*
|
|
13
|
+
* Supports two modes controlled by the `broadcast` option:
|
|
14
|
+
*
|
|
15
|
+
* - **Pull mode** (`broadcast: false`, default): Signs the transaction
|
|
16
|
+
* and sends the serialized bytes as a `type="transaction"` credential.
|
|
17
|
+
* The server broadcasts it to the Solana network.
|
|
18
|
+
*
|
|
19
|
+
* - **Push mode** (`broadcast: true`): Signs, broadcasts, confirms
|
|
20
|
+
* the transaction on-chain, and sends the signature as a `type="signature"`
|
|
21
|
+
* credential. Cannot be used with fee sponsorship.
|
|
22
|
+
*
|
|
23
|
+
* When the server advertises `feePayer: true` in the challenge, the client
|
|
24
|
+
* sets the server's `feePayerKey` as the transaction fee payer and partially
|
|
25
|
+
* signs (transfer authority only). The server adds its fee payer signature
|
|
26
|
+
* before broadcasting.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { Mppx, solana } from 'solana-mpp-sdk/client'
|
|
31
|
+
*
|
|
32
|
+
* const method = solana.charge({ signer, rpcUrl: 'https://api.devnet.solana.com' })
|
|
33
|
+
* const mppx = Mppx.create({ methods: [method] })
|
|
34
|
+
*
|
|
35
|
+
* const response = await mppx.fetch('https://api.example.com/paid-content')
|
|
36
|
+
* console.log(await response.json())
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export function charge(parameters) {
|
|
40
|
+
const { signer, broadcast = false, onProgress } = parameters;
|
|
41
|
+
const method = Method.toClient(Methods.charge, {
|
|
42
|
+
async createCredential({ challenge }) {
|
|
43
|
+
const { amount, currency, recipient, methodDetails } = challenge.request;
|
|
44
|
+
const { network, splToken, decimals, reference, tokenProgram: tokenProgramAddr, feePayer: serverPaysFees, feePayerKey, recentBlockhash: serverBlockhash, } = methodDetails;
|
|
45
|
+
const rpcUrl = parameters.rpcUrl ?? DEFAULT_RPC_URLS[network || 'mainnet-beta'] ?? DEFAULT_RPC_URLS['mainnet-beta'];
|
|
46
|
+
const rpc = createSolanaRpc(rpcUrl);
|
|
47
|
+
onProgress?.({
|
|
48
|
+
amount,
|
|
49
|
+
currency: currency || (splToken ? 'token' : 'SOL'),
|
|
50
|
+
feePayerKey: feePayerKey || undefined,
|
|
51
|
+
recipient,
|
|
52
|
+
splToken: splToken || undefined,
|
|
53
|
+
type: 'challenge',
|
|
54
|
+
});
|
|
55
|
+
const useServerFeePayer = serverPaysFees && feePayerKey && !broadcast;
|
|
56
|
+
// Build transfer instructions.
|
|
57
|
+
const instructions = [];
|
|
58
|
+
if (splToken) {
|
|
59
|
+
// ── SPL token transfer ──
|
|
60
|
+
const mint = address(splToken);
|
|
61
|
+
const tokenProg = address(tokenProgramAddr || TOKEN_PROGRAM);
|
|
62
|
+
const [sourceAta] = await findAssociatedTokenPda({
|
|
63
|
+
mint,
|
|
64
|
+
owner: signer.address,
|
|
65
|
+
tokenProgram: tokenProg,
|
|
66
|
+
});
|
|
67
|
+
const [destAta] = await findAssociatedTokenPda({
|
|
68
|
+
mint,
|
|
69
|
+
owner: address(recipient),
|
|
70
|
+
tokenProgram: tokenProg,
|
|
71
|
+
});
|
|
72
|
+
// Create destination ATA if it doesn't exist (idempotent).
|
|
73
|
+
// WARNING: When the server is fee payer, it pays ~0.002 SOL rent for ATA
|
|
74
|
+
// creation. The recipient can close the ATA to reclaim rent, then the next
|
|
75
|
+
// payment re-creates it — repeatedly draining the fee payer. Servers SHOULD
|
|
76
|
+
// verify the ATA exists before signing, or require recipients to pre-create
|
|
77
|
+
// their ATAs, or factor rent cost into pricing.
|
|
78
|
+
if (useServerFeePayer) {
|
|
79
|
+
// In fee payer mode, the server's key pays ATA rent.
|
|
80
|
+
// We build the instruction manually since the payer isn't a local signer.
|
|
81
|
+
instructions.push(createAssociatedTokenAccountIdempotent(address(feePayerKey), address(recipient), mint, destAta, tokenProg));
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
// Standard mode: client pays ATA rent via Codama-generated instruction.
|
|
85
|
+
instructions.push(getCreateAssociatedTokenIdempotentInstruction({
|
|
86
|
+
ata: destAta,
|
|
87
|
+
mint,
|
|
88
|
+
owner: address(recipient),
|
|
89
|
+
payer: signer,
|
|
90
|
+
tokenProgram: tokenProg,
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
instructions.push(getTransferCheckedInstruction({
|
|
94
|
+
amount: BigInt(amount),
|
|
95
|
+
authority: signer,
|
|
96
|
+
decimals: decimals ?? 6,
|
|
97
|
+
destination: destAta,
|
|
98
|
+
mint,
|
|
99
|
+
source: sourceAta,
|
|
100
|
+
}, { programAddress: tokenProg }));
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
// ── Native SOL transfer ──
|
|
104
|
+
instructions.push(getTransferSolInstruction({
|
|
105
|
+
amount: BigInt(amount),
|
|
106
|
+
destination: address(recipient),
|
|
107
|
+
source: signer,
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
if (reference?.trim()) {
|
|
111
|
+
instructions.push(createReferenceMemoInstruction(reference));
|
|
112
|
+
}
|
|
113
|
+
onProgress?.({ type: 'signing' });
|
|
114
|
+
// Use server-provided blockhash if available, otherwise fetch one.
|
|
115
|
+
const latestBlockhash = serverBlockhash
|
|
116
|
+
? {
|
|
117
|
+
blockhash: serverBlockhash,
|
|
118
|
+
lastValidBlockHeight: BigInt(0), // Server doesn't provide this; tx lifetime is managed by the blockhash itself.
|
|
119
|
+
}
|
|
120
|
+
: (await rpc.getLatestBlockhash().send()).value;
|
|
121
|
+
const txMessage = pipe(createTransactionMessage({ version: 0 }), msg => useServerFeePayer
|
|
122
|
+
? setTransactionMessageFeePayer(address(feePayerKey), msg)
|
|
123
|
+
: setTransactionMessageFeePayerSigner(signer, msg), msg => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, msg), msg => appendTransactionMessageInstructions(instructions, msg),
|
|
124
|
+
// Prepend compute budget instructions per best practice.
|
|
125
|
+
msg => prependTransactionMessageInstructions([
|
|
126
|
+
getSetComputeUnitPriceInstruction({ microLamports: parameters.computeUnitPrice ?? 1n }),
|
|
127
|
+
getSetComputeUnitLimitInstruction({ units: parameters.computeUnitLimit ?? 50_000 }),
|
|
128
|
+
], msg));
|
|
129
|
+
// When server pays fees, partially sign (only the transfer authority).
|
|
130
|
+
// The server will add its fee payer signature before broadcasting.
|
|
131
|
+
const signedTx = useServerFeePayer
|
|
132
|
+
? await partiallySignTransactionMessageWithSigners(txMessage)
|
|
133
|
+
: await signTransactionMessageWithSigners(txMessage);
|
|
134
|
+
const encodedTx = getBase64EncodedWireTransaction(signedTx);
|
|
135
|
+
if (broadcast) {
|
|
136
|
+
// ── Push mode (type="signature") ──
|
|
137
|
+
onProgress?.({ type: 'paying' });
|
|
138
|
+
const signature = await rpc
|
|
139
|
+
.sendTransaction(encodedTx, {
|
|
140
|
+
encoding: 'base64',
|
|
141
|
+
skipPreflight: false,
|
|
142
|
+
})
|
|
143
|
+
.send();
|
|
144
|
+
onProgress?.({ signature, type: 'confirming' });
|
|
145
|
+
await confirmTransaction(rpc, signature);
|
|
146
|
+
onProgress?.({ signature, type: 'paid' });
|
|
147
|
+
return Credential.serialize({
|
|
148
|
+
challenge,
|
|
149
|
+
payload: { signature, type: 'signature' },
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
// ── Pull mode (type="transaction", default) ──
|
|
153
|
+
onProgress?.({ transaction: encodedTx, type: 'signed' });
|
|
154
|
+
return Credential.serialize({
|
|
155
|
+
challenge,
|
|
156
|
+
payload: { transaction: encodedTx, type: 'transaction' },
|
|
157
|
+
});
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
return method;
|
|
161
|
+
}
|
|
162
|
+
// ── Helpers ──
|
|
163
|
+
/**
|
|
164
|
+
* Creates an Associated Token Account using the idempotent instruction
|
|
165
|
+
* (CreateIdempotent = discriminator 1). This is a no-op if the ATA exists.
|
|
166
|
+
*
|
|
167
|
+
* Used in fee payer mode where the payer is the server's key (not a local
|
|
168
|
+
* signer). The server adds its signature before broadcasting.
|
|
169
|
+
*/
|
|
170
|
+
function createAssociatedTokenAccountIdempotent(payer, owner, mint, ata, tokenProgram) {
|
|
171
|
+
return {
|
|
172
|
+
accounts: [
|
|
173
|
+
{ address: payer, role: AccountRole.WRITABLE_SIGNER },
|
|
174
|
+
{ address: ata, role: AccountRole.WRITABLE },
|
|
175
|
+
{ address: owner, role: AccountRole.READONLY },
|
|
176
|
+
{ address: mint, role: AccountRole.READONLY },
|
|
177
|
+
{ address: address('11111111111111111111111111111111'), role: AccountRole.READONLY },
|
|
178
|
+
{ address: tokenProgram, role: AccountRole.READONLY },
|
|
179
|
+
],
|
|
180
|
+
data: new Uint8Array([1]),
|
|
181
|
+
programAddress: address(ASSOCIATED_TOKEN_PROGRAM), // CreateIdempotent discriminator
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Adds challenge reference as memo to make rapid identical payments unique
|
|
186
|
+
* per challenge (important for local simnets such as Surfpool).
|
|
187
|
+
*/
|
|
188
|
+
function createReferenceMemoInstruction(reference) {
|
|
189
|
+
return {
|
|
190
|
+
accounts: [],
|
|
191
|
+
data: textEncoder.encode(`mppx:${reference}`),
|
|
192
|
+
programAddress: address(MEMO_PROGRAM),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Polls for transaction confirmation via getSignatureStatuses.
|
|
197
|
+
* Only used in push mode.
|
|
198
|
+
*/
|
|
199
|
+
async function confirmTransaction(rpc, signature, timeoutMs = 30_000) {
|
|
200
|
+
const start = Date.now();
|
|
201
|
+
while (Date.now() - start < timeoutMs) {
|
|
202
|
+
const { value } = await rpc.getSignatureStatuses([toSignature(signature)]).send();
|
|
203
|
+
const status = value[0];
|
|
204
|
+
if (status) {
|
|
205
|
+
if (status.err) {
|
|
206
|
+
throw new Error(`Transaction failed: ${JSON.stringify(status.err)}`);
|
|
207
|
+
}
|
|
208
|
+
if (status.confirmationStatus === 'confirmed' || status.confirmationStatus === 'finalized') {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
await new Promise(r => setTimeout(r, 2_000));
|
|
213
|
+
}
|
|
214
|
+
throw new Error('Transaction confirmation timeout');
|
|
215
|
+
}
|
|
216
|
+
//# sourceMappingURL=Charge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Charge.js","sourceRoot":"","sources":["../../sdk/src/client/Charge.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EAEX,OAAO,EACP,oCAAoC,EAEpC,eAAe,EACf,wBAAwB,EACxB,+BAA+B,EAE/B,0CAA0C,EAC1C,IAAI,EACJ,qCAAqC,EACrC,6BAA6B,EAC7B,mCAAmC,EACnC,2CAA2C,EAC3C,SAAS,IAAI,WAAW,EACxB,iCAAiC,GAEpC,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,iCAAiC,EAAE,iCAAiC,EAAE,MAAM,gCAAgC,CAAC;AACtH,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EACH,sBAAsB,EACtB,6CAA6C,EAC7C,6BAA6B,GAChC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE1C,OAAO,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC5F,OAAO,KAAK,OAAO,MAAM,eAAe,CAAC;AAEzC,MAAM,YAAY,GAAG,6CAA6C,CAAC;AACnE,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,MAAM,CAAC,UAA6B;IAChD,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,KAAK,EAAE,UAAU,EAAE,GAAG,UAAU,CAAC;IAE7D,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE;QAC3C,KAAK,CAAC,gBAAgB,CAAC,EAAE,SAAS,EAAE;YAChC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,S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CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YACzE,CAAC;YACD,IAAI,MAAM,CAAC,kBAAkB,KAAK,WAAW,IAAI,MAAM,CAAC,kBAAkB,KAAK,WAAW,EAAE,CAAC;gBACzF,OAAO;YACX,CAAC;QACL,CAAC;QACD,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;IACjD,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { charge as charge_ } from './Charge.js';
|
|
2
|
+
import { session as session_ } from './Session.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a Solana `charge` method for usage on the client.
|
|
5
|
+
*
|
|
6
|
+
* Intercepts 402 responses, sends a Solana transaction to pay the challenge,
|
|
7
|
+
* and retries with the transaction signature as credential automatically.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { Mppx, solana } from 'solana-mpp-sdk/client'
|
|
12
|
+
*
|
|
13
|
+
* const method = solana.charge({ signer })
|
|
14
|
+
* const mppx = Mppx.create({ methods: [method] })
|
|
15
|
+
*
|
|
16
|
+
* const response = await mppx.fetch('https://api.example.com/paid-content')
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const solana: {
|
|
20
|
+
(parameters: solana.Parameters): ReturnType<typeof charge_>;
|
|
21
|
+
charge: typeof charge_;
|
|
22
|
+
session: typeof session_;
|
|
23
|
+
};
|
|
24
|
+
export declare namespace solana {
|
|
25
|
+
type Parameters = charge_.Parameters;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=Methods.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Methods.d.ts","sourceRoot":"","sources":["../../sdk/src/client/Methods.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEnD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,MAAM,EAAE;IACjB,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,GAAG,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC;IAC5D,MAAM,EAAE,OAAO,OAAO,CAAC;IACvB,OAAO,EAAE,OAAO,QAAQ,CAAC;CAI3B,CAAC;AAEH,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC5B,KAAK,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;CACxC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { charge as charge_ } from './Charge.js';
|
|
2
|
+
import { session as session_ } from './Session.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a Solana `charge` method for usage on the client.
|
|
5
|
+
*
|
|
6
|
+
* Intercepts 402 responses, sends a Solana transaction to pay the challenge,
|
|
7
|
+
* and retries with the transaction signature as credential automatically.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { Mppx, solana } from 'solana-mpp-sdk/client'
|
|
12
|
+
*
|
|
13
|
+
* const method = solana.charge({ signer })
|
|
14
|
+
* const mppx = Mppx.create({ methods: [method] })
|
|
15
|
+
*
|
|
16
|
+
* const response = await mppx.fetch('https://api.example.com/paid-content')
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export const solana = Object.assign((parameters) => charge_(parameters), {
|
|
20
|
+
charge: charge_,
|
|
21
|
+
session: session_,
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=Methods.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Methods.js","sourceRoot":"","sources":["../../sdk/src/client/Methods.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEnD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,MAAM,GAIf,MAAM,CAAC,MAAM,CAAC,CAAC,UAA6B,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;IACtE,MAAM,EAAE,OAAO;IACf,OAAO,EAAE,QAAQ;CACpB,CAAC,CAAC"}
|