@faremeter/payment-solana 0.9.0 → 0.10.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/dist/src/exact/client.d.ts.map +1 -1
- package/dist/src/exact/client.js +5 -9
- package/dist/src/exact/common.d.ts +13 -0
- package/dist/src/exact/common.d.ts.map +1 -0
- package/dist/src/exact/common.js +17 -0
- package/dist/src/exact/common.test.d.ts +3 -0
- package/dist/src/exact/common.test.d.ts.map +1 -0
- package/dist/src/exact/common.test.js +35 -0
- package/dist/src/exact/facilitator.d.ts +0 -2
- package/dist/src/exact/facilitator.d.ts.map +1 -1
- package/dist/src/exact/facilitator.js +14 -24
- package/dist/src/exact/index.d.ts +1 -1
- package/dist/src/exact/index.d.ts.map +1 -1
- package/dist/src/exact/index.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/exact/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/exact/client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,cAAc,EAEf,MAAM,yBAAyB,CAAC;AAWjC,OAAO,EAEL,UAAU,EACV,SAAS,EACT,sBAAsB,EAEtB,oBAAoB,EACrB,MAAM,iBAAiB,CAAC;AAIzB,MAAM,MAAM,MAAM,GAAG;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,SAAS,CAAC;IACrB,gBAAgB,CAAC,EAAE,CACjB,YAAY,EAAE,sBAAsB,EAAE,EACtC,eAAe,EAAE,MAAM,KACpB,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACnC,iBAAiB,CAAC,EAAE,CAClB,EAAE,EAAE,oBAAoB,KACrB,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACnC,eAAe,CAAC,EAAE,CAAC,EAAE,EAAE,oBAAoB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CACjE,CAAC;AAEF,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,EACf,UAAU,CAAC,EAAE,UAAU,GACtB,cAAc,CAwHhB"}
|
package/dist/src/exact/client.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import { isValidationError, throwValidationError
|
|
1
|
+
import { isValidationError, throwValidationError } from "@faremeter/types";
|
|
2
2
|
import { createTransferCheckedInstruction, getAssociatedTokenAddressSync, getMint, } from "@solana/spl-token";
|
|
3
3
|
import { getBase64EncodedWireTransaction, } from "@solana/transactions";
|
|
4
4
|
import { ComputeBudgetProgram, Connection, PublicKey, TransactionInstruction, TransactionMessage, VersionedTransaction, } from "@solana/web3.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { PaymentRequirementsExtra } from "./facilitator.js";
|
|
6
|
+
import { generateMatcher } from "./common.js";
|
|
7
7
|
export function createPaymentHandler(wallet, mint, connection) {
|
|
8
|
-
const
|
|
9
|
-
scheme: caseInsensitiveLiteral(x402Scheme),
|
|
10
|
-
network: caseInsensitiveLiteral(lookupX402Network(wallet.network)),
|
|
11
|
-
asset: caseInsensitiveLiteral(mint ? mint.toBase58() : "sol"),
|
|
12
|
-
});
|
|
8
|
+
const { matchTupleAndAsset } = generateMatcher(wallet.network, mint ? mint.toBase58() : "sol");
|
|
13
9
|
return async (context, accepts) => {
|
|
14
10
|
const res = accepts
|
|
15
|
-
.filter((r) => !isValidationError(
|
|
11
|
+
.filter((r) => !isValidationError(matchTupleAndAsset(r)))
|
|
16
12
|
.map((requirements) => {
|
|
17
13
|
const extra = PaymentRequirementsExtra(requirements.extra);
|
|
18
14
|
if (isValidationError(extra)) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const x402Scheme = "exact";
|
|
2
|
+
export declare function generateMatcher(network: string, asset: string): {
|
|
3
|
+
matchTuple: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
4
|
+
scheme: (In: string) => import("arktype/internal/attributes.ts").To<"exact">;
|
|
5
|
+
network: (In: string) => import("arktype/internal/attributes.ts").To<Lowercase<string>>;
|
|
6
|
+
}, {}>;
|
|
7
|
+
matchTupleAndAsset: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
8
|
+
scheme: (In: string) => import("arktype/internal/attributes.ts").To<"exact">;
|
|
9
|
+
network: (In: string) => import("arktype/internal/attributes.ts").To<Lowercase<string>>;
|
|
10
|
+
asset: (In: string) => import("arktype/internal/attributes.ts").To<Lowercase<string>>;
|
|
11
|
+
}, {}>;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/exact/common.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,UAAU,UAAU,CAAC;AAElC,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;;;;;;;;;;EAa7D"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type } from "arktype";
|
|
2
|
+
import { caseInsensitiveLiteral } from "@faremeter/types";
|
|
3
|
+
import { lookupX402Network } from "@faremeter/info/solana";
|
|
4
|
+
export const x402Scheme = "exact";
|
|
5
|
+
export function generateMatcher(network, asset) {
|
|
6
|
+
const matchTuple = type({
|
|
7
|
+
scheme: caseInsensitiveLiteral(x402Scheme),
|
|
8
|
+
network: caseInsensitiveLiteral(...lookupX402Network(network)),
|
|
9
|
+
});
|
|
10
|
+
const matchTupleAndAsset = matchTuple.and({
|
|
11
|
+
asset: caseInsensitiveLiteral(asset),
|
|
12
|
+
});
|
|
13
|
+
return {
|
|
14
|
+
matchTuple,
|
|
15
|
+
matchTupleAndAsset,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.test.d.ts","sourceRoot":"","sources":["../../../src/exact/common.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env pnpm tsx
|
|
2
|
+
import t from "tap";
|
|
3
|
+
import { isValidationError as iVE } from "@faremeter/types";
|
|
4
|
+
import { lookupKnownSPLToken } from "@faremeter/info/solana";
|
|
5
|
+
import { generateMatcher } from "./common.js";
|
|
6
|
+
await t.test("testBasicMatching", async (t) => {
|
|
7
|
+
{
|
|
8
|
+
const tokenInfo = lookupKnownSPLToken("mainnet-beta", "USDC");
|
|
9
|
+
if (tokenInfo === undefined) {
|
|
10
|
+
t.bailout("couldn't find SPL token");
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const { matchTuple, matchTupleAndAsset } = generateMatcher("mainnet-beta", tokenInfo.address);
|
|
14
|
+
const req = {
|
|
15
|
+
network: "solana-mainnet-beta",
|
|
16
|
+
scheme: "exact",
|
|
17
|
+
asset: tokenInfo.address,
|
|
18
|
+
};
|
|
19
|
+
t.ok(!iVE(matchTuple(req)));
|
|
20
|
+
t.ok(!iVE(matchTupleAndAsset(req)));
|
|
21
|
+
t.ok(!iVE(matchTupleAndAsset({
|
|
22
|
+
...req,
|
|
23
|
+
network: "solana",
|
|
24
|
+
})));
|
|
25
|
+
t.ok(iVE(matchTuple({
|
|
26
|
+
...req,
|
|
27
|
+
network: "foobar",
|
|
28
|
+
})));
|
|
29
|
+
t.ok(iVE(matchTuple({
|
|
30
|
+
...req,
|
|
31
|
+
scheme: "fner",
|
|
32
|
+
})));
|
|
33
|
+
}
|
|
34
|
+
t.end();
|
|
35
|
+
});
|
|
@@ -2,7 +2,6 @@ import type { FacilitatorHandler } from "@faremeter/types/facilitator";
|
|
|
2
2
|
import { type Rpc, type SolanaRpcApi } from "@solana/kit";
|
|
3
3
|
import type { TransactionError } from "@solana/rpc-types";
|
|
4
4
|
import { Keypair, type PublicKey } from "@solana/web3.js";
|
|
5
|
-
export declare const x402Scheme = "exact";
|
|
6
5
|
export declare const PaymentRequirementsExtra: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
7
6
|
feePayer: string;
|
|
8
7
|
decimals?: number;
|
|
@@ -14,7 +13,6 @@ export declare const PaymentPayload: import("arktype/internal/methods/object.ts"
|
|
|
14
13
|
signatures: import("@solana/transactions").SignaturesMap;
|
|
15
14
|
}>>;
|
|
16
15
|
}, {}>;
|
|
17
|
-
export declare const lookupX402Network: (network: string) => string;
|
|
18
16
|
export declare function transactionErrorToString(t: TransactionError): string;
|
|
19
17
|
export declare const createFacilitatorHandler: (network: string, rpc: Rpc<SolanaRpcApi>, feePayerKeypair: Keypair, mint: PublicKey, maxRetries?: number, retryDelayMs?: number) => FacilitatorHandler;
|
|
20
18
|
//# sourceMappingURL=facilitator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"facilitator.d.ts","sourceRoot":"","sources":["../../../src/exact/facilitator.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"facilitator.d.ts","sourceRoot":"","sources":["../../../src/exact/facilitator.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAGvE,OAAO,EAML,KAAK,GAAG,EACR,KAAK,YAAY,EAClB,MAAM,aAAa,CAAC;AAOrB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAM1D,eAAO,MAAM,wBAAwB;;;;MAInC,CAAC;AAmBH,eAAO,MAAM,cAAc;;;;;MAEzB,CAAC;AAEH,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,gBAAgB,UAY3D;AAiDD,eAAO,MAAM,wBAAwB,GACnC,SAAS,MAAM,EACf,KAAK,GAAG,CAAC,YAAY,CAAC,EACtB,iBAAiB,OAAO,EACxB,MAAM,SAAS,EACf,mBAAe,EACf,qBAAmB,KAClB,kBAkHF,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { isValidationError
|
|
1
|
+
import { isValidationError } from "@faremeter/types";
|
|
2
|
+
import { lookupX402Network } from "@faremeter/info/solana";
|
|
2
3
|
import { fetchMint } from "@solana-program/token";
|
|
3
4
|
import { address, createKeyPairSignerFromBytes, decompileTransactionMessage, getBase64Encoder, getCompiledTransactionMessageDecoder, } from "@solana/kit";
|
|
4
5
|
import { getBase64EncodedWireTransaction, getTransactionDecoder, partiallySignTransaction, } from "@solana/transactions";
|
|
@@ -6,7 +7,7 @@ import { Keypair } from "@solana/web3.js";
|
|
|
6
7
|
import { type } from "arktype";
|
|
7
8
|
import { isValidTransaction } from "./verify.js";
|
|
8
9
|
import { logger } from "./logger.js";
|
|
9
|
-
|
|
10
|
+
import { x402Scheme, generateMatcher } from "./common.js";
|
|
10
11
|
export const PaymentRequirementsExtra = type({
|
|
11
12
|
feePayer: "string",
|
|
12
13
|
decimals: "number?",
|
|
@@ -30,9 +31,6 @@ const TransactionString = type("string").pipe.try((tx) => {
|
|
|
30
31
|
export const PaymentPayload = type({
|
|
31
32
|
transaction: TransactionString,
|
|
32
33
|
});
|
|
33
|
-
export const lookupX402Network = (network) => {
|
|
34
|
-
return `solana-${network}`;
|
|
35
|
-
};
|
|
36
34
|
export function transactionErrorToString(t) {
|
|
37
35
|
if (typeof t == "string") {
|
|
38
36
|
return t;
|
|
@@ -75,31 +73,23 @@ const sendTransaction = async (rpc, signedTransaction, maxRetries, retryDelayMs)
|
|
|
75
73
|
return { success: false, error: "Transaction confirmation timeout" };
|
|
76
74
|
};
|
|
77
75
|
export const createFacilitatorHandler = (network, rpc, feePayerKeypair, mint, maxRetries = 30, retryDelayMs = 1000) => {
|
|
78
|
-
const
|
|
79
|
-
scheme: caseInsensitiveLiteral(x402Scheme),
|
|
80
|
-
network: caseInsensitiveLiteral(lookupX402Network(network)),
|
|
81
|
-
});
|
|
82
|
-
const checkTupleAndAsset = checkTuple.and({
|
|
83
|
-
asset: caseInsensitiveLiteral(mint.toBase58()),
|
|
84
|
-
});
|
|
76
|
+
const { matchTuple, matchTupleAndAsset } = generateMatcher(network, mint.toBase58());
|
|
85
77
|
const getSupported = () => {
|
|
86
|
-
return
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}),
|
|
95
|
-
];
|
|
78
|
+
return lookupX402Network(network).map((network) => Promise.resolve({
|
|
79
|
+
x402Version: 1,
|
|
80
|
+
scheme: x402Scheme,
|
|
81
|
+
network,
|
|
82
|
+
extra: {
|
|
83
|
+
feePayer: feePayerKeypair.publicKey.toString(),
|
|
84
|
+
},
|
|
85
|
+
}));
|
|
96
86
|
};
|
|
97
87
|
const getRequirements = async (req) => {
|
|
98
88
|
const recentBlockhash = (await rpc.getLatestBlockhash().send()).value
|
|
99
89
|
.blockhash;
|
|
100
90
|
const mintInfo = await fetchMint(rpc, address(mint.toBase58()));
|
|
101
91
|
return req
|
|
102
|
-
.filter((x) => !isValidationError(
|
|
92
|
+
.filter((x) => !isValidationError(matchTupleAndAsset(x)))
|
|
103
93
|
.map((x) => {
|
|
104
94
|
return {
|
|
105
95
|
...x,
|
|
@@ -113,7 +103,7 @@ export const createFacilitatorHandler = (network, rpc, feePayerKeypair, mint, ma
|
|
|
113
103
|
});
|
|
114
104
|
};
|
|
115
105
|
const handleSettle = async (requirements, payment) => {
|
|
116
|
-
if (isValidationError(
|
|
106
|
+
if (isValidationError(matchTuple(payment))) {
|
|
117
107
|
return null;
|
|
118
108
|
}
|
|
119
109
|
const paymentPayload = PaymentPayload(payment.payload);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/exact/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/exact/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/src/exact/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { createPaymentHandler } from "./client.js";
|
|
2
|
-
export { createFacilitatorHandler
|
|
2
|
+
export { createFacilitatorHandler } from "./facilitator.js";
|