better-auth-solana-payments 0.3.0 → 0.4.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/README.md +12 -4
- package/dist/client.d.mts +3 -1
- package/dist/client.d.mts.map +1 -1
- package/dist/client.mjs +1 -1
- package/dist/client.mjs.map +1 -1
- package/dist/{index-OBNQULwf.d.mts → index-DlPQtl6v.d.mts} +7 -4
- package/dist/{index-OBNQULwf.d.mts.map → index-DlPQtl6v.d.mts.map} +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +20 -4
- package/dist/index.mjs.map +1 -1
- package/dist/version-B5dtK-2_.mjs +6 -0
- package/dist/version-B5dtK-2_.mjs.map +1 -0
- package/package.json +2 -2
- package/dist/version-L8AhU29A.mjs +0 -6
- package/dist/version-L8AhU29A.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -84,10 +84,18 @@ Amounts are decimal strings in the configured token's display units (for example
|
|
|
84
84
|
2.5 USDT with the default six-decimal USDT token). Do not pass JavaScript numbers, which can lose
|
|
85
85
|
precision for token amounts.
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
If the wallet already returned a transaction signature, send it as the optional `signature` field
|
|
88
|
+
to `payment.verify`. The SDK checks that candidate before scanning recent transactions, while still
|
|
89
|
+
verifying the configured mint, recipient, amount, cluster and confirmation commitment. The plugin
|
|
90
|
+
inherits the token program configured on the server's SDK client. Basic Token-2022 transfers are
|
|
91
|
+
supported; transfer-fee and transfer-hook mints need extension-aware verification and are not
|
|
92
|
+
accepted as ordinary transfers. See Solana's [payment verification guidance](https://solana.com/docs/payments/accept-payments/verification-tools)
|
|
93
|
+
and [Token Extensions documentation](https://solana.com/docs/tokens/extensions) when configuring a mint.
|
|
94
|
+
|
|
95
|
+
The browser may supply the amount, optional metadata, reference, optional transaction signature,
|
|
96
|
+
and optional organization ID. The server controls the recipient and token configuration, so clients
|
|
97
|
+
cannot redirect funds or choose another mint. The integration uses a read-only RPC client: it stores
|
|
98
|
+
no private keys and never signs or sends a transaction on behalf of a customer.
|
|
91
99
|
|
|
92
100
|
This package supports one-time payments only. It does not create recurring subscriptions or
|
|
93
101
|
perform recurring charges.
|
package/dist/client.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as solanaPayments } from "./index-
|
|
1
|
+
import { t as solanaPayments } from "./index-DlPQtl6v.mjs";
|
|
2
2
|
import { BetterFetch, BetterFetchOption, BetterFetchResponse } from "@better-fetch/fetch";
|
|
3
3
|
import { BetterAuthClientPlugin } from "better-auth/client";
|
|
4
4
|
//#region src/client.d.ts
|
|
@@ -13,6 +13,7 @@ export interface SolanaPaymentResponse {
|
|
|
13
13
|
decimals: number;
|
|
14
14
|
recipient: string;
|
|
15
15
|
status: "pending" | "paid" | "expired" | "failed";
|
|
16
|
+
fulfillmentStatus?: "pending" | "processing" | "completed";
|
|
16
17
|
expiresAt: Date;
|
|
17
18
|
signature?: string;
|
|
18
19
|
slot?: string;
|
|
@@ -27,6 +28,7 @@ export interface SolanaPaymentActions {
|
|
|
27
28
|
}, options?: O) => Promise<FetchResult<SolanaPaymentResponse, O>>;
|
|
28
29
|
verify: <O extends BetterFetchOption | undefined = undefined>(data: {
|
|
29
30
|
reference: string;
|
|
31
|
+
signature?: string;
|
|
30
32
|
organizationId?: string;
|
|
31
33
|
}, options?: O) => Promise<FetchResult<SolanaPaymentResponse, O>>;
|
|
32
34
|
get: <O extends BetterFetchOption | undefined = undefined>(data: {
|
package/dist/client.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.mts","names":["solanaPaymentsServer"],"sources":["../src/client.ts"],"mappings":";;;;YAMY,YAAY,GAAG,UAAU,iCAAiC;EAAY;IAC9E,IACA,oBAAoB;iBAEP;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA,WAAW;EACX;EACA;EACA,WAAW;EACX;;iBAGe;EACf,SAAS,UAAU,2CACjB;IACE;IACA,WAAW;IACX;KAEF,UAAU,MACP,QAAQ,YAAY,uBAAuB;EAChD,SAAS,UAAU,2CACjB;IAAQ;IAAmB;
|
|
1
|
+
{"version":3,"file":"client.d.mts","names":["solanaPaymentsServer"],"sources":["../src/client.ts"],"mappings":";;;;YAMY,YAAY,GAAG,UAAU,iCAAiC;EAAY;IAC9E,IACA,oBAAoB;iBAEP;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,WAAW;EACX;EACA;EACA,WAAW;EACX;;iBAGe;EACf,SAAS,UAAU,2CACjB;IACE;IACA,WAAW;IACX;KAEF,UAAU,MACP,QAAQ,YAAY,uBAAuB;EAChD,SAAS,UAAU,2CACjB;IAAQ;IAAmB;IAAoB;KAC/C,UAAU,MACP,QAAQ,YAAY,uBAAuB;EAChD,MAAM,UAAU,2CACd;IAAQ;IAAmB;KAC3B,UAAU,MACP,QAAQ,YAAY,uBAAuB;;iBAGjC;EACf,SAAS;;;YAIC;IACR,SAAS;;;;YAKD;IACR,gBAAgB,kBAAkB;;;KAIjC,qCAAqC,KACxC;EAGA;EACA,oBAAoB,kBAAkBA;EACtC,aACE,QAAQ,aACR,iBACA,qBACG;;qBAGM,4BAA2B"}
|
package/dist/client.mjs
CHANGED
package/dist/client.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.mjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import type { BetterFetch, BetterFetchOption, BetterFetchResponse } from \"@better-fetch/fetch\";\nimport type { BetterAuthClientPlugin } from \"better-auth/client\";\n\nimport type { solanaPayments as solanaPaymentsServer } from \"./index.ts\";\nimport { PACKAGE_VERSION } from \"./version.ts\";\n\nexport type FetchResult<T, O extends BetterFetchOption | undefined> = O extends { throw: true }\n ? T\n : BetterFetchResponse<T>;\n\nexport interface SolanaPaymentResponse {\n id: string;\n reference: string;\n amount: string;\n mint: string;\n decimals: number;\n recipient: string;\n status: \"pending\" | \"paid\" | \"expired\" | \"failed\";\n expiresAt: Date;\n signature?: string;\n slot?: string;\n metadata?: Record<string, unknown>;\n paymentUrl?: string;\n}\n\nexport interface SolanaPaymentActions {\n create: <O extends BetterFetchOption | undefined = undefined>(\n data: {\n amount: string;\n metadata?: Record<string, unknown>;\n organizationId?: string;\n },\n options?: O,\n ) => Promise<FetchResult<SolanaPaymentResponse, O>>;\n verify: <O extends BetterFetchOption | undefined = undefined>(\n data: { reference: string; organizationId?: string },\n options?: O,\n ) => Promise<FetchResult<SolanaPaymentResponse, O>>;\n get: <O extends BetterFetchOption | undefined = undefined>(\n data: { reference: string; organizationId?: string },\n options?: O,\n ) => Promise<FetchResult<SolanaPaymentResponse, O>>;\n}\n\nexport interface SolanaPaymentsClientActions {\n payment: SolanaPaymentActions;\n}\n\ndeclare module \"better-auth/client\" {\n interface BetterAuthClient {\n payment: SolanaPaymentActions;\n }\n}\n\ndeclare module \"better-auth\" {\n interface BetterAuthClientPlugins {\n solanaPayments: ReturnType<typeof solanaPaymentsClient>;\n }\n}\n\ntype SolanaPaymentsClientPluginInstance = Omit<\n BetterAuthClientPlugin,\n \"id\" | \"$InferServerPlugin\" | \"getActions\"\n> & {\n id: \"solanaPayments\";\n $InferServerPlugin: ReturnType<typeof solanaPaymentsServer>;\n getActions: (\n $fetch: BetterFetch,\n $store: unknown,\n options: unknown,\n ) => SolanaPaymentsClientActions;\n};\n\nexport const solanaPaymentsClient = (): SolanaPaymentsClientPluginInstance => ({\n id: \"solanaPayments\",\n version: PACKAGE_VERSION,\n $InferServerPlugin: {} as ReturnType<typeof solanaPaymentsServer>,\n pathMethods: {\n \"/solana-payments/create-payment\": \"POST\",\n \"/solana-payments/verify-payment\": \"POST\",\n \"/solana-payments/payment\": \"GET\",\n },\n getActions: ($fetch): SolanaPaymentsClientActions => ({\n payment: {\n create: (data, options) =>\n $fetch(\"/solana-payments/create-payment\", {\n ...options,\n method: \"POST\",\n body: data,\n }),\n verify: (data, options) =>\n $fetch(\"/solana-payments/verify-payment\", {\n ...options,\n method: \"POST\",\n body: data,\n }),\n get: (data, options) =>\n $fetch(\"/solana-payments/payment\", { ...options, method: \"GET\", query: data }),\n },\n }),\n});\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"client.mjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import type { BetterFetch, BetterFetchOption, BetterFetchResponse } from \"@better-fetch/fetch\";\nimport type { BetterAuthClientPlugin } from \"better-auth/client\";\n\nimport type { solanaPayments as solanaPaymentsServer } from \"./index.ts\";\nimport { PACKAGE_VERSION } from \"./version.ts\";\n\nexport type FetchResult<T, O extends BetterFetchOption | undefined> = O extends { throw: true }\n ? T\n : BetterFetchResponse<T>;\n\nexport interface SolanaPaymentResponse {\n id: string;\n reference: string;\n amount: string;\n mint: string;\n decimals: number;\n recipient: string;\n status: \"pending\" | \"paid\" | \"expired\" | \"failed\";\n fulfillmentStatus?: \"pending\" | \"processing\" | \"completed\";\n expiresAt: Date;\n signature?: string;\n slot?: string;\n metadata?: Record<string, unknown>;\n paymentUrl?: string;\n}\n\nexport interface SolanaPaymentActions {\n create: <O extends BetterFetchOption | undefined = undefined>(\n data: {\n amount: string;\n metadata?: Record<string, unknown>;\n organizationId?: string;\n },\n options?: O,\n ) => Promise<FetchResult<SolanaPaymentResponse, O>>;\n verify: <O extends BetterFetchOption | undefined = undefined>(\n data: { reference: string; signature?: string; organizationId?: string },\n options?: O,\n ) => Promise<FetchResult<SolanaPaymentResponse, O>>;\n get: <O extends BetterFetchOption | undefined = undefined>(\n data: { reference: string; organizationId?: string },\n options?: O,\n ) => Promise<FetchResult<SolanaPaymentResponse, O>>;\n}\n\nexport interface SolanaPaymentsClientActions {\n payment: SolanaPaymentActions;\n}\n\ndeclare module \"better-auth/client\" {\n interface BetterAuthClient {\n payment: SolanaPaymentActions;\n }\n}\n\ndeclare module \"better-auth\" {\n interface BetterAuthClientPlugins {\n solanaPayments: ReturnType<typeof solanaPaymentsClient>;\n }\n}\n\ntype SolanaPaymentsClientPluginInstance = Omit<\n BetterAuthClientPlugin,\n \"id\" | \"$InferServerPlugin\" | \"getActions\"\n> & {\n id: \"solanaPayments\";\n $InferServerPlugin: ReturnType<typeof solanaPaymentsServer>;\n getActions: (\n $fetch: BetterFetch,\n $store: unknown,\n options: unknown,\n ) => SolanaPaymentsClientActions;\n};\n\nexport const solanaPaymentsClient = (): SolanaPaymentsClientPluginInstance => ({\n id: \"solanaPayments\",\n version: PACKAGE_VERSION,\n $InferServerPlugin: {} as ReturnType<typeof solanaPaymentsServer>,\n pathMethods: {\n \"/solana-payments/create-payment\": \"POST\",\n \"/solana-payments/verify-payment\": \"POST\",\n \"/solana-payments/payment\": \"GET\",\n },\n getActions: ($fetch): SolanaPaymentsClientActions => ({\n payment: {\n create: (data, options) =>\n $fetch(\"/solana-payments/create-payment\", {\n ...options,\n method: \"POST\",\n body: data,\n }),\n verify: (data, options) =>\n $fetch(\"/solana-payments/verify-payment\", {\n ...options,\n method: \"POST\",\n body: data,\n }),\n get: (data, options) =>\n $fetch(\"/solana-payments/payment\", { ...options, method: \"GET\", query: data }),\n },\n }),\n});\n"],"mappings":";;AA0EA,MAAa,8BAAkE;CAC7E,IAAI;CACJ,SAAS;CACT,oBAAoB,CAAC;CACrB,aAAa;EACX,mCAAmC;EACnC,mCAAmC;EACnC,4BAA4B;CAC9B;CACA,aAAa,YAAyC,EACpD,SAAS;EACP,SAAS,MAAM,YACb,OAAO,mCAAmC;GACxC,GAAG;GACH,QAAQ;GACR,MAAM;EACR,CAAC;EACH,SAAS,MAAM,YACb,OAAO,mCAAmC;GACxC,GAAG;GACH,QAAQ;GACR,MAAM;EACR,CAAC;EACH,MAAM,MAAM,YACV,OAAO,4BAA4B;GAAE,GAAG;GAAS,QAAQ;GAAO,OAAO;EAAK,CAAC;CACjF,EACF;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GenericEndpointContext, InferOptionSchema } from "better-auth";
|
|
2
|
-
import { AddressInput,
|
|
2
|
+
import { AddressInput, SolanaPaymentsReadOnlyClient } from "solana-payments";
|
|
3
3
|
import { BetterAuthPluginDBSchema, DBFieldAttribute } from "better-auth/db";
|
|
4
4
|
//#region src/schema.d.ts
|
|
5
5
|
type SolanaPaymentSchema = Record<"solanaPayment", {
|
|
@@ -34,7 +34,7 @@ interface SolanaPayment {
|
|
|
34
34
|
updatedAt: Date;
|
|
35
35
|
}
|
|
36
36
|
interface SolanaPaymentsOptions {
|
|
37
|
-
client:
|
|
37
|
+
client: SolanaPaymentsReadOnlyClient;
|
|
38
38
|
recipient: AddressInput;
|
|
39
39
|
paymentExpirationMs?: number;
|
|
40
40
|
onPaymentComplete?: (payment: SolanaPayment, context: GenericEndpointContext) => Promise<void> | void;
|
|
@@ -45,7 +45,7 @@ interface SolanaPaymentsOptions {
|
|
|
45
45
|
}
|
|
46
46
|
//#endregion
|
|
47
47
|
//#region src/version.d.ts
|
|
48
|
-
declare const PACKAGE_VERSION = "0.
|
|
48
|
+
declare const PACKAGE_VERSION = "0.4.0";
|
|
49
49
|
//#endregion
|
|
50
50
|
//#region src/store.d.ts
|
|
51
51
|
type Adapter = {
|
|
@@ -102,6 +102,7 @@ declare function createSolanaPaymentStore(context: SolanaPaymentStoreContext): S
|
|
|
102
102
|
//#region src/index.d.ts
|
|
103
103
|
declare function solanaPayments(input: SolanaPaymentsOptions): {
|
|
104
104
|
id: "solanaPayments";
|
|
105
|
+
version: string;
|
|
105
106
|
endpoints: {
|
|
106
107
|
createPayment: import("better-auth").StrictEndpoint<"/solana-payments/create-payment", {
|
|
107
108
|
method: "POST";
|
|
@@ -152,6 +153,7 @@ declare function solanaPayments(input: SolanaPaymentsOptions): {
|
|
|
152
153
|
method: "POST";
|
|
153
154
|
body: import("zod").ZodObject<{
|
|
154
155
|
reference: import("zod").ZodString;
|
|
156
|
+
signature: import("zod").ZodOptional<import("zod").ZodString>;
|
|
155
157
|
organizationId: import("zod").ZodOptional<import("zod").ZodString>;
|
|
156
158
|
}, import("zod/v4/core").$strip>;
|
|
157
159
|
use: (import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
|
|
@@ -244,8 +246,9 @@ declare function solanaPayments(input: SolanaPaymentsOptions): {
|
|
|
244
246
|
PAYMENT_EXPIRED: import("better-auth").RawError<"PAYMENT_EXPIRED">;
|
|
245
247
|
INVALID_PAYMENT: import("better-auth").RawError<"INVALID_PAYMENT">;
|
|
246
248
|
PAYMENT_MISMATCH: import("better-auth").RawError<"PAYMENT_MISMATCH">;
|
|
249
|
+
PAYMENT_PROVIDER_UNAVAILABLE: import("better-auth").RawError<"PAYMENT_PROVIDER_UNAVAILABLE">;
|
|
247
250
|
};
|
|
248
251
|
};
|
|
249
252
|
//#endregion
|
|
250
253
|
export { SolanaPaymentStore as a, PACKAGE_VERSION as c, SolanaPaymentsOptions as d, getSchema as f, MarkPaidResult as i, SolanaPayment as l, CreateSolanaPaymentInput as n, SolanaPaymentStoreContext as o, solanaPaymentsPluginSchema as p, MarkPaidInput as r, createSolanaPaymentStore as s, solanaPayments as t, SolanaPaymentStatus as u };
|
|
251
|
-
//# sourceMappingURL=index-
|
|
254
|
+
//# sourceMappingURL=index-DlPQtl6v.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-
|
|
1
|
+
{"version":3,"file":"index-DlPQtl6v.d.mts","names":["_$__types_ts0.SolanaPaymentStatus"],"sources":["../src/schema.ts","../src/types.d.ts","../src/version.ts","../src/store.ts","../src/index.ts"],"mappings":";;;;KAIK,sBAAsB;EAGvB,QAAQ,kQAkBN;;KA6BM,6BAA6B;cAC5B,4BAA4B;iBAEzB,UACd,SAAS,KAAK,mCACb;;;KCxDS;UACK;EACb;EACA;EACA;EACA;;EAEA;EACA;EACA;EACA;EACA,QAAQ;EACR;EACA;EACA,uBAAuB;EACvB,WAAW;EACX;;EAEA;EACA;EACA,WAAW;EACX,WAAW;;UAEE;EACb,QAAQ;EACR,WAAW;EACX;EACA,qBAAqB,SAAS,eAAe,SAAS,2BAA2B;EACjF;IACI;;EAEJ,SAAS,kBAAkB;;;;cClClB;;;KCMR;EACH,OAAO,GAAG;IAAS;IAAe,MAAM,KAAK;MAAa,QAAQ;EAClE,QAAQ,GAAG;IAAS;IAAe,OAAO;MAAgB,QAAQ;EAClE,OAAO,GAAG;IAAS;IAAe,QAAQ,QAAQ;IAAI,OAAO;MAAgB,QAAQ;;KAElF;EAAgB;EAAe;;UAEnB;EACf,SAAS;EACT;IAAY;MAAS;;;EACrB;EACA;;KAGU,2BAA2B,KACrC;UAIe;EACf;EACA;;UAGe;EACf,SAAS;EACT;;UAGe;EACf,eAAe;EACf,OAAO,OAAO,2BAA2B,QAAQ;EACjD,SAAS,aAAa,QAAQ;EAC9B,gBAAgB,oBAAoB,QAAQ;EAC5C,SAAS,mBAAmB,QAAQ,gBAAgB,QAAQ;EAC5D,uBAAuB,mBAAmB,QAAQ,gBAAgB,QAAQ;EAC1E,iBAAiB,oBAAoB,QAAQ;EAC7C,kBACE,mBACA,eACA,qBACC,QAAQ;EACX,YAAY,oBAAoB,QAAQ;;iBAG1B,yBAAyB,SAAS,4BAA4B;;;iBCtB9D,eAAe,OAAO;;;;;;;;;;;;;;;;;;;;YAwBitD;YAA6C;;;;;;;;;YAAyN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAAtQ;YAA6C;;;;;;;;;YAAyN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAAtQ;YAA6C;;;;;;;;;YAAyN"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as SolanaPaymentStore, c as PACKAGE_VERSION, d as SolanaPaymentsOptions, f as getSchema, i as MarkPaidResult, l as SolanaPayment, n as CreateSolanaPaymentInput, o as SolanaPaymentStoreContext, p as solanaPaymentsPluginSchema, r as MarkPaidInput, s as createSolanaPaymentStore, t as solanaPayments, u as SolanaPaymentStatus } from "./index-
|
|
1
|
+
import { a as SolanaPaymentStore, c as PACKAGE_VERSION, d as SolanaPaymentsOptions, f as getSchema, i as MarkPaidResult, l as SolanaPayment, n as CreateSolanaPaymentInput, o as SolanaPaymentStoreContext, p as solanaPaymentsPluginSchema, r as MarkPaidInput, s as createSolanaPaymentStore, t as solanaPayments, u as SolanaPaymentStatus } from "./index-DlPQtl6v.mjs";
|
|
2
2
|
export { type CreateSolanaPaymentInput, type MarkPaidInput, type MarkPaidResult, PACKAGE_VERSION, type SolanaPayment, type SolanaPaymentStatus, type SolanaPaymentStore, type SolanaPaymentStoreContext, type SolanaPaymentsOptions, createSolanaPaymentStore, getSchema, solanaPayments, solanaPaymentsPluginSchema };
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { t as PACKAGE_VERSION } from "./version-
|
|
1
|
+
import { t as PACKAGE_VERSION } from "./version-B5dtK-2_.mjs";
|
|
2
2
|
import { defineErrorCodes } from "better-auth";
|
|
3
3
|
import { randomBytes, randomUUID } from "node:crypto";
|
|
4
4
|
import { APIError, createAuthEndpoint, getSessionFromCtx, originCheckMiddleware, sessionMiddleware } from "better-auth/api";
|
|
5
|
-
import { formatTokenAmount } from "solana-payments";
|
|
5
|
+
import { formatTokenAmount, isSolanaPaymentsError } from "solana-payments";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { mergeSchema } from "better-auth/db";
|
|
8
8
|
//#region src/store.ts
|
|
@@ -207,6 +207,8 @@ const createPaymentBody = z.object({
|
|
|
207
207
|
});
|
|
208
208
|
const verifyPaymentBody = z.object({
|
|
209
209
|
reference: z.string().min(1),
|
|
210
|
+
/** Transaction signature lets the SDK verify a candidate before scanning recent history. */
|
|
211
|
+
signature: z.string().min(1).optional(),
|
|
210
212
|
organizationId: z.string().min(1).optional()
|
|
211
213
|
});
|
|
212
214
|
const getPaymentQuery = z.object({
|
|
@@ -214,11 +216,14 @@ const getPaymentQuery = z.object({
|
|
|
214
216
|
organizationId: z.string().min(1).optional()
|
|
215
217
|
});
|
|
216
218
|
function routeError(code, message) {
|
|
217
|
-
throw new APIError(code === "MISSING_SESSION" ? "UNAUTHORIZED" : "BAD_REQUEST", {
|
|
219
|
+
throw new APIError(code === "MISSING_SESSION" ? "UNAUTHORIZED" : code === "PAYMENT_PROVIDER_UNAVAILABLE" ? "INTERNAL_SERVER_ERROR" : "BAD_REQUEST", {
|
|
218
220
|
code,
|
|
219
221
|
message
|
|
220
222
|
});
|
|
221
223
|
}
|
|
224
|
+
function assertOrganizationEnabled(options, organizationId) {
|
|
225
|
+
if (organizationId && options.organization?.enabled !== true) routeError("UNAUTHORIZED_PAYMENT", "Organization payments are not enabled.");
|
|
226
|
+
}
|
|
222
227
|
async function paymentStore(ctx, organizationId) {
|
|
223
228
|
const session = await getSessionFromCtx(ctx);
|
|
224
229
|
if (!session) routeError("MISSING_SESSION", "An authenticated session is required.");
|
|
@@ -300,6 +305,7 @@ const createPayment = (options, path = "/create-payment") => createAuthEndpoint(
|
|
|
300
305
|
body: createPaymentBody,
|
|
301
306
|
use: [sessionMiddleware, originCheckMiddleware]
|
|
302
307
|
}, async (ctx) => {
|
|
308
|
+
assertOrganizationEnabled(options, ctx.body.organizationId);
|
|
303
309
|
const store = await paymentStore(ctx, ctx.body.organizationId);
|
|
304
310
|
const reference = createReference();
|
|
305
311
|
const request = options.client.payments.createRequest({
|
|
@@ -327,6 +333,7 @@ const verifyPayment = (options, path = "/verify-payment") => createAuthEndpoint(
|
|
|
327
333
|
body: verifyPaymentBody,
|
|
328
334
|
use: [sessionMiddleware, originCheckMiddleware]
|
|
329
335
|
}, async (ctx) => {
|
|
336
|
+
assertOrganizationEnabled(options, ctx.body.organizationId);
|
|
330
337
|
const { store, payment } = await loadPayment(ctx, ctx.body.reference, ctx.body.organizationId);
|
|
331
338
|
if (payment.status === "paid") return ctx.json(asResponse(await fulfillPayment(ctx, options, store, payment)));
|
|
332
339
|
if (payment.status === "expired" || payment.expiresAt <= /* @__PURE__ */ new Date()) {
|
|
@@ -338,10 +345,16 @@ const verifyPayment = (options, path = "/verify-payment") => createAuthEndpoint(
|
|
|
338
345
|
try {
|
|
339
346
|
verified = await options.client.payments.verify({
|
|
340
347
|
reference: payment.reference,
|
|
348
|
+
...ctx.body.signature ? { signature: ctx.body.signature } : {},
|
|
341
349
|
recipient: payment.recipient,
|
|
342
350
|
amount: formatTokenAmount(payment.amount, payment.decimals)
|
|
343
351
|
});
|
|
344
352
|
} catch (error) {
|
|
353
|
+
if (isSolanaPaymentsError(error) && [
|
|
354
|
+
"RPC_ERROR",
|
|
355
|
+
"RPC_TIMEOUT",
|
|
356
|
+
"TRANSACTION_TIMEOUT"
|
|
357
|
+
].includes(error.code)) routeError("PAYMENT_PROVIDER_UNAVAILABLE", "Solana RPC could not confirm the payment. Retry verification with the same reference.");
|
|
345
358
|
routeError("PAYMENT_MISMATCH", error instanceof Error ? error.message : "Payment did not match intent.");
|
|
346
359
|
}
|
|
347
360
|
if (!verified.found || verified.reference !== payment.reference || verified.recipient !== payment.recipient || verified.amount?.toString() !== payment.amount) routeError("PAYMENT_MISMATCH", "Payment did not exactly match the stored intent.");
|
|
@@ -357,6 +370,7 @@ const getPayment = (options, path = "/payment") => createAuthEndpoint(path, {
|
|
|
357
370
|
query: getPaymentQuery,
|
|
358
371
|
use: [sessionMiddleware]
|
|
359
372
|
}, async (ctx) => {
|
|
373
|
+
assertOrganizationEnabled(options, ctx.query.organizationId);
|
|
360
374
|
const { store, payment } = await loadPayment(ctx, ctx.query.reference, ctx.query.organizationId);
|
|
361
375
|
const current = payment.status === "pending" && payment.expiresAt <= /* @__PURE__ */ new Date() ? await store.markExpired(payment.reference) : payment;
|
|
362
376
|
return ctx.json(asResponse(current ?? payment));
|
|
@@ -450,7 +464,8 @@ const ERROR_CODES = defineErrorCodes({
|
|
|
450
464
|
UNAUTHORIZED_PAYMENT: "Payment was not found for this owner.",
|
|
451
465
|
PAYMENT_EXPIRED: "Payment intent has expired.",
|
|
452
466
|
INVALID_PAYMENT: "Payment is invalid.",
|
|
453
|
-
PAYMENT_MISMATCH: "Payment did not exactly match the stored intent."
|
|
467
|
+
PAYMENT_MISMATCH: "Payment did not exactly match the stored intent.",
|
|
468
|
+
PAYMENT_PROVIDER_UNAVAILABLE: "Solana RPC could not confirm the payment; retry verification."
|
|
454
469
|
});
|
|
455
470
|
function solanaPayments(input) {
|
|
456
471
|
const normalized = input.client.payments.createRequest({
|
|
@@ -466,6 +481,7 @@ function solanaPayments(input) {
|
|
|
466
481
|
};
|
|
467
482
|
return {
|
|
468
483
|
id: "solanaPayments",
|
|
484
|
+
version: PACKAGE_VERSION,
|
|
469
485
|
endpoints: {
|
|
470
486
|
createPayment: createPayment(options, "/solana-payments/create-payment"),
|
|
471
487
|
verifyPayment: verifyPayment(options, "/solana-payments/verify-payment"),
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/store.ts","../src/routes.ts","../src/schema.ts","../src/index.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\n\nimport type { SolanaPayment } from \"./types.ts\";\n\nconst SOLANA_PAYMENT_MODEL = \"solanaPayment\";\n\ntype Adapter = {\n create<T>(input: { model: string; data: Omit<T, \"id\"> }): Promise<T>;\n findOne<T>(input: { model: string; where: WhereClause }): Promise<T | null>;\n update<T>(input: { model: string; update: Partial<T>; where: WhereClause }): Promise<T | null>;\n};\ntype WhereClause = { field: string; value: string | null }[];\n\nexport interface SolanaPaymentStoreContext {\n adapter: Adapter;\n session?: { user?: { id: string } | null } | null;\n organizationId?: string;\n hasOrganizationPlugin?: boolean;\n}\n\nexport type CreateSolanaPaymentInput = Omit<\n SolanaPayment,\n \"id\" | \"referenceType\" | \"referenceId\" | \"status\" | \"createdAt\" | \"updatedAt\"\n>;\n\nexport interface MarkPaidInput {\n signature?: string;\n slot?: string;\n}\n\nexport interface MarkPaidResult {\n payment: SolanaPayment | null;\n transitioned: boolean;\n}\n\nexport interface SolanaPaymentStore {\n assertOwner(): Promise<void>;\n create(input: CreateSolanaPaymentInput): Promise<SolanaPayment>;\n findById(id: string): Promise<SolanaPayment | null>;\n findByReference(reference: string): Promise<SolanaPayment | null>;\n markPaid(reference: string, input?: MarkPaidInput): Promise<SolanaPayment | null>;\n markPaidWithTransition(reference: string, input?: MarkPaidInput): Promise<MarkPaidResult>;\n claimFulfillment(reference: string): Promise<SolanaPayment | null>;\n finishFulfillment(\n reference: string,\n token: string,\n completed: boolean,\n ): Promise<SolanaPayment | null>;\n markExpired(reference: string): Promise<SolanaPayment | null>;\n}\n\nexport function createSolanaPaymentStore(context: SolanaPaymentStoreContext): SolanaPaymentStore {\n const getOwner = async (): Promise<{ type: \"user\" | \"organization\"; id: string }> => {\n const userId = context.session?.user?.id;\n if (!userId) throw new Error(\"A session user is required to access Solana payments\");\n\n if (!context.organizationId) return { type: \"user\", id: userId };\n if (!context.hasOrganizationPlugin) {\n throw new Error(\"The Better Auth organization plugin is required for organization payments\");\n }\n\n const member = await context.adapter.findOne<{ id: string }>({\n model: \"member\",\n where: [\n { field: \"organizationId\", value: context.organizationId },\n { field: \"userId\", value: userId },\n ],\n });\n if (!member) throw new Error(\"The session user must be an organization member\");\n return { type: \"organization\", id: context.organizationId };\n };\n\n const paymentWhere = async (where: WhereClause): Promise<WhereClause> => {\n const owner = await getOwner();\n return [\n ...where,\n { field: \"referenceType\", value: owner.type },\n { field: \"referenceId\", value: owner.id },\n ];\n };\n\n const findByReference = async (reference: string): Promise<SolanaPayment | null> =>\n context.adapter.findOne<SolanaPayment>({\n model: SOLANA_PAYMENT_MODEL,\n where: await paymentWhere([{ field: \"reference\", value: reference }]),\n });\n\n const markPaidWithTransition = async (\n reference: string,\n input: MarkPaidInput = {},\n ): Promise<MarkPaidResult> => {\n const payment = await findByReference(reference);\n if (!payment) return { payment: null, transitioned: false };\n if (payment.status === \"paid\") return { payment, transitioned: false };\n if (payment.status !== \"pending\") return { payment: null, transitioned: false };\n const updated = await context.adapter.update<SolanaPayment>({\n model: SOLANA_PAYMENT_MODEL,\n update: { status: \"paid\", ...input, updatedAt: new Date() },\n where: await paymentWhere([\n { field: \"id\", value: payment.id },\n { field: \"status\", value: \"pending\" },\n ]),\n });\n if (updated) return { payment: updated, transitioned: true };\n const current = await findByReference(reference);\n return { payment: current?.status === \"paid\" ? current : null, transitioned: false };\n };\n\n return {\n async assertOwner() {\n await getOwner();\n },\n async create(input) {\n const owner = await getOwner();\n const now = new Date();\n return context.adapter.create<SolanaPayment>({\n model: SOLANA_PAYMENT_MODEL,\n data: {\n ...input,\n referenceType: owner.type,\n referenceId: owner.id,\n status: \"pending\",\n fulfillmentStatus: \"pending\",\n fulfillmentToken: null,\n fulfillmentClaimedAt: null,\n createdAt: now,\n updatedAt: now,\n },\n });\n },\n findById: async (id) =>\n context.adapter.findOne<SolanaPayment>({\n model: SOLANA_PAYMENT_MODEL,\n where: await paymentWhere([{ field: \"id\", value: id }]),\n }),\n findByReference,\n async markPaid(reference, input = {}) {\n return (await markPaidWithTransition(reference, input)).payment;\n },\n markPaidWithTransition,\n async claimFulfillment(reference) {\n const payment = await findByReference(reference);\n if (\n !payment ||\n payment.status !== \"paid\" ||\n !payment.fulfillmentStatus ||\n payment.fulfillmentStatus === \"completed\"\n )\n return null;\n if (\n payment.fulfillmentStatus === \"processing\" &&\n payment.fulfillmentClaimedAt &&\n new Date(payment.fulfillmentClaimedAt).getTime() > Date.now() - 5 * 60_000\n )\n return null;\n return context.adapter.update<SolanaPayment>({\n model: SOLANA_PAYMENT_MODEL,\n where: await paymentWhere([\n { field: \"id\", value: payment.id },\n { field: \"fulfillmentStatus\", value: payment.fulfillmentStatus },\n { field: \"fulfillmentToken\", value: payment.fulfillmentToken ?? null },\n ]),\n update: {\n fulfillmentStatus: \"processing\",\n fulfillmentToken: randomUUID(),\n fulfillmentClaimedAt: new Date(),\n updatedAt: new Date(),\n },\n });\n },\n async finishFulfillment(reference, token, completed) {\n return context.adapter.update<SolanaPayment>({\n model: SOLANA_PAYMENT_MODEL,\n where: await paymentWhere([\n { field: \"reference\", value: reference },\n { field: \"fulfillmentToken\", value: token },\n { field: \"fulfillmentStatus\", value: \"processing\" },\n ]),\n update: {\n fulfillmentStatus: completed ? \"completed\" : \"pending\",\n fulfillmentToken: null,\n fulfillmentClaimedAt: null,\n updatedAt: new Date(),\n },\n });\n },\n async markExpired(reference) {\n const payment = await findByReference(reference);\n if (!payment || payment.status !== \"pending\")\n return payment?.status === \"expired\" ? payment : null;\n\n return context.adapter.update<SolanaPayment>({\n model: SOLANA_PAYMENT_MODEL,\n update: { status: \"expired\", updatedAt: new Date() },\n where: await paymentWhere([\n { field: \"id\", value: payment.id },\n { field: \"status\", value: \"pending\" },\n ]),\n });\n },\n };\n}\n","import { randomBytes } from \"node:crypto\";\n\nimport {\n APIError,\n createAuthEndpoint,\n getSessionFromCtx,\n originCheckMiddleware,\n sessionMiddleware,\n} from \"better-auth/api\";\nimport type { GenericEndpointContext } from \"better-auth\";\nimport { formatTokenAmount } from \"solana-payments\";\nimport { z } from \"zod\";\n\nimport { createSolanaPaymentStore } from \"./store.ts\";\nimport type { SolanaPayment, SolanaPaymentsOptions } from \"./types.ts\";\n\nconst createPaymentBody = z.object({\n amount: z.string().min(1),\n metadata: z.record(z.string(), z.unknown()).optional(),\n organizationId: z.string().min(1).optional(),\n});\nconst verifyPaymentBody = z.object({\n reference: z.string().min(1),\n organizationId: z.string().min(1).optional(),\n});\nconst getPaymentQuery = z.object({\n reference: z.string().min(1),\n organizationId: z.string().min(1).optional(),\n});\n\nfunction routeError(\n code:\n | \"MISSING_SESSION\"\n | \"UNAUTHORIZED_PAYMENT\"\n | \"PAYMENT_EXPIRED\"\n | \"INVALID_PAYMENT\"\n | \"PAYMENT_MISMATCH\",\n message: string,\n): never {\n throw new APIError(code === \"MISSING_SESSION\" ? \"UNAUTHORIZED\" : \"BAD_REQUEST\", {\n code,\n message,\n });\n}\n\nasync function paymentStore(ctx: GenericEndpointContext, organizationId?: string) {\n const session = await getSessionFromCtx(ctx);\n if (!session) routeError(\"MISSING_SESSION\", \"An authenticated session is required.\");\n try {\n const store = createSolanaPaymentStore({\n adapter: ctx.context.adapter,\n session,\n organizationId,\n hasOrganizationPlugin: ctx.context.hasPlugin?.(\"organization\") === true,\n });\n await store.assertOwner();\n return store;\n } catch (error) {\n routeError(\n \"UNAUTHORIZED_PAYMENT\",\n error instanceof Error ? error.message : \"Unauthorized payment.\",\n );\n }\n}\n\nasync function loadPayment(\n ctx: GenericEndpointContext,\n reference: string,\n organizationId?: string,\n) {\n const store = await paymentStore(ctx, organizationId);\n try {\n const payment = await store.findByReference(reference);\n if (!payment) routeError(\"UNAUTHORIZED_PAYMENT\", \"Payment was not found for this owner.\");\n return { store, payment };\n } catch (error) {\n if (error instanceof APIError) throw error;\n routeError(\n \"UNAUTHORIZED_PAYMENT\",\n error instanceof Error ? error.message : \"Unauthorized payment.\",\n );\n }\n}\n\nfunction asResponse(payment: SolanaPayment, paymentUrl?: string) {\n return {\n id: payment.id,\n reference: payment.reference,\n amount: payment.amount,\n mint: payment.mint,\n decimals: payment.decimals,\n recipient: payment.recipient,\n status: payment.status,\n fulfillmentStatus:\n payment.fulfillmentStatus ?? (payment.status === \"paid\" ? \"completed\" : \"pending\"),\n expiresAt: payment.expiresAt,\n signature: payment.signature ?? undefined,\n slot: payment.slot ?? undefined,\n metadata: payment.metadata\n ? (JSON.parse(payment.metadata) as Record<string, unknown>)\n : undefined,\n ...(paymentUrl ? { paymentUrl } : {}),\n };\n}\n\n// Solana Pay references are public keys (base58-encoded 32-byte values).\nfunction createReference() {\n const bytes = randomBytes(32);\n const alphabet = \"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz\";\n let number = BigInt(`0x${bytes.toString(\"hex\")}`);\n let encoded = \"\";\n while (number > 0n) {\n encoded = alphabet[Number(number % 58n)] + encoded;\n number /= 58n;\n }\n for (const byte of bytes) {\n if (byte !== 0) break;\n encoded = \"1\" + encoded;\n }\n return encoded;\n}\n\nasync function fulfillPayment(\n ctx: GenericEndpointContext,\n options: SolanaPaymentsOptions,\n store: Awaited<ReturnType<typeof paymentStore>>,\n payment: SolanaPayment,\n) {\n const claimed = await store.claimFulfillment(payment.reference);\n if (!claimed) return (await store.findByReference(payment.reference)) ?? payment;\n const token = claimed.fulfillmentToken!;\n try {\n await options.onPaymentComplete?.(claimed, ctx);\n const completed = await store.finishFulfillment(claimed.reference, token, true);\n if (!completed) throw new Error(\"Fulfillment lease was lost; retry verification.\");\n return completed;\n } catch (error) {\n await store.finishFulfillment(claimed.reference, token, false);\n throw error;\n }\n}\n\nexport const createPayment = <P extends string = \"/create-payment\">(\n options: SolanaPaymentsOptions,\n path: P = \"/create-payment\" as P,\n) =>\n createAuthEndpoint(\n path,\n { method: \"POST\", body: createPaymentBody, use: [sessionMiddleware, originCheckMiddleware] },\n async (ctx) => {\n const store = await paymentStore(ctx, ctx.body.organizationId);\n const reference = createReference();\n const request = options.client.payments.createRequest({\n amount: ctx.body.amount,\n recipient: options.recipient,\n reference,\n metadata: ctx.body.metadata,\n });\n const payment = await store.create({\n reference: request.reference,\n amount: request.amount.toString(),\n mint: request.mint,\n decimals: request.decimals,\n recipient: request.recipient ?? options.recipient,\n expiresAt: new Date(Date.now() + (options.paymentExpirationMs ?? 30 * 60 * 1000)),\n metadata: ctx.body.metadata ? JSON.stringify(ctx.body.metadata) : null,\n signature: null,\n slot: null,\n });\n const paymentUrl = options.client.payments.toSolanaPayUrl(request).toString();\n return ctx.json(asResponse(payment, paymentUrl));\n },\n );\n\nexport const verifyPayment = <P extends string = \"/verify-payment\">(\n options: SolanaPaymentsOptions,\n path: P = \"/verify-payment\" as P,\n) =>\n createAuthEndpoint(\n path,\n { method: \"POST\", body: verifyPaymentBody, use: [sessionMiddleware, originCheckMiddleware] },\n async (ctx) => {\n const { store, payment } = await loadPayment(\n ctx,\n ctx.body.reference,\n ctx.body.organizationId,\n );\n if (payment.status === \"paid\")\n return ctx.json(asResponse(await fulfillPayment(ctx, options, store, payment)));\n if (payment.status === \"expired\" || payment.expiresAt <= new Date()) {\n if (payment.status === \"pending\") await store.markExpired(payment.reference);\n routeError(\"PAYMENT_EXPIRED\", \"Payment intent has expired.\");\n }\n if (payment.status !== \"pending\") routeError(\"INVALID_PAYMENT\", \"Payment is not pending.\");\n\n let verified;\n try {\n verified = await options.client.payments.verify({\n reference: payment.reference,\n recipient: payment.recipient,\n amount: formatTokenAmount(payment.amount, payment.decimals),\n });\n } catch (error) {\n routeError(\n \"PAYMENT_MISMATCH\",\n error instanceof Error ? error.message : \"Payment did not match intent.\",\n );\n }\n if (\n !verified.found ||\n verified.reference !== payment.reference ||\n verified.recipient !== payment.recipient ||\n verified.amount?.toString() !== payment.amount\n ) {\n routeError(\"PAYMENT_MISMATCH\", \"Payment did not exactly match the stored intent.\");\n }\n const { payment: paid } = await store.markPaidWithTransition(payment.reference, {\n signature: verified.signature,\n slot: verified.slot?.toString(),\n });\n if (!paid) routeError(\"INVALID_PAYMENT\", \"Payment state could not be updated.\");\n return ctx.json(asResponse(await fulfillPayment(ctx, options, store, paid)));\n },\n );\n\nexport const getPayment = <P extends string = \"/payment\">(\n options: SolanaPaymentsOptions,\n path: P = \"/payment\" as P,\n) =>\n createAuthEndpoint(\n path,\n { method: \"GET\", query: getPaymentQuery, use: [sessionMiddleware] },\n async (ctx) => {\n const { store, payment } = await loadPayment(\n ctx,\n ctx.query.reference,\n ctx.query.organizationId,\n );\n const current =\n payment.status === \"pending\" && payment.expiresAt <= new Date()\n ? await store.markExpired(payment.reference)\n : payment;\n return ctx.json(asResponse(current ?? payment));\n },\n );\n","import { mergeSchema, type BetterAuthPluginDBSchema, type DBFieldAttribute } from \"better-auth/db\";\n\nimport type { SolanaPaymentsOptions } from \"./types.ts\";\n\ntype SolanaPaymentSchema = Record<\n \"solanaPayment\",\n {\n fields: Record<\n | \"reference\"\n | \"referenceType\"\n | \"referenceId\"\n | \"amount\"\n | \"mint\"\n | \"decimals\"\n | \"recipient\"\n | \"status\"\n | \"fulfillmentStatus\"\n | \"fulfillmentToken\"\n | \"fulfillmentClaimedAt\"\n | \"expiresAt\"\n | \"signature\"\n | \"slot\"\n | \"metadata\"\n | \"createdAt\"\n | \"updatedAt\",\n DBFieldAttribute\n >;\n }\n>;\n\nconst solanaPaymentSchema: SolanaPaymentSchema = {\n solanaPayment: {\n fields: {\n reference: { type: \"string\", required: true, unique: true },\n referenceType: { type: \"string\", required: true },\n referenceId: { type: \"string\", required: true, index: true },\n amount: { type: \"string\", required: true },\n mint: { type: \"string\", required: true },\n decimals: { type: \"number\", required: true },\n recipient: { type: \"string\", required: true },\n status: { type: \"string\", required: true, defaultValue: \"pending\", index: true },\n fulfillmentStatus: { type: \"string\", required: true, defaultValue: \"pending\" },\n fulfillmentToken: { type: \"string\", required: false },\n fulfillmentClaimedAt: { type: \"date\", required: false },\n expiresAt: { type: \"date\", required: true },\n signature: { type: \"string\", required: false, unique: true },\n slot: { type: \"string\", required: false },\n metadata: { type: \"string\", required: false },\n createdAt: { type: \"date\", required: true },\n updatedAt: { type: \"date\", required: true },\n },\n },\n} satisfies BetterAuthPluginDBSchema;\n\nexport type SolanaPaymentsPluginSchema = SolanaPaymentSchema;\nexport const solanaPaymentsPluginSchema: SolanaPaymentSchema = solanaPaymentSchema;\n\nexport function getSchema(\n options: Pick<SolanaPaymentsOptions, \"schema\">,\n): BetterAuthPluginDBSchema {\n return mergeSchema(solanaPaymentSchema, options.schema as Parameters<typeof mergeSchema>[1]);\n}\n","import { defineErrorCodes, type BetterAuthPlugin } from \"better-auth\";\n\nimport { createPayment, getPayment, verifyPayment } from \"./routes.ts\";\nimport { getSchema } from \"./schema.ts\";\nimport type { SolanaPaymentsOptions } from \"./types.ts\";\n\nexport { PACKAGE_VERSION } from \"./version.ts\";\nexport { getSchema, solanaPaymentsPluginSchema } from \"./schema.ts\";\nexport { createSolanaPaymentStore } from \"./store.ts\";\nexport type {\n CreateSolanaPaymentInput,\n MarkPaidInput,\n MarkPaidResult,\n SolanaPaymentStore,\n SolanaPaymentStoreContext,\n} from \"./store.ts\";\nexport type { SolanaPayment, SolanaPaymentsOptions, SolanaPaymentStatus } from \"./types.ts\";\n\nconst ERROR_CODES = defineErrorCodes({\n MISSING_SESSION: \"An authenticated session is required.\",\n UNAUTHORIZED_PAYMENT: \"Payment was not found for this owner.\",\n PAYMENT_EXPIRED: \"Payment intent has expired.\",\n INVALID_PAYMENT: \"Payment is invalid.\",\n PAYMENT_MISMATCH: \"Payment did not exactly match the stored intent.\",\n});\n\nexport function solanaPayments(input: SolanaPaymentsOptions) {\n const normalized = input.client.payments.createRequest({\n amount: \"0\",\n recipient: input.recipient,\n reference: \"solana-payments-recipient-normalization\",\n }).recipient;\n if (!normalized) throw new Error(\"A Solana payment recipient is required.\");\n const options = {\n ...input,\n recipient: normalized,\n paymentExpirationMs: input.paymentExpirationMs ?? 30 * 60 * 1000,\n } satisfies SolanaPaymentsOptions;\n return {\n id: \"solanaPayments\",\n endpoints: {\n createPayment: createPayment(options, \"/solana-payments/create-payment\"),\n verifyPayment: verifyPayment(options, \"/solana-payments/verify-payment\"),\n getPayment: getPayment(options, \"/solana-payments/payment\"),\n },\n schema: getSchema(options),\n $ERROR_CODES: ERROR_CODES,\n } satisfies BetterAuthPlugin;\n}\n"],"mappings":";;;;;;;;AAIA,MAAM,uBAAuB;AA+C7B,SAAgB,yBAAyB,SAAwD;CAC/F,MAAM,WAAW,YAAoE;EACnF,MAAM,SAAS,QAAQ,SAAS,MAAM;EACtC,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,sDAAsD;EAEnF,IAAI,CAAC,QAAQ,gBAAgB,OAAO;GAAE,MAAM;GAAQ,IAAI;EAAO;EAC/D,IAAI,CAAC,QAAQ,uBACX,MAAM,IAAI,MAAM,2EAA2E;EAU7F,IAAI,CAAC,MAPgB,QAAQ,QAAQ,QAAwB;GAC3D,OAAO;GACP,OAAO,C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;EAAU,UAAU;CAAM;CACpD,sBAAsB;EAAE,MAAM;EAAQ,UAAU;CAAM;CACtD,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAK;CAC1C,WAAW;EAAE,MAAM;EAAU,UAAU;EAAO,QAAQ;CAAK;CAC3D,MAAM;EAAE,MAAM;EAAU,UAAU;CAAM;CACxC,UAAU;EAAE,MAAM;EAAU,UAAU;CAAM;CAC5C,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAK;CAC1C,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAK;AAC5C,EACF,EACF;AAGA,MAAa,6BAAkD;AAE/D,SAAgB,UACd,SAC0B;CAC1B,OAAO,YAAY,qBAAqB,QAAQ,MAA2C;AAC7F;;;AC3CA,MAAM,cAAc,iBAAiB;CACnC,iBAAiB;CACjB,sBAAsB;CACtB,iBAAiB;CACjB,iBAAiB;CACjB,kBAAkB;AACpB,CAAC;AAED,SAAgB,eAAe,OAA8B;CAC3D,MAAM,aAAa,MAAM,OAAO,SAAS,cAAc;EACrD,QAAQ;EACR,WAAW,MAAM;EACjB,WAAW;CACb,CAAC,CAAC,CAAC;CACH,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,yCAAyC;CAC1E,MAAM,UAAU;EACd,GAAG;EACH,WAAW;EACX,qBAAqB,MAAM,uBAAuB;CACpD;CACA,OAAO;EACL,IAAI;EACJ,WAAW;GACT,eAAe,cAAc,SAAS,iCAAiC;GACvE,eAAe,cAAc,SAAS,iCAAiC;GACvE,YAAY,WAAW,SAAS,0BAA0B;EAC5D;EACA,QAAQ,UAAU,OAAO;EACzB,cAAc;CAChB;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/store.ts","../src/routes.ts","../src/schema.ts","../src/index.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\n\nimport type { SolanaPayment } from \"./types.ts\";\n\nconst SOLANA_PAYMENT_MODEL = \"solanaPayment\";\n\ntype Adapter = {\n create<T>(input: { model: string; data: Omit<T, \"id\"> }): Promise<T>;\n findOne<T>(input: { model: string; where: WhereClause }): Promise<T | null>;\n update<T>(input: { model: string; update: Partial<T>; where: WhereClause }): Promise<T | null>;\n};\ntype WhereClause = { field: string; value: string | null }[];\n\nexport interface SolanaPaymentStoreContext {\n adapter: Adapter;\n session?: { user?: { id: string } | null } | null;\n organizationId?: string;\n hasOrganizationPlugin?: boolean;\n}\n\nexport type CreateSolanaPaymentInput = Omit<\n SolanaPayment,\n \"id\" | \"referenceType\" | \"referenceId\" | \"status\" | \"createdAt\" | \"updatedAt\"\n>;\n\nexport interface MarkPaidInput {\n signature?: string;\n slot?: string;\n}\n\nexport interface MarkPaidResult {\n payment: SolanaPayment | null;\n transitioned: boolean;\n}\n\nexport interface SolanaPaymentStore {\n assertOwner(): Promise<void>;\n create(input: CreateSolanaPaymentInput): Promise<SolanaPayment>;\n findById(id: string): Promise<SolanaPayment | null>;\n findByReference(reference: string): Promise<SolanaPayment | null>;\n markPaid(reference: string, input?: MarkPaidInput): Promise<SolanaPayment | null>;\n markPaidWithTransition(reference: string, input?: MarkPaidInput): Promise<MarkPaidResult>;\n claimFulfillment(reference: string): Promise<SolanaPayment | null>;\n finishFulfillment(\n reference: string,\n token: string,\n completed: boolean,\n ): Promise<SolanaPayment | null>;\n markExpired(reference: string): Promise<SolanaPayment | null>;\n}\n\nexport function createSolanaPaymentStore(context: SolanaPaymentStoreContext): SolanaPaymentStore {\n const getOwner = async (): Promise<{ type: \"user\" | \"organization\"; id: string }> => {\n const userId = context.session?.user?.id;\n if (!userId) throw new Error(\"A session user is required to access Solana payments\");\n\n if (!context.organizationId) return { type: \"user\", id: userId };\n if (!context.hasOrganizationPlugin) {\n throw new Error(\"The Better Auth organization plugin is required for organization payments\");\n }\n\n const member = await context.adapter.findOne<{ id: string }>({\n model: \"member\",\n where: [\n { field: \"organizationId\", value: context.organizationId },\n { field: \"userId\", value: userId },\n ],\n });\n if (!member) throw new Error(\"The session user must be an organization member\");\n return { type: \"organization\", id: context.organizationId };\n };\n\n const paymentWhere = async (where: WhereClause): Promise<WhereClause> => {\n const owner = await getOwner();\n return [\n ...where,\n { field: \"referenceType\", value: owner.type },\n { field: \"referenceId\", value: owner.id },\n ];\n };\n\n const findByReference = async (reference: string): Promise<SolanaPayment | null> =>\n context.adapter.findOne<SolanaPayment>({\n model: SOLANA_PAYMENT_MODEL,\n where: await paymentWhere([{ field: \"reference\", value: reference }]),\n });\n\n const markPaidWithTransition = async (\n reference: string,\n input: MarkPaidInput = {},\n ): Promise<MarkPaidResult> => {\n const payment = await findByReference(reference);\n if (!payment) return { payment: null, transitioned: false };\n if (payment.status === \"paid\") return { payment, transitioned: false };\n if (payment.status !== \"pending\") return { payment: null, transitioned: false };\n const updated = await context.adapter.update<SolanaPayment>({\n model: SOLANA_PAYMENT_MODEL,\n update: { status: \"paid\", ...input, updatedAt: new Date() },\n where: await paymentWhere([\n { field: \"id\", value: payment.id },\n { field: \"status\", value: \"pending\" },\n ]),\n });\n if (updated) return { payment: updated, transitioned: true };\n const current = await findByReference(reference);\n return { payment: current?.status === \"paid\" ? current : null, transitioned: false };\n };\n\n return {\n async assertOwner() {\n await getOwner();\n },\n async create(input) {\n const owner = await getOwner();\n const now = new Date();\n return context.adapter.create<SolanaPayment>({\n model: SOLANA_PAYMENT_MODEL,\n data: {\n ...input,\n referenceType: owner.type,\n referenceId: owner.id,\n status: \"pending\",\n fulfillmentStatus: \"pending\",\n fulfillmentToken: null,\n fulfillmentClaimedAt: null,\n createdAt: now,\n updatedAt: now,\n },\n });\n },\n findById: async (id) =>\n context.adapter.findOne<SolanaPayment>({\n model: SOLANA_PAYMENT_MODEL,\n where: await paymentWhere([{ field: \"id\", value: id }]),\n }),\n findByReference,\n async markPaid(reference, input = {}) {\n return (await markPaidWithTransition(reference, input)).payment;\n },\n markPaidWithTransition,\n async claimFulfillment(reference) {\n const payment = await findByReference(reference);\n if (\n !payment ||\n payment.status !== \"paid\" ||\n !payment.fulfillmentStatus ||\n payment.fulfillmentStatus === \"completed\"\n )\n return null;\n if (\n payment.fulfillmentStatus === \"processing\" &&\n payment.fulfillmentClaimedAt &&\n new Date(payment.fulfillmentClaimedAt).getTime() > Date.now() - 5 * 60_000\n )\n return null;\n return context.adapter.update<SolanaPayment>({\n model: SOLANA_PAYMENT_MODEL,\n where: await paymentWhere([\n { field: \"id\", value: payment.id },\n { field: \"fulfillmentStatus\", value: payment.fulfillmentStatus },\n { field: \"fulfillmentToken\", value: payment.fulfillmentToken ?? null },\n ]),\n update: {\n fulfillmentStatus: \"processing\",\n fulfillmentToken: randomUUID(),\n fulfillmentClaimedAt: new Date(),\n updatedAt: new Date(),\n },\n });\n },\n async finishFulfillment(reference, token, completed) {\n return context.adapter.update<SolanaPayment>({\n model: SOLANA_PAYMENT_MODEL,\n where: await paymentWhere([\n { field: \"reference\", value: reference },\n { field: \"fulfillmentToken\", value: token },\n { field: \"fulfillmentStatus\", value: \"processing\" },\n ]),\n update: {\n fulfillmentStatus: completed ? \"completed\" : \"pending\",\n fulfillmentToken: null,\n fulfillmentClaimedAt: null,\n updatedAt: new Date(),\n },\n });\n },\n async markExpired(reference) {\n const payment = await findByReference(reference);\n if (!payment || payment.status !== \"pending\")\n return payment?.status === \"expired\" ? payment : null;\n\n return context.adapter.update<SolanaPayment>({\n model: SOLANA_PAYMENT_MODEL,\n update: { status: \"expired\", updatedAt: new Date() },\n where: await paymentWhere([\n { field: \"id\", value: payment.id },\n { field: \"status\", value: \"pending\" },\n ]),\n });\n },\n };\n}\n","import { randomBytes } from \"node:crypto\";\n\nimport {\n APIError,\n createAuthEndpoint,\n getSessionFromCtx,\n originCheckMiddleware,\n sessionMiddleware,\n} from \"better-auth/api\";\nimport type { GenericEndpointContext } from \"better-auth\";\nimport { formatTokenAmount, isSolanaPaymentsError } from \"solana-payments\";\nimport { z } from \"zod\";\n\nimport { createSolanaPaymentStore } from \"./store.ts\";\nimport type { SolanaPayment, SolanaPaymentsOptions } from \"./types.ts\";\n\nconst createPaymentBody = z.object({\n amount: z.string().min(1),\n metadata: z.record(z.string(), z.unknown()).optional(),\n organizationId: z.string().min(1).optional(),\n});\nconst verifyPaymentBody = z.object({\n reference: z.string().min(1),\n /** Transaction signature lets the SDK verify a candidate before scanning recent history. */\n signature: z.string().min(1).optional(),\n organizationId: z.string().min(1).optional(),\n});\nconst getPaymentQuery = z.object({\n reference: z.string().min(1),\n organizationId: z.string().min(1).optional(),\n});\n\nfunction routeError(\n code:\n | \"MISSING_SESSION\"\n | \"UNAUTHORIZED_PAYMENT\"\n | \"PAYMENT_EXPIRED\"\n | \"INVALID_PAYMENT\"\n | \"PAYMENT_MISMATCH\"\n | \"PAYMENT_PROVIDER_UNAVAILABLE\",\n message: string,\n): never {\n const status =\n code === \"MISSING_SESSION\"\n ? \"UNAUTHORIZED\"\n : code === \"PAYMENT_PROVIDER_UNAVAILABLE\"\n ? \"INTERNAL_SERVER_ERROR\"\n : \"BAD_REQUEST\";\n throw new APIError(status, {\n code,\n message,\n });\n}\n\nfunction assertOrganizationEnabled(options: SolanaPaymentsOptions, organizationId?: string) {\n if (organizationId && options.organization?.enabled !== true) {\n routeError(\"UNAUTHORIZED_PAYMENT\", \"Organization payments are not enabled.\");\n }\n}\n\nasync function paymentStore(ctx: GenericEndpointContext, organizationId?: string) {\n const session = await getSessionFromCtx(ctx);\n if (!session) routeError(\"MISSING_SESSION\", \"An authenticated session is required.\");\n try {\n const store = createSolanaPaymentStore({\n adapter: ctx.context.adapter,\n session,\n organizationId,\n hasOrganizationPlugin: ctx.context.hasPlugin?.(\"organization\") === true,\n });\n await store.assertOwner();\n return store;\n } catch (error) {\n routeError(\n \"UNAUTHORIZED_PAYMENT\",\n error instanceof Error ? error.message : \"Unauthorized payment.\",\n );\n }\n}\n\nasync function loadPayment(\n ctx: GenericEndpointContext,\n reference: string,\n organizationId?: string,\n) {\n const store = await paymentStore(ctx, organizationId);\n try {\n const payment = await store.findByReference(reference);\n if (!payment) routeError(\"UNAUTHORIZED_PAYMENT\", \"Payment was not found for this owner.\");\n return { store, payment };\n } catch (error) {\n if (error instanceof APIError) throw error;\n routeError(\n \"UNAUTHORIZED_PAYMENT\",\n error instanceof Error ? error.message : \"Unauthorized payment.\",\n );\n }\n}\n\nfunction asResponse(payment: SolanaPayment, paymentUrl?: string) {\n return {\n id: payment.id,\n reference: payment.reference,\n amount: payment.amount,\n mint: payment.mint,\n decimals: payment.decimals,\n recipient: payment.recipient,\n status: payment.status,\n fulfillmentStatus:\n payment.fulfillmentStatus ?? (payment.status === \"paid\" ? \"completed\" : \"pending\"),\n expiresAt: payment.expiresAt,\n signature: payment.signature ?? undefined,\n slot: payment.slot ?? undefined,\n metadata: payment.metadata\n ? (JSON.parse(payment.metadata) as Record<string, unknown>)\n : undefined,\n ...(paymentUrl ? { paymentUrl } : {}),\n };\n}\n\n// Solana Pay references are public keys (base58-encoded 32-byte values).\nfunction createReference() {\n const bytes = randomBytes(32);\n const alphabet = \"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz\";\n let number = BigInt(`0x${bytes.toString(\"hex\")}`);\n let encoded = \"\";\n while (number > 0n) {\n encoded = alphabet[Number(number % 58n)] + encoded;\n number /= 58n;\n }\n for (const byte of bytes) {\n if (byte !== 0) break;\n encoded = \"1\" + encoded;\n }\n return encoded;\n}\n\nasync function fulfillPayment(\n ctx: GenericEndpointContext,\n options: SolanaPaymentsOptions,\n store: Awaited<ReturnType<typeof paymentStore>>,\n payment: SolanaPayment,\n) {\n const claimed = await store.claimFulfillment(payment.reference);\n if (!claimed) return (await store.findByReference(payment.reference)) ?? payment;\n const token = claimed.fulfillmentToken!;\n try {\n await options.onPaymentComplete?.(claimed, ctx);\n const completed = await store.finishFulfillment(claimed.reference, token, true);\n if (!completed) throw new Error(\"Fulfillment lease was lost; retry verification.\");\n return completed;\n } catch (error) {\n await store.finishFulfillment(claimed.reference, token, false);\n throw error;\n }\n}\n\nexport const createPayment = <P extends string = \"/create-payment\">(\n options: SolanaPaymentsOptions,\n path: P = \"/create-payment\" as P,\n) =>\n createAuthEndpoint(\n path,\n { method: \"POST\", body: createPaymentBody, use: [sessionMiddleware, originCheckMiddleware] },\n async (ctx) => {\n assertOrganizationEnabled(options, ctx.body.organizationId);\n const store = await paymentStore(ctx, ctx.body.organizationId);\n const reference = createReference();\n const request = options.client.payments.createRequest({\n amount: ctx.body.amount,\n recipient: options.recipient,\n reference,\n metadata: ctx.body.metadata,\n });\n const payment = await store.create({\n reference: request.reference,\n amount: request.amount.toString(),\n mint: request.mint,\n decimals: request.decimals,\n recipient: request.recipient ?? options.recipient,\n expiresAt: new Date(Date.now() + (options.paymentExpirationMs ?? 30 * 60 * 1000)),\n metadata: ctx.body.metadata ? JSON.stringify(ctx.body.metadata) : null,\n signature: null,\n slot: null,\n });\n const paymentUrl = options.client.payments.toSolanaPayUrl(request).toString();\n return ctx.json(asResponse(payment, paymentUrl));\n },\n );\n\nexport const verifyPayment = <P extends string = \"/verify-payment\">(\n options: SolanaPaymentsOptions,\n path: P = \"/verify-payment\" as P,\n) =>\n createAuthEndpoint(\n path,\n { method: \"POST\", body: verifyPaymentBody, use: [sessionMiddleware, originCheckMiddleware] },\n async (ctx) => {\n assertOrganizationEnabled(options, ctx.body.organizationId);\n const { store, payment } = await loadPayment(\n ctx,\n ctx.body.reference,\n ctx.body.organizationId,\n );\n if (payment.status === \"paid\")\n return ctx.json(asResponse(await fulfillPayment(ctx, options, store, payment)));\n if (payment.status === \"expired\" || payment.expiresAt <= new Date()) {\n if (payment.status === \"pending\") await store.markExpired(payment.reference);\n routeError(\"PAYMENT_EXPIRED\", \"Payment intent has expired.\");\n }\n if (payment.status !== \"pending\") routeError(\"INVALID_PAYMENT\", \"Payment is not pending.\");\n\n let verified;\n try {\n verified = await options.client.payments.verify({\n reference: payment.reference,\n ...(ctx.body.signature ? { signature: ctx.body.signature } : {}),\n recipient: payment.recipient,\n amount: formatTokenAmount(payment.amount, payment.decimals),\n });\n } catch (error) {\n if (\n isSolanaPaymentsError(error) &&\n [\"RPC_ERROR\", \"RPC_TIMEOUT\", \"TRANSACTION_TIMEOUT\"].includes(error.code)\n ) {\n routeError(\n \"PAYMENT_PROVIDER_UNAVAILABLE\",\n \"Solana RPC could not confirm the payment. Retry verification with the same reference.\",\n );\n }\n routeError(\n \"PAYMENT_MISMATCH\",\n error instanceof Error ? error.message : \"Payment did not match intent.\",\n );\n }\n if (\n !verified.found ||\n verified.reference !== payment.reference ||\n verified.recipient !== payment.recipient ||\n verified.amount?.toString() !== payment.amount\n ) {\n routeError(\"PAYMENT_MISMATCH\", \"Payment did not exactly match the stored intent.\");\n }\n const { payment: paid } = await store.markPaidWithTransition(payment.reference, {\n signature: verified.signature,\n slot: verified.slot?.toString(),\n });\n if (!paid) routeError(\"INVALID_PAYMENT\", \"Payment state could not be updated.\");\n return ctx.json(asResponse(await fulfillPayment(ctx, options, store, paid)));\n },\n );\n\nexport const getPayment = <P extends string = \"/payment\">(\n options: SolanaPaymentsOptions,\n path: P = \"/payment\" as P,\n) =>\n createAuthEndpoint(\n path,\n { method: \"GET\", query: getPaymentQuery, use: [sessionMiddleware] },\n async (ctx) => {\n assertOrganizationEnabled(options, ctx.query.organizationId);\n const { store, payment } = await loadPayment(\n ctx,\n ctx.query.reference,\n ctx.query.organizationId,\n );\n const current =\n payment.status === \"pending\" && payment.expiresAt <= new Date()\n ? await store.markExpired(payment.reference)\n : payment;\n return ctx.json(asResponse(current ?? payment));\n },\n );\n","import { mergeSchema, type BetterAuthPluginDBSchema, type DBFieldAttribute } from \"better-auth/db\";\n\nimport type { SolanaPaymentsOptions } from \"./types.ts\";\n\ntype SolanaPaymentSchema = Record<\n \"solanaPayment\",\n {\n fields: Record<\n | \"reference\"\n | \"referenceType\"\n | \"referenceId\"\n | \"amount\"\n | \"mint\"\n | \"decimals\"\n | \"recipient\"\n | \"status\"\n | \"fulfillmentStatus\"\n | \"fulfillmentToken\"\n | \"fulfillmentClaimedAt\"\n | \"expiresAt\"\n | \"signature\"\n | \"slot\"\n | \"metadata\"\n | \"createdAt\"\n | \"updatedAt\",\n DBFieldAttribute\n >;\n }\n>;\n\nconst solanaPaymentSchema: SolanaPaymentSchema = {\n solanaPayment: {\n fields: {\n reference: { type: \"string\", required: true, unique: true },\n referenceType: { type: \"string\", required: true },\n referenceId: { type: \"string\", required: true, index: true },\n amount: { type: \"string\", required: true },\n mint: { type: \"string\", required: true },\n decimals: { type: \"number\", required: true },\n recipient: { type: \"string\", required: true },\n status: { type: \"string\", required: true, defaultValue: \"pending\", index: true },\n fulfillmentStatus: { type: \"string\", required: true, defaultValue: \"pending\" },\n fulfillmentToken: { type: \"string\", required: false },\n fulfillmentClaimedAt: { type: \"date\", required: false },\n expiresAt: { type: \"date\", required: true },\n signature: { type: \"string\", required: false, unique: true },\n slot: { type: \"string\", required: false },\n metadata: { type: \"string\", required: false },\n createdAt: { type: \"date\", required: true },\n updatedAt: { type: \"date\", required: true },\n },\n },\n} satisfies BetterAuthPluginDBSchema;\n\nexport type SolanaPaymentsPluginSchema = SolanaPaymentSchema;\nexport const solanaPaymentsPluginSchema: SolanaPaymentSchema = solanaPaymentSchema;\n\nexport function getSchema(\n options: Pick<SolanaPaymentsOptions, \"schema\">,\n): BetterAuthPluginDBSchema {\n return mergeSchema(solanaPaymentSchema, options.schema as Parameters<typeof mergeSchema>[1]);\n}\n","import { defineErrorCodes, type BetterAuthPlugin } from \"better-auth\";\n\nimport { createPayment, getPayment, verifyPayment } from \"./routes.ts\";\nimport { getSchema } from \"./schema.ts\";\nimport type { SolanaPaymentsOptions } from \"./types.ts\";\n\nimport { PACKAGE_VERSION } from \"./version.ts\";\n\nexport { PACKAGE_VERSION } from \"./version.ts\";\nexport { getSchema, solanaPaymentsPluginSchema } from \"./schema.ts\";\nexport { createSolanaPaymentStore } from \"./store.ts\";\nexport type {\n CreateSolanaPaymentInput,\n MarkPaidInput,\n MarkPaidResult,\n SolanaPaymentStore,\n SolanaPaymentStoreContext,\n} from \"./store.ts\";\nexport type { SolanaPayment, SolanaPaymentsOptions, SolanaPaymentStatus } from \"./types.ts\";\n\nconst ERROR_CODES = defineErrorCodes({\n MISSING_SESSION: \"An authenticated session is required.\",\n UNAUTHORIZED_PAYMENT: \"Payment was not found for this owner.\",\n PAYMENT_EXPIRED: \"Payment intent has expired.\",\n INVALID_PAYMENT: \"Payment is invalid.\",\n PAYMENT_MISMATCH: \"Payment did not exactly match the stored intent.\",\n PAYMENT_PROVIDER_UNAVAILABLE: \"Solana RPC could not confirm the payment; retry verification.\",\n});\n\nexport function solanaPayments(input: SolanaPaymentsOptions) {\n const normalized = input.client.payments.createRequest({\n amount: \"0\",\n recipient: input.recipient,\n reference: \"solana-payments-recipient-normalization\",\n }).recipient;\n if (!normalized) throw new Error(\"A Solana payment recipient is required.\");\n const options = {\n ...input,\n recipient: normalized,\n paymentExpirationMs: input.paymentExpirationMs ?? 30 * 60 * 1000,\n } satisfies SolanaPaymentsOptions;\n return {\n id: \"solanaPayments\",\n version: PACKAGE_VERSION,\n endpoints: {\n createPayment: createPayment(options, \"/solana-payments/create-payment\"),\n verifyPayment: verifyPayment(options, \"/solana-payments/verify-payment\"),\n getPayment: getPayment(options, \"/solana-payments/payment\"),\n },\n schema: getSchema(options),\n $ERROR_CODES: ERROR_CODES,\n } satisfies BetterAuthPlugin;\n}\n"],"mappings":";;;;;;;;AAIA,MAAM,uBAAuB;AA+C7B,SAAgB,yBAAyB,SAAwD;CAC/F,MAAM,WAAW,YAAoE;EACnF,MAAM,SAAS,QAAQ,SAAS,MAAM;EACtC,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,sDAAsD;EAEnF,IAAI,CAAC,QAAQ,gBAAgB,OAAO;GAAE,MAAM;GAAQ,IAAI;EAAO;EAC/D,IAAI,CAAC,QAAQ,uBACX,MAAM,IAAI,MAAM,2EAA2E;EAU7F,IAAI,CAAC,MAPgB,QAAQ,QAAQ,QAAwB;GAC3D,OAAO;GACP,OAAO,CACL;IAAE,OAAO;IAAkB,OAAO,QA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1E,MAAM,UAAU;EACd,GAAG;EACH,WAAW;EACX,qBAAqB,MAAM,uBAAuB;CACpD;CACA,OAAO;EACL,IAAI;EACJ,SAAS;EACT,WAAW;GACT,eAAe,cAAc,SAAS,iCAAiC;GACvE,eAAe,cAAc,SAAS,iCAAiC;GACvE,YAAY,WAAW,SAAS,0BAA0B;EAC5D;EACA,QAAQ,UAAU,OAAO;EACzB,cAAc;CAChB;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version-B5dtK-2_.mjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["export const PACKAGE_VERSION = \"0.4.0\"; // x-release-please-version\n"],"mappings":";AAAA,MAAa,kBAAkB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-auth-solana-payments",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "One-time Solana payment integration for Better Auth",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"better-auth",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"@better-fetch/fetch": "^1.3.1",
|
|
58
58
|
"better-auth": "^1.6.25",
|
|
59
|
-
"solana-payments": "^1.
|
|
59
|
+
"solana-payments": "^1.1.0"
|
|
60
60
|
},
|
|
61
61
|
"engines": {
|
|
62
62
|
"node": ">=22.0.0"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"version-L8AhU29A.mjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["export const PACKAGE_VERSION = \"0.3.0\"; // x-release-please-version\n"],"mappings":";AAAA,MAAa,kBAAkB"}
|