@redditech/x402-solana 0.0.0-stage → 0.1.1
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/CHANGELOG.md +90 -0
- package/LICENSE +21 -0
- package/README.md +301 -2
- package/dist/budget-policy.d.ts +68 -0
- package/dist/budget-policy.js +234 -0
- package/dist/buyer.d.ts +54 -0
- package/dist/buyer.js +147 -0
- package/dist/client.d.ts +80 -0
- package/dist/client.js +225 -0
- package/dist/direct-auth.d.ts +94 -0
- package/dist/direct-auth.js +120 -0
- package/dist/direct-payment.d.ts +33 -0
- package/dist/direct-payment.js +65 -0
- package/dist/ed25519.d.ts +6 -0
- package/dist/ed25519.js +42 -0
- package/dist/escrow-http.d.ts +125 -0
- package/dist/escrow-http.js +192 -0
- package/dist/escrow-readiness.d.ts +132 -0
- package/dist/escrow-readiness.js +171 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +42 -0
- package/dist/jupiter.d.ts +36 -0
- package/dist/jupiter.js +120 -0
- package/dist/metered.d.ts +58 -0
- package/dist/metered.js +82 -0
- package/dist/middleware.d.ts +9 -0
- package/dist/middleware.js +71 -0
- package/dist/nonce.d.ts +57 -0
- package/dist/nonce.js +123 -0
- package/dist/payment.d.ts +202 -0
- package/dist/payment.js +967 -0
- package/dist/provider.d.ts +371 -0
- package/dist/provider.js +492 -0
- package/dist/rating.d.ts +552 -0
- package/dist/rating.js +829 -0
- package/dist/session-auth.d.ts +168 -0
- package/dist/session-auth.js +341 -0
- package/dist/session.d.ts +220 -0
- package/dist/session.js +297 -0
- package/dist/spl-token-observer.d.ts +70 -0
- package/dist/spl-token-observer.js +319 -0
- package/dist/token-escrow.d.ts +125 -0
- package/dist/token-escrow.js +163 -0
- package/dist/types.d.ts +148 -0
- package/dist/types.js +2 -0
- package/package.json +109 -4
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* x402 payment request parsed from HTTP header.
|
|
3
|
+
* Amount is represented as the smallest payment unit for the declared currency.
|
|
4
|
+
*/
|
|
5
|
+
export interface X402Request {
|
|
6
|
+
amount: number;
|
|
7
|
+
currency: string;
|
|
8
|
+
paymentAddress: string;
|
|
9
|
+
nonce: string;
|
|
10
|
+
network?: SolanaPaymentNetwork;
|
|
11
|
+
endpoint?: string;
|
|
12
|
+
memo?: string;
|
|
13
|
+
payerCurrency?: string;
|
|
14
|
+
payerAddress?: string;
|
|
15
|
+
autoSwap?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export type SolanaPaymentNetwork = 'solana-devnet' | 'solana-mainnet-beta' | 'solana-testnet';
|
|
18
|
+
export interface X402ChallengeInput {
|
|
19
|
+
version?: string;
|
|
20
|
+
network: SolanaPaymentNetwork;
|
|
21
|
+
payTo: string;
|
|
22
|
+
amount: string | number;
|
|
23
|
+
currency: string;
|
|
24
|
+
endpoint: string;
|
|
25
|
+
nonce: string;
|
|
26
|
+
memo?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Protocol fee stated in a challenge so the buyer sees the split before paying.
|
|
30
|
+
* The fee comes out of the listed amount: the buyer pays `amount` in total, the
|
|
31
|
+
* provider receives `providerAmount` and `payTo` (the treasury) receives `amount`
|
|
32
|
+
* of this block. Amounts are decimal strings in the challenge currency.
|
|
33
|
+
*/
|
|
34
|
+
export interface X402FeeTerms {
|
|
35
|
+
/** Fee rate in basis points of the listed amount. */
|
|
36
|
+
bps: number;
|
|
37
|
+
/** Treasury owner address that receives the fee. */
|
|
38
|
+
payTo: string;
|
|
39
|
+
/** Fee, rounded down to the currency's smallest unit. "0" when the price is too small to yield one unit. */
|
|
40
|
+
amount: string;
|
|
41
|
+
/** What the provider receives: listed amount minus the fee. */
|
|
42
|
+
providerAmount: string;
|
|
43
|
+
/** Fee ceiling in the challenge currency, when there is one (0.1 for SOL). */
|
|
44
|
+
cap?: string;
|
|
45
|
+
}
|
|
46
|
+
/** Operator configuration for the protocol fee. Never taken from a buyer or a provider. */
|
|
47
|
+
export interface ProtocolFeeConfig {
|
|
48
|
+
/** Treasury owner address. */
|
|
49
|
+
treasury: string;
|
|
50
|
+
/** Fee rate in basis points. Defaults to the scheduled rate (protocolFeeBpsAt): 2.5% until 1 April 2027, then 5%. */
|
|
51
|
+
bps?: number;
|
|
52
|
+
}
|
|
53
|
+
export interface X402Challenge extends X402ChallengeInput {
|
|
54
|
+
version: string;
|
|
55
|
+
fee?: X402FeeTerms;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Receipt shape used by specialist-side verifiers. This package deliberately
|
|
59
|
+
* does not require secrets or submit transactions.
|
|
60
|
+
*/
|
|
61
|
+
export interface X402PaymentReceipt {
|
|
62
|
+
network: SolanaPaymentNetwork;
|
|
63
|
+
payTo: string;
|
|
64
|
+
amount: string | number;
|
|
65
|
+
currency: string;
|
|
66
|
+
nonce: string;
|
|
67
|
+
signature?: string;
|
|
68
|
+
txSignature?: string;
|
|
69
|
+
payer?: string;
|
|
70
|
+
mint?: string;
|
|
71
|
+
destinationTokenAccount?: string;
|
|
72
|
+
demo?: boolean;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Payment receipt after successful SOL transfer.
|
|
76
|
+
*/
|
|
77
|
+
export interface PaymentReceipt {
|
|
78
|
+
txSignature: string;
|
|
79
|
+
slot: number;
|
|
80
|
+
lamports: number;
|
|
81
|
+
nonce: string;
|
|
82
|
+
settlementCurrency?: string;
|
|
83
|
+
swap?: {
|
|
84
|
+
performed: boolean;
|
|
85
|
+
fromCurrency?: string;
|
|
86
|
+
toCurrency?: string;
|
|
87
|
+
orderId?: string;
|
|
88
|
+
executeId?: string;
|
|
89
|
+
inAmount?: string;
|
|
90
|
+
outAmount?: string;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export type ReceiptVerificationFailureReason = 'invalid_receipt' | 'invalid_payee' | 'invalid_nonce' | 'duplicate_nonce' | 'wrong_amount' | 'wrong_currency' | 'wrong_payee' | 'wrong_network' | 'demo_payment_disabled' | 'unsupported_receipt' | 'payer_proof_required' | 'payer_proof_invalid' | 'payer_proof_expired';
|
|
94
|
+
/** The payment a direct receipt proved, handed to a payer-proof check. */
|
|
95
|
+
export interface ProvenDirectPayment {
|
|
96
|
+
network: SolanaPaymentNetwork;
|
|
97
|
+
txSignature: string;
|
|
98
|
+
/** The wallet that signed the transaction and moved the funds. */
|
|
99
|
+
payer: string;
|
|
100
|
+
payTo: string;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Checks that the request presenting a direct receipt comes from the wallet
|
|
104
|
+
* that paid. `directPaymentProofCheck` builds one from the request's headers
|
|
105
|
+
* and raw body.
|
|
106
|
+
*/
|
|
107
|
+
export type PayerProofCheck = (paid: ProvenDirectPayment) => {
|
|
108
|
+
ok: true;
|
|
109
|
+
} | {
|
|
110
|
+
ok: false;
|
|
111
|
+
reason: 'payer_proof_required' | 'payer_proof_invalid' | 'payer_proof_expired';
|
|
112
|
+
message: string;
|
|
113
|
+
} | Promise<{
|
|
114
|
+
ok: true;
|
|
115
|
+
} | {
|
|
116
|
+
ok: false;
|
|
117
|
+
reason: 'payer_proof_required' | 'payer_proof_invalid' | 'payer_proof_expired';
|
|
118
|
+
message: string;
|
|
119
|
+
}>;
|
|
120
|
+
export type ReceiptVerificationResult = {
|
|
121
|
+
ok: true;
|
|
122
|
+
receipt: X402PaymentReceipt;
|
|
123
|
+
demo: boolean;
|
|
124
|
+
fee?: X402FeeTerms;
|
|
125
|
+
} | {
|
|
126
|
+
ok: false;
|
|
127
|
+
reason: ReceiptVerificationFailureReason;
|
|
128
|
+
message: string;
|
|
129
|
+
expected?: unknown;
|
|
130
|
+
actual?: unknown;
|
|
131
|
+
};
|
|
132
|
+
export interface NonceReplayStore {
|
|
133
|
+
checkAndStore(nonce: string): boolean | Promise<boolean>;
|
|
134
|
+
/**
|
|
135
|
+
* Records every key or none: true when all of them were new and are now
|
|
136
|
+
* stored, false when any was already present (and then none is stored).
|
|
137
|
+
* Stores that can do this atomically should; a verifier that records two keys
|
|
138
|
+
* for one payment uses it so a failure between them cannot leave half a record.
|
|
139
|
+
*/
|
|
140
|
+
checkAndStoreAll?(keys: string[]): boolean | Promise<boolean>;
|
|
141
|
+
}
|
|
142
|
+
export interface ReceiptVerifier {
|
|
143
|
+
verifyReceipt(receipt: unknown, challenge: X402Challenge, replayStore?: NonceReplayStore, payerProof?: PayerProofCheck): Promise<ReceiptVerificationResult>;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* x402 error codes.
|
|
147
|
+
*/
|
|
148
|
+
export type X402Error = 'insufficient_funds' | 'duplicate_nonce' | 'invalid_request' | 'rpc_timeout' | 'unauthorized';
|
package/dist/types.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,111 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@redditech/x402-solana",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "x402 payments on Solana for Reddi Agent Protocol: per-token pricing, metered escrow, payment checks and receipts for AI agent buyers and providers.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/nissan/reddi-agent-protocol.git",
|
|
9
|
+
"directory": "packages/x402-solana"
|
|
10
|
+
},
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"types": "dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"require": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./budget-policy": {
|
|
20
|
+
"types": "./dist/budget-policy.d.ts",
|
|
21
|
+
"import": "./dist/budget-policy.js",
|
|
22
|
+
"require": "./dist/budget-policy.js"
|
|
23
|
+
},
|
|
24
|
+
"./client": {
|
|
25
|
+
"types": "./dist/client.d.ts",
|
|
26
|
+
"import": "./dist/client.js",
|
|
27
|
+
"require": "./dist/client.js"
|
|
28
|
+
},
|
|
29
|
+
"./jupiter": {
|
|
30
|
+
"types": "./dist/jupiter.d.ts",
|
|
31
|
+
"import": "./dist/jupiter.js",
|
|
32
|
+
"require": "./dist/jupiter.js"
|
|
33
|
+
},
|
|
34
|
+
"./middleware": {
|
|
35
|
+
"types": "./dist/middleware.d.ts",
|
|
36
|
+
"import": "./dist/middleware.js",
|
|
37
|
+
"require": "./dist/middleware.js"
|
|
38
|
+
},
|
|
39
|
+
"./nonce": {
|
|
40
|
+
"types": "./dist/nonce.d.ts",
|
|
41
|
+
"import": "./dist/nonce.js",
|
|
42
|
+
"require": "./dist/nonce.js"
|
|
43
|
+
},
|
|
44
|
+
"./payment": {
|
|
45
|
+
"types": "./dist/payment.d.ts",
|
|
46
|
+
"import": "./dist/payment.js",
|
|
47
|
+
"require": "./dist/payment.js"
|
|
48
|
+
},
|
|
49
|
+
"./spl-token-observer": {
|
|
50
|
+
"types": "./dist/spl-token-observer.d.ts",
|
|
51
|
+
"import": "./dist/spl-token-observer.js",
|
|
52
|
+
"require": "./dist/spl-token-observer.js"
|
|
53
|
+
},
|
|
54
|
+
"./types": {
|
|
55
|
+
"types": "./dist/types.d.ts",
|
|
56
|
+
"import": "./dist/types.js",
|
|
57
|
+
"require": "./dist/types.js"
|
|
58
|
+
},
|
|
59
|
+
"./provider": {
|
|
60
|
+
"types": "./dist/provider.d.ts",
|
|
61
|
+
"import": "./dist/provider.js",
|
|
62
|
+
"require": "./dist/provider.js"
|
|
63
|
+
},
|
|
64
|
+
"./metered": {
|
|
65
|
+
"types": "./dist/metered.d.ts",
|
|
66
|
+
"import": "./dist/metered.js",
|
|
67
|
+
"require": "./dist/metered.js"
|
|
68
|
+
},
|
|
69
|
+
"./token-escrow": {
|
|
70
|
+
"types": "./dist/token-escrow.d.ts",
|
|
71
|
+
"import": "./dist/token-escrow.js",
|
|
72
|
+
"require": "./dist/token-escrow.js"
|
|
73
|
+
},
|
|
74
|
+
"./escrow-readiness": {
|
|
75
|
+
"types": "./dist/escrow-readiness.d.ts",
|
|
76
|
+
"import": "./dist/escrow-readiness.js",
|
|
77
|
+
"require": "./dist/escrow-readiness.js"
|
|
78
|
+
},
|
|
79
|
+
"./rating": {
|
|
80
|
+
"types": "./dist/rating.d.ts",
|
|
81
|
+
"import": "./dist/rating.js",
|
|
82
|
+
"require": "./dist/rating.js"
|
|
83
|
+
},
|
|
84
|
+
"./package.json": "./package.json"
|
|
85
|
+
},
|
|
86
|
+
"files": [
|
|
87
|
+
"dist",
|
|
88
|
+
"README.md",
|
|
89
|
+
"CHANGELOG.md"
|
|
90
|
+
],
|
|
91
|
+
"sideEffects": false,
|
|
92
|
+
"scripts": {
|
|
93
|
+
"build": "node ./node_modules/typescript/lib/tsc.js",
|
|
94
|
+
"test": "jest",
|
|
95
|
+
"clean": "rm -rf dist",
|
|
96
|
+
"check:artifacts": "node ../../scripts/check-package-artifact-contents.mjs --dir packages/x402-solana",
|
|
97
|
+
"release:dry-run": "npm run clean && npm run build && npm test -- --runInBand && npm run check:artifacts && npm pack --dry-run",
|
|
98
|
+
"example:local": "node examples/local-puzzle.cjs"
|
|
99
|
+
},
|
|
100
|
+
"dependencies": {
|
|
101
|
+
"@solana/spl-token": "^0.4.14",
|
|
102
|
+
"@solana/web3.js": "^1.95.8"
|
|
103
|
+
},
|
|
104
|
+
"devDependencies": {
|
|
105
|
+
"typescript": "^5",
|
|
106
|
+
"jest": "^29",
|
|
107
|
+
"ts-jest": "^29",
|
|
108
|
+
"@types/jest": "^29",
|
|
109
|
+
"@types/node": "^20"
|
|
110
|
+
}
|
|
111
|
+
}
|