aether-agent-sdk 3.1.1 → 3.2.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 +1 -0
- package/dist/src/agents/SettlementAgent.d.ts +5 -7
- package/dist/src/agents/SettlementAgent.d.ts.map +1 -1
- package/dist/src/agents/SettlementAgent.js +25 -36
- package/dist/src/agents/SettlementAgent.js.map +1 -1
- package/dist/src/agents/index.d.ts +1 -0
- package/dist/src/agents/index.d.ts.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/paygate/PayGateClient.d.ts +92 -0
- package/dist/src/paygate/PayGateClient.d.ts.map +1 -0
- package/dist/src/paygate/PayGateClient.js +396 -0
- package/dist/src/paygate/PayGateClient.js.map +1 -0
- package/dist/src/paygate/index.d.ts +7 -0
- package/dist/src/paygate/index.d.ts.map +1 -0
- package/dist/src/paygate/index.js +11 -0
- package/dist/src/paygate/index.js.map +1 -0
- package/dist/src/paygate/types.d.ts +180 -0
- package/dist/src/paygate/types.d.ts.map +1 -0
- package/dist/src/paygate/types.js +7 -0
- package/dist/src/paygate/types.js.map +1 -0
- package/dist/src/utils/index.d.ts +2 -0
- package/dist/src/utils/index.d.ts.map +1 -1
- package/dist/src/utils/index.js +10 -1
- package/dist/src/utils/index.js.map +1 -1
- package/dist/src/utils/tokens.d.ts +16 -0
- package/dist/src/utils/tokens.d.ts.map +1 -0
- package/dist/src/utils/tokens.js +31 -0
- package/dist/src/utils/tokens.js.map +1 -0
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -46,6 +46,7 @@ Aether is a production-ready SDK for building autonomous agent-to-agent systems
|
|
|
46
46
|
### Agent Framework
|
|
47
47
|
|
|
48
48
|
- **SettlementAgent**: Executes x402 payments and settlement on-chain
|
|
49
|
+
- **PayGateClient**: Client for purchasing x402-protected content from PayGate
|
|
49
50
|
- **x402 Facilitator**: Payment verification and USDC transfers
|
|
50
51
|
- **Protocol Support**: A2A and AP2 protocol implementations
|
|
51
52
|
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { Keypair } from '@solana/web3.js';
|
|
2
|
+
import { PaymentToken } from '../utils/tokens';
|
|
3
|
+
export interface PaymentOptions {
|
|
4
|
+
token?: PaymentToken;
|
|
5
|
+
}
|
|
2
6
|
export declare class SettlementAgent {
|
|
3
7
|
private connection;
|
|
4
8
|
private agentWallet?;
|
|
@@ -10,16 +14,10 @@ export declare class SettlementAgent {
|
|
|
10
14
|
constructor(merchantWallet?: string);
|
|
11
15
|
triggerSettlement(verification: any): Promise<void>;
|
|
12
16
|
init(wallet?: Keypair): Promise<void>;
|
|
13
|
-
/**
|
|
14
|
-
* Set merchant wallet dynamically (for marketplace consumer)
|
|
15
|
-
*/
|
|
16
17
|
setMerchantWallet(merchantWallet: string): void;
|
|
17
18
|
private createPaymentRequirements;
|
|
18
19
|
private executeSettlement;
|
|
19
20
|
private createPaymentPayload;
|
|
20
|
-
|
|
21
|
-
* Creates a signed x402 payment
|
|
22
|
-
*/
|
|
23
|
-
createSignedPayment(recipientAddress: string, amountUsdc: number): Promise<string>;
|
|
21
|
+
createSignedPayment(recipientAddress: string, amount: number, options?: PaymentOptions): Promise<string>;
|
|
24
22
|
}
|
|
25
23
|
//# sourceMappingURL=SettlementAgent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SettlementAgent.d.ts","sourceRoot":"","sources":["../../../src/agents/SettlementAgent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,OAAO,EAAe,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"SettlementAgent.d.ts","sourceRoot":"","sources":["../../../src/agents/SettlementAgent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,OAAO,EAAe,MAAM,iBAAiB,CAAA;AAM7E,OAAO,EAAE,YAAY,EAAwC,MAAM,iBAAiB,CAAA;AAKpF,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,EAAE,YAAY,CAAA;CACrB;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,UAAU,CAAY;IAC9B,OAAO,CAAC,WAAW,CAAC,CAAS;IAC7B,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,cAAc,CAAC,CAAQ;IAC/B,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,MAAM,CAAkC;gBAEpC,cAAc,CAAC,EAAE,MAAM;IAyB7B,iBAAiB,CAAC,YAAY,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAKnD,IAAI,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAqB3C,iBAAiB,CAAC,cAAc,EAAE,MAAM;IAIxC,OAAO,CAAC,yBAAyB;YAsBnB,iBAAiB;IAsC/B,OAAO,CAAC,oBAAoB;IAwBtB,mBAAmB,CACvB,gBAAgB,EAAE,MAAM,EACxB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,MAAM,CAAC;CAyFnB"}
|
|
@@ -10,6 +10,7 @@ const X402FacilitatorServer_1 = require("../facilitator/X402FacilitatorServer");
|
|
|
10
10
|
const solana_1 = require("../utils/solana");
|
|
11
11
|
const wallet_1 = require("../utils/wallet");
|
|
12
12
|
const logger_1 = require("../utils/logger");
|
|
13
|
+
const tokens_1 = require("../utils/tokens");
|
|
13
14
|
const dotenv_1 = __importDefault(require("dotenv"));
|
|
14
15
|
dotenv_1.default.config();
|
|
15
16
|
class SettlementAgent {
|
|
@@ -24,7 +25,6 @@ class SettlementAgent {
|
|
|
24
25
|
const { network, rpcUrl, networkId } = (0, solana_1.resolveSolanaNetwork)();
|
|
25
26
|
this.network = network;
|
|
26
27
|
this.networkId = networkId;
|
|
27
|
-
// Allow merchant wallet from parameter or env variable
|
|
28
28
|
if (merchantWallet) {
|
|
29
29
|
this.merchantWallet = merchantWallet;
|
|
30
30
|
}
|
|
@@ -50,7 +50,6 @@ class SettlementAgent {
|
|
|
50
50
|
}
|
|
51
51
|
async init(wallet) {
|
|
52
52
|
try {
|
|
53
|
-
// If a wallet is provided, use it instead of loading from env
|
|
54
53
|
if (wallet) {
|
|
55
54
|
this.agentWallet = wallet;
|
|
56
55
|
this.logger.info(`Settlement Agent initialized with provided wallet ${wallet.publicKey.toBase58()}`);
|
|
@@ -70,34 +69,32 @@ class SettlementAgent {
|
|
|
70
69
|
throw error;
|
|
71
70
|
}
|
|
72
71
|
}
|
|
73
|
-
/**
|
|
74
|
-
* Set merchant wallet dynamically (for marketplace consumer)
|
|
75
|
-
*/
|
|
76
72
|
setMerchantWallet(merchantWallet) {
|
|
77
73
|
this.merchantWallet = merchantWallet;
|
|
78
74
|
}
|
|
79
|
-
createPaymentRequirements() {
|
|
75
|
+
createPaymentRequirements(token = 'usdc') {
|
|
80
76
|
if (!this.merchantWallet) {
|
|
81
77
|
throw new Error('Merchant wallet not set. Call setMerchantWallet() first.');
|
|
82
78
|
}
|
|
83
79
|
const paymentAmount = parseFloat(process.env.DEFAULT_PAYMENT_AMOUNT_USDC || '1.0');
|
|
84
|
-
const
|
|
80
|
+
const amountInMicro = (0, tokens_1.tokenToAmount)(paymentAmount);
|
|
81
|
+
const mint = (0, tokens_1.getTokenMintPublicKey)(token, (0, solana_1.isMainnet)(this.network));
|
|
85
82
|
return {
|
|
86
83
|
scheme: 'exact',
|
|
87
84
|
network: this.networkId,
|
|
88
|
-
asset:
|
|
85
|
+
asset: mint.toBase58(),
|
|
89
86
|
payTo: this.merchantWallet,
|
|
90
|
-
maxAmountRequired:
|
|
87
|
+
maxAmountRequired: amountInMicro.toString(),
|
|
91
88
|
resource: '/agent-settlement',
|
|
92
|
-
description:
|
|
89
|
+
description: `A2A agent settlement via x402 on Solana (${token.toUpperCase()})`,
|
|
93
90
|
mimeType: 'application/json',
|
|
94
91
|
maxTimeoutSeconds: 120
|
|
95
92
|
};
|
|
96
93
|
}
|
|
97
|
-
async executeSettlement(verification) {
|
|
94
|
+
async executeSettlement(verification, token = 'usdc') {
|
|
98
95
|
try {
|
|
99
96
|
this.logger.info('Initiating settlement flow on Solana');
|
|
100
|
-
const requirements = this.createPaymentRequirements();
|
|
97
|
+
const requirements = this.createPaymentRequirements(token);
|
|
101
98
|
this.logger.info('Step 1: Creating payment authorization');
|
|
102
99
|
const paymentPayload = this.createPaymentPayload(requirements);
|
|
103
100
|
const paymentHeader = Buffer.from(JSON.stringify(paymentPayload)).toString('base64');
|
|
@@ -108,7 +105,7 @@ class SettlementAgent {
|
|
|
108
105
|
throw new Error(`Payment verification failed: ${verificationResult.invalidReason}`);
|
|
109
106
|
}
|
|
110
107
|
this.logger.info('Payment verification successful');
|
|
111
|
-
this.logger.info(
|
|
108
|
+
this.logger.info(`Step 3: Settling payment and executing ${token.toUpperCase()} transfer`);
|
|
112
109
|
const settlementResult = await this.facilitator.settle(paymentHeader, requirements);
|
|
113
110
|
if (!settlementResult.success) {
|
|
114
111
|
throw new Error(`Payment settlement failed: ${settlementResult.error}`);
|
|
@@ -144,41 +141,34 @@ class SettlementAgent {
|
|
|
144
141
|
}
|
|
145
142
|
};
|
|
146
143
|
}
|
|
147
|
-
|
|
148
|
-
* Creates a signed x402 payment
|
|
149
|
-
*/
|
|
150
|
-
async createSignedPayment(recipientAddress, amountUsdc) {
|
|
144
|
+
async createSignedPayment(recipientAddress, amount, options = {}) {
|
|
151
145
|
try {
|
|
152
146
|
if (!this.agentWallet) {
|
|
153
147
|
throw new Error('Agent wallet not initialized');
|
|
154
148
|
}
|
|
149
|
+
const token = options.token || 'usdc';
|
|
150
|
+
const tokenSymbol = token.toUpperCase();
|
|
155
151
|
this.logger.info('Creating signed x402 payment');
|
|
156
|
-
this.logger.info(`Amount: ${
|
|
152
|
+
this.logger.info(`Amount: ${amount} ${tokenSymbol}`);
|
|
157
153
|
this.logger.info(`Recipient: ${recipientAddress}`);
|
|
158
|
-
const
|
|
154
|
+
const amountInMicro = (0, tokens_1.tokenToAmount)(amount);
|
|
159
155
|
const recipientPubkey = new web3_js_1.PublicKey(recipientAddress);
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
const fromTokenAccount = await token.getOrCreateAssociatedAccountInfo(this.agentWallet.publicKey);
|
|
165
|
-
const toTokenAccount = await token.getOrCreateAssociatedAccountInfo(recipientPubkey);
|
|
156
|
+
const mint = (0, tokens_1.getTokenMintPublicKey)(token, (0, solana_1.isMainnet)(this.network));
|
|
157
|
+
const tokenInstance = new spl_token_1.Token(this.connection, mint, spl_token_1.TOKEN_PROGRAM_ID, this.agentWallet);
|
|
158
|
+
const fromTokenAccount = await tokenInstance.getOrCreateAssociatedAccountInfo(this.agentWallet.publicKey);
|
|
159
|
+
const toTokenAccount = await tokenInstance.getOrCreateAssociatedAccountInfo(recipientPubkey);
|
|
166
160
|
this.logger.debug(`From: ${this.agentWallet.publicKey.toBase58()}`);
|
|
167
161
|
this.logger.debug(`To: ${recipientAddress}`);
|
|
168
|
-
|
|
169
|
-
const transferInstruction = spl_token_1.Token.createTransferInstruction(spl_token_1.TOKEN_PROGRAM_ID, fromTokenAccount.address, toTokenAccount.address, this.agentWallet.publicKey, [],
|
|
170
|
-
// Create transaction
|
|
162
|
+
this.logger.debug(`Mint: ${mint.toBase58()}`);
|
|
163
|
+
const transferInstruction = spl_token_1.Token.createTransferInstruction(spl_token_1.TOKEN_PROGRAM_ID, fromTokenAccount.address, toTokenAccount.address, this.agentWallet.publicKey, [], amountInMicro);
|
|
171
164
|
const transaction = new web3_js_1.Transaction().add(transferInstruction);
|
|
172
|
-
// Get recent blockhash
|
|
173
165
|
const { blockhash, lastValidBlockHeight } = await this.connection.getLatestBlockhash('confirmed');
|
|
174
166
|
transaction.recentBlockhash = blockhash;
|
|
175
167
|
transaction.lastValidBlockHeight = lastValidBlockHeight;
|
|
176
168
|
transaction.feePayer = this.agentWallet.publicKey;
|
|
177
|
-
// Sign transaction
|
|
178
169
|
transaction.sign(this.agentWallet);
|
|
179
170
|
this.logger.info('Transaction signed');
|
|
180
|
-
|
|
181
|
-
const validBefore = Math.floor(Date.now() / 1000) + 300; // 5 minutes
|
|
171
|
+
const validBefore = Math.floor(Date.now() / 1000) + 300;
|
|
182
172
|
const paymentPayload = {
|
|
183
173
|
x402Version: 1,
|
|
184
174
|
scheme: 'exact',
|
|
@@ -187,8 +177,8 @@ class SettlementAgent {
|
|
|
187
177
|
authorization: {
|
|
188
178
|
from: this.agentWallet.publicKey.toBase58(),
|
|
189
179
|
to: recipientAddress,
|
|
190
|
-
value:
|
|
191
|
-
asset:
|
|
180
|
+
value: amountInMicro.toString(),
|
|
181
|
+
asset: mint.toBase58(),
|
|
192
182
|
validBefore: validBefore,
|
|
193
183
|
nonce: (0, solana_1.createNonce)()
|
|
194
184
|
},
|
|
@@ -199,9 +189,8 @@ class SettlementAgent {
|
|
|
199
189
|
}
|
|
200
190
|
}
|
|
201
191
|
};
|
|
202
|
-
// Encode to base64
|
|
203
192
|
const paymentHeader = Buffer.from(JSON.stringify(paymentPayload)).toString('base64');
|
|
204
|
-
this.logger.info(
|
|
193
|
+
this.logger.info(`x402 payment created (${tokenSymbol}, signed transaction included)`);
|
|
205
194
|
return paymentHeader;
|
|
206
195
|
}
|
|
207
196
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SettlementAgent.js","sourceRoot":"","sources":["../../../src/agents/SettlementAgent.ts"],"names":[],"mappings":";;;;;;AAAA,6CAA6E;AAC7E,iDAA2D;AAC3D,gFAA4E;AAC5E,
|
|
1
|
+
{"version":3,"file":"SettlementAgent.js","sourceRoot":"","sources":["../../../src/agents/SettlementAgent.ts"],"names":[],"mappings":";;;;;;AAAA,6CAA6E;AAC7E,iDAA2D;AAC3D,gFAA4E;AAC5E,4CAA6F;AAC7F,4CAAoD;AACpD,4CAA8C;AAC9C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M,KAAK,CAAA;QACb,CAAC;IACH,CAAC;CACF;AAjPD,0CAiPC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/agents/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/agents/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA"}
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAiBH,cAAc,UAAU,CAAA;AAGxB,cAAc,eAAe,CAAA;AAG7B,cAAc,eAAe,CAAA;AAG7B,cAAc,SAAS,CAAA;AAEvB;;GAEG;AACH,eAAO,MAAM,OAAO,QAAc,CAAA;AAElC;;GAEG;AACH,eAAO,MAAM,QAAQ,QAAW,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAiBH,cAAc,UAAU,CAAA;AAGxB,cAAc,eAAe,CAAA;AAG7B,cAAc,eAAe,CAAA;AAG7B,cAAc,WAAW,CAAA;AAGzB,cAAc,SAAS,CAAA;AAEvB;;GAEG;AACH,eAAO,MAAM,OAAO,QAAc,CAAA;AAElC;;GAEG;AACH,eAAO,MAAM,QAAQ,QAAW,CAAA"}
|
package/dist/src/index.js
CHANGED
|
@@ -43,6 +43,8 @@ __exportStar(require("./agents"), exports);
|
|
|
43
43
|
__exportStar(require("./facilitator"), exports);
|
|
44
44
|
// Marketplace
|
|
45
45
|
__exportStar(require("./marketplace"), exports);
|
|
46
|
+
// PayGate
|
|
47
|
+
__exportStar(require("./paygate"), exports);
|
|
46
48
|
// Utils
|
|
47
49
|
__exportStar(require("./utils"), exports);
|
|
48
50
|
/**
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;;;;;AAEH,gDAAuB;AAEvB,SAAS,sBAAsB;IAC7B,IAAI,CAAC;QACH,kDAAkD;QAClD,MAAM,GAAG,GAAG,OAAO,CAAC,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC,CAAA;QACxE,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,IAAc,EAAE,OAAO,EAAE,GAAG,CAAC,OAAiB,EAAE,CAAA;IACrE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,EAAE,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,SAAS,EAAE,CAAA;IACzD,CAAC;AACH,CAAC;AAED,MAAM,GAAG,GAAG,sBAAsB,EAAE,CAAA;AAEpC,SAAS;AACT,2CAAwB;AAExB,cAAc;AACd,gDAA6B;AAE7B,cAAc;AACd,gDAA6B;AAE7B,QAAQ;AACR,0CAAuB;AAEvB;;GAEG;AACU,QAAA,OAAO,GAAG,GAAG,CAAC,OAAO,CAAA;AAElC;;GAEG;AACU,QAAA,QAAQ,GAAG,GAAG,CAAC,IAAI,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;;;;;AAEH,gDAAuB;AAEvB,SAAS,sBAAsB;IAC7B,IAAI,CAAC;QACH,kDAAkD;QAClD,MAAM,GAAG,GAAG,OAAO,CAAC,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC,CAAA;QACxE,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,IAAc,EAAE,OAAO,EAAE,GAAG,CAAC,OAAiB,EAAE,CAAA;IACrE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,EAAE,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,SAAS,EAAE,CAAA;IACzD,CAAC;AACH,CAAC;AAED,MAAM,GAAG,GAAG,sBAAsB,EAAE,CAAA;AAEpC,SAAS;AACT,2CAAwB;AAExB,cAAc;AACd,gDAA6B;AAE7B,cAAc;AACd,gDAA6B;AAE7B,UAAU;AACV,4CAAyB;AAEzB,QAAQ;AACR,0CAAuB;AAEvB;;GAEG;AACU,QAAA,OAAO,GAAG,GAAG,CAAC,OAAO,CAAA;AAElC;;GAEG;AACU,QAAA,QAAQ,GAAG,GAAG,CAAC,IAAI,CAAA"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PayGate Client
|
|
3
|
+
* Client for interacting with PayGate x402 payment protocol
|
|
4
|
+
*/
|
|
5
|
+
import { Keypair } from '@solana/web3.js';
|
|
6
|
+
import { PayGateClientConfig, PaymentCurrency, Product, PaymentRequirements, PricingResponse, VerifyResponse, PurchaseOptions, PurchaseResult, ContentResult, PurchaseHistoryResponse } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Error class for PayGate-specific errors
|
|
9
|
+
*/
|
|
10
|
+
export declare class PayGateError extends Error {
|
|
11
|
+
readonly statusCode: number | undefined;
|
|
12
|
+
readonly code: string | undefined;
|
|
13
|
+
constructor(message: string, statusCode?: number, code?: string);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* PayGate client for purchasing and retrieving x402-protected content
|
|
17
|
+
*/
|
|
18
|
+
export declare class PayGateClient {
|
|
19
|
+
private baseUrl;
|
|
20
|
+
private wallet;
|
|
21
|
+
private defaultCurrency;
|
|
22
|
+
private timeout;
|
|
23
|
+
private http;
|
|
24
|
+
private settlementAgent;
|
|
25
|
+
private logger;
|
|
26
|
+
constructor(config: PayGateClientConfig);
|
|
27
|
+
/**
|
|
28
|
+
* Initialize the client with a wallet for signing payments
|
|
29
|
+
* @param wallet Optional wallet keypair (loads from env if not provided)
|
|
30
|
+
*/
|
|
31
|
+
init(wallet?: Keypair): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Fetch product information
|
|
34
|
+
* @param productId The product ID
|
|
35
|
+
* @returns Product information
|
|
36
|
+
*/
|
|
37
|
+
fetchProduct(productId: string): Promise<Product>;
|
|
38
|
+
/**
|
|
39
|
+
* Get full payment requirements from x402 402 response
|
|
40
|
+
* @param productId The product ID
|
|
41
|
+
* @returns Payment requirements
|
|
42
|
+
*/
|
|
43
|
+
getPaymentRequirements(productId: string): Promise<PaymentRequirements>;
|
|
44
|
+
/**
|
|
45
|
+
* Get pricing options for a product (USDC/ATHR)
|
|
46
|
+
* @param productId The product ID
|
|
47
|
+
* @returns Pricing options
|
|
48
|
+
*/
|
|
49
|
+
getPricing(productId: string): Promise<PricingResponse>;
|
|
50
|
+
/**
|
|
51
|
+
* Verify payment details before purchase
|
|
52
|
+
* @param productId The product ID
|
|
53
|
+
* @param amount The payment amount
|
|
54
|
+
* @param currency The payment currency
|
|
55
|
+
* @returns Verification result
|
|
56
|
+
*/
|
|
57
|
+
verify(productId: string, amount: string, currency?: PaymentCurrency): Promise<VerifyResponse>;
|
|
58
|
+
/**
|
|
59
|
+
* Purchase a product using the x402 flow
|
|
60
|
+
* @param productId The product ID
|
|
61
|
+
* @param options Purchase options
|
|
62
|
+
* @returns Purchase result with transaction hash and delivery URL
|
|
63
|
+
*/
|
|
64
|
+
purchase(productId: string, options?: PurchaseOptions): Promise<PurchaseResult>;
|
|
65
|
+
/**
|
|
66
|
+
* Get content for a purchased product
|
|
67
|
+
* @param productId The product ID
|
|
68
|
+
* @returns Content delivery result
|
|
69
|
+
*/
|
|
70
|
+
getContent(productId: string): Promise<ContentResult>;
|
|
71
|
+
/**
|
|
72
|
+
* Get purchase history for the current wallet
|
|
73
|
+
* @returns Purchase history
|
|
74
|
+
*/
|
|
75
|
+
getPurchaseHistory(): Promise<PurchaseHistoryResponse>;
|
|
76
|
+
/**
|
|
77
|
+
* Check if the current wallet has already purchased a product
|
|
78
|
+
* @param productId The product ID
|
|
79
|
+
* @returns True if already purchased
|
|
80
|
+
*/
|
|
81
|
+
hasPurchased(productId: string): Promise<boolean>;
|
|
82
|
+
/**
|
|
83
|
+
* Get the current wallet public key
|
|
84
|
+
* @returns Wallet public key as base58 string, or undefined if not initialized
|
|
85
|
+
*/
|
|
86
|
+
getWalletAddress(): string | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Handle and log errors consistently
|
|
89
|
+
*/
|
|
90
|
+
private handleError;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=PayGateClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PayGateClient.d.ts","sourceRoot":"","sources":["../../../src/paygate/PayGateClient.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAKzC,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,OAAO,EACP,mBAAmB,EAEnB,eAAe,EACf,cAAc,EAEd,eAAe,EACf,cAAc,EACd,aAAa,EAEb,uBAAuB,EACxB,MAAM,SAAS,CAAA;AAEhB;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,SAAgB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;IAC9C,SAAgB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAA;gBAE5B,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;CAMhE;AAED;;GAEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,OAAO,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Client for interacting with PayGate x402 payment protocol
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.PayGateClient = exports.PayGateError = void 0;
|
|
41
|
+
const axios_1 = __importStar(require("axios"));
|
|
42
|
+
const SettlementAgent_1 = require("../agents/SettlementAgent");
|
|
43
|
+
const wallet_1 = require("../utils/wallet");
|
|
44
|
+
const logger_1 = require("../utils/logger");
|
|
45
|
+
/**
|
|
46
|
+
* Error class for PayGate-specific errors
|
|
47
|
+
*/
|
|
48
|
+
class PayGateError extends Error {
|
|
49
|
+
statusCode;
|
|
50
|
+
code;
|
|
51
|
+
constructor(message, statusCode, code) {
|
|
52
|
+
super(message);
|
|
53
|
+
this.name = 'PayGateError';
|
|
54
|
+
this.statusCode = statusCode;
|
|
55
|
+
this.code = code;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.PayGateError = PayGateError;
|
|
59
|
+
/**
|
|
60
|
+
* PayGate client for purchasing and retrieving x402-protected content
|
|
61
|
+
*/
|
|
62
|
+
class PayGateClient {
|
|
63
|
+
baseUrl;
|
|
64
|
+
wallet;
|
|
65
|
+
defaultCurrency;
|
|
66
|
+
timeout;
|
|
67
|
+
http;
|
|
68
|
+
settlementAgent;
|
|
69
|
+
logger = (0, logger_1.createLogger)('PayGateClient');
|
|
70
|
+
constructor(config) {
|
|
71
|
+
this.baseUrl = config.baseUrl.replace(/\/$/, '');
|
|
72
|
+
this.wallet = config.wallet;
|
|
73
|
+
this.defaultCurrency = config.defaultCurrency || 'USDC';
|
|
74
|
+
this.timeout = config.timeout || 30000;
|
|
75
|
+
this.http = axios_1.default.create({
|
|
76
|
+
baseURL: this.baseUrl,
|
|
77
|
+
timeout: this.timeout,
|
|
78
|
+
headers: {
|
|
79
|
+
'Content-Type': 'application/json'
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
this.logger.info(`PayGateClient initialized for ${this.baseUrl}`);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Initialize the client with a wallet for signing payments
|
|
86
|
+
* @param wallet Optional wallet keypair (loads from env if not provided)
|
|
87
|
+
*/
|
|
88
|
+
async init(wallet) {
|
|
89
|
+
try {
|
|
90
|
+
if (wallet) {
|
|
91
|
+
this.wallet = wallet;
|
|
92
|
+
this.logger.info(`Initialized with provided wallet: ${wallet.publicKey.toBase58()}`);
|
|
93
|
+
}
|
|
94
|
+
else if (!this.wallet) {
|
|
95
|
+
const { keypair } = (0, wallet_1.loadKeypairFromEnv)();
|
|
96
|
+
if (keypair) {
|
|
97
|
+
this.wallet = keypair;
|
|
98
|
+
this.logger.info(`Initialized with wallet from env: ${keypair.publicKey.toBase58()}`);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
this.logger.warn('No wallet configured. Purchase functionality will be unavailable.');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (this.wallet) {
|
|
105
|
+
this.settlementAgent = new SettlementAgent_1.SettlementAgent();
|
|
106
|
+
await this.settlementAgent.init(this.wallet);
|
|
107
|
+
this.logger.info('SettlementAgent initialized');
|
|
108
|
+
}
|
|
109
|
+
this.logger.info('PayGateClient ready');
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
this.logger.error('Failed to initialize PayGateClient', error);
|
|
113
|
+
throw new PayGateError(`Initialization failed: ${error.message}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Fetch product information
|
|
118
|
+
* @param productId The product ID
|
|
119
|
+
* @returns Product information
|
|
120
|
+
*/
|
|
121
|
+
async fetchProduct(productId) {
|
|
122
|
+
try {
|
|
123
|
+
this.logger.info(`Fetching product: ${productId}`);
|
|
124
|
+
const response = await this.http.get(`/pay/${productId}`, {
|
|
125
|
+
validateStatus: (status) => status === 200 || status === 402
|
|
126
|
+
});
|
|
127
|
+
if (response.status === 402) {
|
|
128
|
+
const data = response.data;
|
|
129
|
+
if (data.accepts && data.accepts.length > 0) {
|
|
130
|
+
const req = data.accepts[0];
|
|
131
|
+
if (req) {
|
|
132
|
+
return {
|
|
133
|
+
id: req.productId || productId,
|
|
134
|
+
title: req.description || productId,
|
|
135
|
+
description: req.description || '',
|
|
136
|
+
type: 'content_link',
|
|
137
|
+
price: req.amount,
|
|
138
|
+
currency: req.currency,
|
|
139
|
+
network: req.network,
|
|
140
|
+
status: 'active'
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return response.data;
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
this.handleError('fetchProduct', error);
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Get full payment requirements from x402 402 response
|
|
154
|
+
* @param productId The product ID
|
|
155
|
+
* @returns Payment requirements
|
|
156
|
+
*/
|
|
157
|
+
async getPaymentRequirements(productId) {
|
|
158
|
+
try {
|
|
159
|
+
this.logger.info(`Getting payment requirements for: ${productId}`);
|
|
160
|
+
const response = await this.http.get(`/pay/${productId}`, {
|
|
161
|
+
validateStatus: (status) => status === 402
|
|
162
|
+
});
|
|
163
|
+
if (response.status !== 402) {
|
|
164
|
+
throw new PayGateError('Expected 402 Payment Required response', response.status);
|
|
165
|
+
}
|
|
166
|
+
const data = response.data;
|
|
167
|
+
if (!data.accepts || data.accepts.length === 0) {
|
|
168
|
+
throw new PayGateError('No payment requirements in response');
|
|
169
|
+
}
|
|
170
|
+
const requirements = data.accepts[0];
|
|
171
|
+
if (!requirements) {
|
|
172
|
+
throw new PayGateError('No payment requirements in response');
|
|
173
|
+
}
|
|
174
|
+
this.logger.info(`Payment requirements received for ${productId}`);
|
|
175
|
+
return requirements;
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
this.handleError('getPaymentRequirements', error);
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Get pricing options for a product (USDC/ATHR)
|
|
184
|
+
* @param productId The product ID
|
|
185
|
+
* @returns Pricing options
|
|
186
|
+
*/
|
|
187
|
+
async getPricing(productId) {
|
|
188
|
+
try {
|
|
189
|
+
this.logger.info(`Getting pricing for: ${productId}`);
|
|
190
|
+
const response = await this.http.get(`/x402/pricing/${productId}`);
|
|
191
|
+
this.logger.info(`Pricing received for ${productId}`);
|
|
192
|
+
return response.data;
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
this.handleError('getPricing', error);
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Verify payment details before purchase
|
|
201
|
+
* @param productId The product ID
|
|
202
|
+
* @param amount The payment amount
|
|
203
|
+
* @param currency The payment currency
|
|
204
|
+
* @returns Verification result
|
|
205
|
+
*/
|
|
206
|
+
async verify(productId, amount, currency = this.defaultCurrency) {
|
|
207
|
+
try {
|
|
208
|
+
if (!this.wallet) {
|
|
209
|
+
throw new PayGateError('Wallet not initialized. Call init() first.');
|
|
210
|
+
}
|
|
211
|
+
this.logger.info(`Verifying payment: ${amount} ${currency} for ${productId}`);
|
|
212
|
+
const response = await this.http.post('/x402/verify', {
|
|
213
|
+
productId,
|
|
214
|
+
amount,
|
|
215
|
+
currency,
|
|
216
|
+
payerWallet: this.wallet.publicKey.toBase58()
|
|
217
|
+
});
|
|
218
|
+
const result = response.data;
|
|
219
|
+
if (result.isValid) {
|
|
220
|
+
this.logger.info('Payment verification successful');
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
this.logger.warn(`Payment verification failed: ${result.invalidReason}`);
|
|
224
|
+
}
|
|
225
|
+
return result;
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
this.handleError('verify', error);
|
|
229
|
+
throw error;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Purchase a product using the x402 flow
|
|
234
|
+
* @param productId The product ID
|
|
235
|
+
* @param options Purchase options
|
|
236
|
+
* @returns Purchase result with transaction hash and delivery URL
|
|
237
|
+
*/
|
|
238
|
+
async purchase(productId, options = {}) {
|
|
239
|
+
try {
|
|
240
|
+
if (!this.wallet) {
|
|
241
|
+
throw new PayGateError('Wallet not initialized. Call init() first.');
|
|
242
|
+
}
|
|
243
|
+
if (!this.settlementAgent) {
|
|
244
|
+
throw new PayGateError('SettlementAgent not initialized. Call init() first.');
|
|
245
|
+
}
|
|
246
|
+
const currency = options.currency || this.defaultCurrency;
|
|
247
|
+
this.logger.info(`Starting purchase flow for ${productId} with ${currency}`);
|
|
248
|
+
// Step 1: Get payment requirements
|
|
249
|
+
this.logger.info('Step 1: Getting payment requirements');
|
|
250
|
+
const requirements = await this.getPaymentRequirements(productId);
|
|
251
|
+
// Get pricing for selected currency if different from requirements
|
|
252
|
+
let amount = requirements.amount;
|
|
253
|
+
let tokenMint = requirements.tokenMint;
|
|
254
|
+
if (currency !== requirements.currency) {
|
|
255
|
+
const pricing = await this.getPricing(productId);
|
|
256
|
+
const option = pricing.options.find((o) => o.currency === currency);
|
|
257
|
+
if (option) {
|
|
258
|
+
amount = option.amount;
|
|
259
|
+
tokenMint = option.tokenMint;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (options.amount !== undefined) {
|
|
263
|
+
amount = (options.amount * 1_000_000).toString();
|
|
264
|
+
}
|
|
265
|
+
// Step 2: Verify payment
|
|
266
|
+
this.logger.info('Step 2: Verifying payment');
|
|
267
|
+
const verification = await this.verify(productId, amount, currency);
|
|
268
|
+
if (!verification.isValid) {
|
|
269
|
+
throw new PayGateError(`Payment verification failed: ${verification.invalidReason}`);
|
|
270
|
+
}
|
|
271
|
+
// Step 3: Create signed payment via SettlementAgent
|
|
272
|
+
this.logger.info('Step 3: Creating signed payment');
|
|
273
|
+
const paymentToken = currency.toLowerCase();
|
|
274
|
+
const amountDecimal = Number(amount) / 1_000_000;
|
|
275
|
+
const paymentHeader = await this.settlementAgent.createSignedPayment(requirements.recipient, amountDecimal, { token: paymentToken });
|
|
276
|
+
// Step 4: Settle payment
|
|
277
|
+
this.logger.info('Step 4: Settling payment');
|
|
278
|
+
const settleResponse = await this.http.post('/x402/settle', {
|
|
279
|
+
paymentHeader,
|
|
280
|
+
productId
|
|
281
|
+
});
|
|
282
|
+
const settle = settleResponse.data;
|
|
283
|
+
if (!settle.success) {
|
|
284
|
+
throw new PayGateError(`Settlement failed: ${settle.error}`);
|
|
285
|
+
}
|
|
286
|
+
this.logger.info(`Purchase successful! TX: ${settle.txHash}`);
|
|
287
|
+
return {
|
|
288
|
+
transactionHash: settle.txHash,
|
|
289
|
+
productId,
|
|
290
|
+
amount,
|
|
291
|
+
currency,
|
|
292
|
+
deliveryUrl: settle.deliveryUrl
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
catch (error) {
|
|
296
|
+
this.handleError('purchase', error);
|
|
297
|
+
throw error;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Get content for a purchased product
|
|
302
|
+
* @param productId The product ID
|
|
303
|
+
* @returns Content delivery result
|
|
304
|
+
*/
|
|
305
|
+
async getContent(productId) {
|
|
306
|
+
try {
|
|
307
|
+
if (!this.wallet) {
|
|
308
|
+
throw new PayGateError('Wallet not initialized. Call init() first.');
|
|
309
|
+
}
|
|
310
|
+
this.logger.info(`Getting content for: ${productId}`);
|
|
311
|
+
const response = await this.http.get(`/deliver/${productId}`, {
|
|
312
|
+
headers: {
|
|
313
|
+
'X-Wallet-Address': this.wallet.publicKey.toBase58()
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
const delivery = response.data;
|
|
317
|
+
this.logger.info(`Content retrieved for ${productId}`);
|
|
318
|
+
return {
|
|
319
|
+
product: delivery.product,
|
|
320
|
+
downloadUrl: delivery.downloadUrl,
|
|
321
|
+
accessToken: delivery.accessToken,
|
|
322
|
+
purchaseDate: delivery.purchaseDate
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
catch (error) {
|
|
326
|
+
this.handleError('getContent', error);
|
|
327
|
+
throw error;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Get purchase history for the current wallet
|
|
332
|
+
* @returns Purchase history
|
|
333
|
+
*/
|
|
334
|
+
async getPurchaseHistory() {
|
|
335
|
+
try {
|
|
336
|
+
if (!this.wallet) {
|
|
337
|
+
throw new PayGateError('Wallet not initialized. Call init() first.');
|
|
338
|
+
}
|
|
339
|
+
const walletAddress = this.wallet.publicKey.toBase58();
|
|
340
|
+
this.logger.info(`Getting purchase history for: ${walletAddress}`);
|
|
341
|
+
const response = await this.http.get(`/deliver/wallet/${walletAddress}`);
|
|
342
|
+
this.logger.info('Purchase history retrieved');
|
|
343
|
+
return response.data;
|
|
344
|
+
}
|
|
345
|
+
catch (error) {
|
|
346
|
+
this.handleError('getPurchaseHistory', error);
|
|
347
|
+
throw error;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Check if the current wallet has already purchased a product
|
|
352
|
+
* @param productId The product ID
|
|
353
|
+
* @returns True if already purchased
|
|
354
|
+
*/
|
|
355
|
+
async hasPurchased(productId) {
|
|
356
|
+
try {
|
|
357
|
+
if (!this.wallet) {
|
|
358
|
+
return false;
|
|
359
|
+
}
|
|
360
|
+
this.logger.info(`Checking purchase status for: ${productId}`);
|
|
361
|
+
const history = await this.getPurchaseHistory();
|
|
362
|
+
const purchased = history.purchases.some((p) => p.productId === productId && p.status === 'completed');
|
|
363
|
+
this.logger.info(`Product ${productId} purchased: ${purchased}`);
|
|
364
|
+
return purchased;
|
|
365
|
+
}
|
|
366
|
+
catch (error) {
|
|
367
|
+
this.logger.warn('Error checking purchase status', error);
|
|
368
|
+
return false;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Get the current wallet public key
|
|
373
|
+
* @returns Wallet public key as base58 string, or undefined if not initialized
|
|
374
|
+
*/
|
|
375
|
+
getWalletAddress() {
|
|
376
|
+
return this.wallet?.publicKey.toBase58();
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Handle and log errors consistently
|
|
380
|
+
*/
|
|
381
|
+
handleError(method, error) {
|
|
382
|
+
if (error instanceof PayGateError) {
|
|
383
|
+
this.logger.error(`${method} failed: ${error.message}`);
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
if (error instanceof axios_1.AxiosError) {
|
|
387
|
+
const status = error.response?.status;
|
|
388
|
+
const message = error.response?.data?.error || error.message;
|
|
389
|
+
this.logger.error(`${method} failed: HTTP ${status} - ${message}`);
|
|
390
|
+
throw new PayGateError(message, status);
|
|
391
|
+
}
|
|
392
|
+
this.logger.error(`${method} failed: ${error.message}`);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
exports.PayGateClient = PayGateClient;
|
|
396
|
+
//# sourceMappingURL=PayGateClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PayGateClient.js","sourceRoot":"","sources":["../../../src/paygate/PayGateClient.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,+CAAwD;AACxD,+DAA2D;AAC3D,4CAAoD;AACpD,4CAA8C;AAiB9C;;GAEG;AACH,MAAa,YAAa,SAAQ,KAAK;IACrB,UAAU,CAAoB;IAC9B,IAAI,CAAoB;IAExC,YAAY,OAAe,EAAE,UAAmB,EAAE,IAAa;QAC7D,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,cAAc,CAAA;QAC1B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF;AAVD,oCAUC;AAED;;GAEG;AACH,MAAa,aAAa;IAChB,OAAO,CAAQ;IACf,MAAM,CAAqB;IAC3B,eAAe,CAAiB;IAChC,OAAO,CAAQ;IACf,IAAI,CAAe;IACnB,eAAe,CAA6B;IAC5C,MAAM,GAAG,IAAA,qBAAY,EAAC,eAAe,CAAC,CAAA;IAE9C,YAAY,MAA2B;QACrC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC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,CAAC,GAAG,MAAM,iBAAiB,MAAM,MAAM,OAAO,EAAE,CAAC,CAAA;YAClE,MAAM,IAAI,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;QACzC,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,YAAa,KAAe,CAAC,OAAO,EAAE,CAAC,CAAA;IACpE,CAAC;CACF;AA/XD,sCA+XC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PayGate Module
|
|
3
|
+
* Client for interacting with PayGate x402 payment protocol
|
|
4
|
+
*/
|
|
5
|
+
export { PayGateClient, PayGateError } from './PayGateClient';
|
|
6
|
+
export type { PayGateClientConfig, PaymentCurrency, ProductType, Product, PaymentRequirements, X402Response, PricingOption, PricingResponse, VerifyRequest, VerifyResponse, SettleRequest, SettleResponse, PurchaseOptions, PurchaseResult, ContentResult, DeliveryResponse, PurchaseHistoryEntry, PurchaseHistoryResponse } from './types';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/paygate/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE7D,YAAY,EACV,mBAAmB,EACnB,eAAe,EACf,WAAW,EACX,OAAO,EACP,mBAAmB,EACnB,YAAY,EACZ,aAAa,EACb,eAAe,EACf,aAAa,EACb,cAAc,EACd,aAAa,EACb,cAAc,EACd,eAAe,EACf,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,oBAAoB,EACpB,uBAAuB,EACxB,MAAM,SAAS,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* PayGate Module
|
|
4
|
+
* Client for interacting with PayGate x402 payment protocol
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.PayGateError = exports.PayGateClient = void 0;
|
|
8
|
+
var PayGateClient_1 = require("./PayGateClient");
|
|
9
|
+
Object.defineProperty(exports, "PayGateClient", { enumerable: true, get: function () { return PayGateClient_1.PayGateClient; } });
|
|
10
|
+
Object.defineProperty(exports, "PayGateError", { enumerable: true, get: function () { return PayGateClient_1.PayGateError; } });
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/paygate/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,iDAA6D;AAApD,8GAAA,aAAa,OAAA;AAAE,6GAAA,YAAY,OAAA"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PayGate Client Types
|
|
3
|
+
* Type definitions for the PayGate x402 payment client
|
|
4
|
+
*/
|
|
5
|
+
import { Keypair } from '@solana/web3.js';
|
|
6
|
+
/**
|
|
7
|
+
* Supported payment currencies
|
|
8
|
+
*/
|
|
9
|
+
export type PaymentCurrency = 'USDC' | 'ATHR';
|
|
10
|
+
/**
|
|
11
|
+
* Product types available on PayGate
|
|
12
|
+
*/
|
|
13
|
+
export type ProductType = 'content_link' | 'api_proxy' | 'feature_unlock' | 'iot_endpoint';
|
|
14
|
+
/**
|
|
15
|
+
* PayGate client configuration
|
|
16
|
+
*/
|
|
17
|
+
export interface PayGateClientConfig {
|
|
18
|
+
/** Base URL of the PayGate server */
|
|
19
|
+
baseUrl: string;
|
|
20
|
+
/** Optional wallet keypair for signing payments */
|
|
21
|
+
wallet?: Keypair;
|
|
22
|
+
/** Default currency for purchases (defaults to USDC) */
|
|
23
|
+
defaultCurrency?: PaymentCurrency;
|
|
24
|
+
/** Request timeout in milliseconds (defaults to 30000) */
|
|
25
|
+
timeout?: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Product information returned from PayGate
|
|
29
|
+
*/
|
|
30
|
+
export interface Product {
|
|
31
|
+
id: string;
|
|
32
|
+
title: string;
|
|
33
|
+
description: string;
|
|
34
|
+
type: ProductType;
|
|
35
|
+
price: string;
|
|
36
|
+
currency: string;
|
|
37
|
+
network: string;
|
|
38
|
+
status: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Payment requirements from x402 402 response
|
|
42
|
+
*/
|
|
43
|
+
export interface PaymentRequirements {
|
|
44
|
+
scheme: string;
|
|
45
|
+
network: string;
|
|
46
|
+
recipient: string;
|
|
47
|
+
amount: string;
|
|
48
|
+
currency: string;
|
|
49
|
+
tokenMint: string;
|
|
50
|
+
productId: string;
|
|
51
|
+
maxTimeoutSeconds?: number;
|
|
52
|
+
resource?: string;
|
|
53
|
+
description?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Full x402 payment response (402 status)
|
|
57
|
+
*/
|
|
58
|
+
export interface X402Response {
|
|
59
|
+
status: 402;
|
|
60
|
+
accepts: PaymentRequirements[];
|
|
61
|
+
error?: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Pricing option for a product
|
|
65
|
+
*/
|
|
66
|
+
export interface PricingOption {
|
|
67
|
+
currency: PaymentCurrency;
|
|
68
|
+
amount: string;
|
|
69
|
+
tokenMint: string;
|
|
70
|
+
discount?: number;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Pricing response from PayGate
|
|
74
|
+
*/
|
|
75
|
+
export interface PricingResponse {
|
|
76
|
+
productId: string;
|
|
77
|
+
options: PricingOption[];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Verification request payload
|
|
81
|
+
*/
|
|
82
|
+
export interface VerifyRequest {
|
|
83
|
+
productId: string;
|
|
84
|
+
amount: string;
|
|
85
|
+
currency: PaymentCurrency;
|
|
86
|
+
payerWallet: string;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Verification response from PayGate
|
|
90
|
+
*/
|
|
91
|
+
export interface VerifyResponse {
|
|
92
|
+
isValid: boolean;
|
|
93
|
+
invalidReason?: string;
|
|
94
|
+
requirements?: PaymentRequirements;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Settlement request payload
|
|
98
|
+
*/
|
|
99
|
+
export interface SettleRequest {
|
|
100
|
+
paymentHeader: string;
|
|
101
|
+
productId: string;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Settlement response from PayGate
|
|
105
|
+
*/
|
|
106
|
+
export interface SettleResponse {
|
|
107
|
+
success: boolean;
|
|
108
|
+
txHash?: string;
|
|
109
|
+
deliveryUrl?: string;
|
|
110
|
+
error?: string;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Purchase options
|
|
114
|
+
*/
|
|
115
|
+
export interface PurchaseOptions {
|
|
116
|
+
/** Currency to use for payment */
|
|
117
|
+
currency?: PaymentCurrency;
|
|
118
|
+
/** Custom amount (overrides product price) */
|
|
119
|
+
amount?: number;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Result of a successful purchase
|
|
123
|
+
*/
|
|
124
|
+
export interface PurchaseResult {
|
|
125
|
+
transactionHash: string;
|
|
126
|
+
productId: string;
|
|
127
|
+
amount: string;
|
|
128
|
+
currency: string;
|
|
129
|
+
deliveryUrl: string;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Content delivery result
|
|
133
|
+
*/
|
|
134
|
+
export interface ContentResult {
|
|
135
|
+
product: {
|
|
136
|
+
id: string;
|
|
137
|
+
title: string;
|
|
138
|
+
type: ProductType;
|
|
139
|
+
};
|
|
140
|
+
downloadUrl: string | null;
|
|
141
|
+
accessToken: string | undefined;
|
|
142
|
+
purchaseDate: string;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Delivery response from PayGate
|
|
146
|
+
*/
|
|
147
|
+
export interface DeliveryResponse {
|
|
148
|
+
productId: string;
|
|
149
|
+
product: {
|
|
150
|
+
id: string;
|
|
151
|
+
title: string;
|
|
152
|
+
type: ProductType;
|
|
153
|
+
};
|
|
154
|
+
downloadUrl: string | null;
|
|
155
|
+
accessToken?: string;
|
|
156
|
+
purchaseDate: string;
|
|
157
|
+
expiresAt?: string;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Purchase history entry
|
|
161
|
+
*/
|
|
162
|
+
export interface PurchaseHistoryEntry {
|
|
163
|
+
productId: string;
|
|
164
|
+
title: string;
|
|
165
|
+
type: ProductType;
|
|
166
|
+
amount: string;
|
|
167
|
+
currency: string;
|
|
168
|
+
transactionHash: string;
|
|
169
|
+
purchaseDate: string;
|
|
170
|
+
status: 'completed' | 'pending' | 'failed';
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Purchase history response
|
|
174
|
+
*/
|
|
175
|
+
export interface PurchaseHistoryResponse {
|
|
176
|
+
wallet: string;
|
|
177
|
+
purchases: PurchaseHistoryEntry[];
|
|
178
|
+
total: number;
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/paygate/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAEzC;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,CAAA;AAE7C;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,cAAc,GAAG,WAAW,GAAG,gBAAgB,GAAG,cAAc,CAAA;AAE1F;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAA;IACf,mDAAmD;IACnD,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,wDAAwD;IACxD,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,0DAA0D;IAC1D,OAAO,CAAC,E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KAClB,CAAA;IACD,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,WAAW,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,eAAe,EAAE,MAAM,CAAA;IACvB,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,EAAE,WAAW,GAAG,SAAS,GAAG,QAAQ,CAAA;CAC3C;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,oBAAoB,EAAE,CAAA;IACjC,KAAK,EAAE,MAAM,CAAA;CACd"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/paygate/types.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
|
|
@@ -8,4 +8,6 @@ export { resolveSolanaNetwork, isMainnet, createNonce } from './solana';
|
|
|
8
8
|
export type { SolanaNetwork } from './solana';
|
|
9
9
|
export { loadKeypairFromEnv, generateDevWallet, assertMatchingMint, parsePublicKey } from './wallet';
|
|
10
10
|
export { createLogger } from './logger';
|
|
11
|
+
export { ATHR_MINT_MAINNET, USDC_MINT_MAINNET, USDC_MINT_DEVNET, TOKEN_DECIMALS, getTokenMint, getTokenMintPublicKey, tokenToAmount, amountToToken } from './tokens';
|
|
12
|
+
export type { PaymentToken, TokenConfig } from './tokens';
|
|
11
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAC/C,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACvE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACf,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAC/C,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACvE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACf,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,qBAAqB,EACrB,aAAa,EACb,aAAa,EACd,MAAM,UAAU,CAAA;AACjB,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA"}
|
package/dist/src/utils/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Export utility functions
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.createLogger = exports.parsePublicKey = exports.assertMatchingMint = exports.generateDevWallet = exports.loadKeypairFromEnv = exports.createNonce = exports.isMainnet = exports.resolveSolanaNetwork = exports.getEnv = exports.loadEnvIfNeeded = void 0;
|
|
8
|
+
exports.amountToToken = exports.tokenToAmount = exports.getTokenMintPublicKey = exports.getTokenMint = exports.TOKEN_DECIMALS = exports.USDC_MINT_DEVNET = exports.USDC_MINT_MAINNET = exports.ATHR_MINT_MAINNET = exports.createLogger = exports.parsePublicKey = exports.assertMatchingMint = exports.generateDevWallet = exports.loadKeypairFromEnv = exports.createNonce = exports.isMainnet = exports.resolveSolanaNetwork = exports.getEnv = exports.loadEnvIfNeeded = void 0;
|
|
9
9
|
var env_1 = require("./env");
|
|
10
10
|
Object.defineProperty(exports, "loadEnvIfNeeded", { enumerable: true, get: function () { return env_1.loadEnvIfNeeded; } });
|
|
11
11
|
Object.defineProperty(exports, "getEnv", { enumerable: true, get: function () { return env_1.getEnv; } });
|
|
@@ -20,4 +20,13 @@ Object.defineProperty(exports, "assertMatchingMint", { enumerable: true, get: fu
|
|
|
20
20
|
Object.defineProperty(exports, "parsePublicKey", { enumerable: true, get: function () { return wallet_1.parsePublicKey; } });
|
|
21
21
|
var logger_1 = require("./logger");
|
|
22
22
|
Object.defineProperty(exports, "createLogger", { enumerable: true, get: function () { return logger_1.createLogger; } });
|
|
23
|
+
var tokens_1 = require("./tokens");
|
|
24
|
+
Object.defineProperty(exports, "ATHR_MINT_MAINNET", { enumerable: true, get: function () { return tokens_1.ATHR_MINT_MAINNET; } });
|
|
25
|
+
Object.defineProperty(exports, "USDC_MINT_MAINNET", { enumerable: true, get: function () { return tokens_1.USDC_MINT_MAINNET; } });
|
|
26
|
+
Object.defineProperty(exports, "USDC_MINT_DEVNET", { enumerable: true, get: function () { return tokens_1.USDC_MINT_DEVNET; } });
|
|
27
|
+
Object.defineProperty(exports, "TOKEN_DECIMALS", { enumerable: true, get: function () { return tokens_1.TOKEN_DECIMALS; } });
|
|
28
|
+
Object.defineProperty(exports, "getTokenMint", { enumerable: true, get: function () { return tokens_1.getTokenMint; } });
|
|
29
|
+
Object.defineProperty(exports, "getTokenMintPublicKey", { enumerable: true, get: function () { return tokens_1.getTokenMintPublicKey; } });
|
|
30
|
+
Object.defineProperty(exports, "tokenToAmount", { enumerable: true, get: function () { return tokens_1.tokenToAmount; } });
|
|
31
|
+
Object.defineProperty(exports, "amountToToken", { enumerable: true, get: function () { return tokens_1.amountToToken; } });
|
|
23
32
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,6BAA+C;AAAtC,sGAAA,eAAe,OAAA;AAAE,6FAAA,MAAM,OAAA;AAChC,mCAAuE;AAA9D,8GAAA,oBAAoB,OAAA;AAAE,mGAAA,SAAS,OAAA;AAAE,qGAAA,WAAW,OAAA;AAErD,mCAKiB;AAJf,4GAAA,kBAAkB,OAAA;AAClB,2GAAA,iBAAiB,OAAA;AACjB,4GAAA,kBAAkB,OAAA;AAClB,wGAAA,cAAc,OAAA;AAEhB,mCAAuC;AAA9B,sGAAA,YAAY,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,6BAA+C;AAAtC,sGAAA,eAAe,OAAA;AAAE,6FAAA,MAAM,OAAA;AAChC,mCAAuE;AAA9D,8GAAA,oBAAoB,OAAA;AAAE,mGAAA,SAAS,OAAA;AAAE,qGAAA,WAAW,OAAA;AAErD,mCAKiB;AAJf,4GAAA,kBAAkB,OAAA;AAClB,2GAAA,iBAAiB,OAAA;AACjB,4GAAA,kBAAkB,OAAA;AAClB,wGAAA,cAAc,OAAA;AAEhB,mCAAuC;AAA9B,sGAAA,YAAY,OAAA;AACrB,mCASiB;AARf,2GAAA,iBAAiB,OAAA;AACjB,2GAAA,iBAAiB,OAAA;AACjB,0GAAA,gBAAgB,OAAA;AAChB,wGAAA,cAAc,OAAA;AACd,sGAAA,YAAY,OAAA;AACZ,+GAAA,qBAAqB,OAAA;AACrB,uGAAA,aAAa,OAAA;AACb,uGAAA,aAAa,OAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
export declare const ATHR_MINT_MAINNET = "5abiPeWqRLYb21DWNGYRFwrABML24dYuGn39ZpPYpump";
|
|
3
|
+
export declare const USDC_MINT_MAINNET = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
4
|
+
export declare const USDC_MINT_DEVNET = "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU";
|
|
5
|
+
export declare const TOKEN_DECIMALS = 6;
|
|
6
|
+
export type PaymentToken = 'athr' | 'usdc';
|
|
7
|
+
export interface TokenConfig {
|
|
8
|
+
mint: string;
|
|
9
|
+
decimals: number;
|
|
10
|
+
symbol: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function getTokenMint(token: PaymentToken, isMainnet: boolean): string;
|
|
13
|
+
export declare function getTokenMintPublicKey(token: PaymentToken, isMainnet: boolean): PublicKey;
|
|
14
|
+
export declare function tokenToAmount(amount: number): number;
|
|
15
|
+
export declare function amountToToken(amount: number): number;
|
|
16
|
+
//# sourceMappingURL=tokens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../../src/utils/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,eAAO,MAAM,iBAAiB,iDAAiD,CAAA;AAC/E,eAAO,MAAM,iBAAiB,iDAAiD,CAAA;AAC/E,eAAO,MAAM,gBAAgB,iDAAiD,CAAA;AAE9E,eAAO,MAAM,cAAc,IAAI,CAAA;AAE/B,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,CAAA;AAE1C,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;CACf;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,GAAG,MAAM,CAQ5E;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,GAAG,SAAS,CAExF;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEpD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TOKEN_DECIMALS = exports.USDC_MINT_DEVNET = exports.USDC_MINT_MAINNET = exports.ATHR_MINT_MAINNET = void 0;
|
|
4
|
+
exports.getTokenMint = getTokenMint;
|
|
5
|
+
exports.getTokenMintPublicKey = getTokenMintPublicKey;
|
|
6
|
+
exports.tokenToAmount = tokenToAmount;
|
|
7
|
+
exports.amountToToken = amountToToken;
|
|
8
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
9
|
+
exports.ATHR_MINT_MAINNET = '5abiPeWqRLYb21DWNGYRFwrABML24dYuGn39ZpPYpump';
|
|
10
|
+
exports.USDC_MINT_MAINNET = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v';
|
|
11
|
+
exports.USDC_MINT_DEVNET = '4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU';
|
|
12
|
+
exports.TOKEN_DECIMALS = 6;
|
|
13
|
+
function getTokenMint(token, isMainnet) {
|
|
14
|
+
if (token === 'athr') {
|
|
15
|
+
return process.env.ATHR_MINT || exports.ATHR_MINT_MAINNET;
|
|
16
|
+
}
|
|
17
|
+
if (isMainnet) {
|
|
18
|
+
return process.env.USDC_MINT || exports.USDC_MINT_MAINNET;
|
|
19
|
+
}
|
|
20
|
+
return process.env.USDC_MINT || exports.USDC_MINT_DEVNET;
|
|
21
|
+
}
|
|
22
|
+
function getTokenMintPublicKey(token, isMainnet) {
|
|
23
|
+
return new web3_js_1.PublicKey(getTokenMint(token, isMainnet));
|
|
24
|
+
}
|
|
25
|
+
function tokenToAmount(amount) {
|
|
26
|
+
return Math.floor(amount * Math.pow(10, exports.TOKEN_DECIMALS));
|
|
27
|
+
}
|
|
28
|
+
function amountToToken(amount) {
|
|
29
|
+
return amount / Math.pow(10, exports.TOKEN_DECIMALS);
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../../src/utils/tokens.ts"],"names":[],"mappings":";;;AAgBA,oCAQC;AAED,sDAEC;AAED,sCAEC;AAED,sCAEC;AApCD,6CAA2C;AAE9B,QAAA,iBAAiB,GAAG,8CAA8C,CAAA;AAClE,QAAA,iBAAiB,GAAG,8CAA8C,CAAA;AAClE,QAAA,gBAAgB,GAAG,8CAA8C,CAAA;AAEjE,QAAA,cAAc,GAAG,CAAC,CAAA;AAU/B,SAAgB,YAAY,CAAC,KAAmB,EAAE,SAAkB;IAClE,IAAI,KAAK,KAAK,MAAM,EAAE,CAAC;QACrB,OAAO,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,yBAAiB,CAAA;IACnD,CAAC;IACD,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,yBAAiB,CAAA;IACnD,CAAC;IACD,OAAO,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,wBAAgB,CAAA;AAClD,CAAC;AAED,SAAgB,qBAAqB,CAAC,KAAmB,EAAE,SAAkB;IAC3E,OAAO,IAAI,mBAAS,CAAC,YAAY,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAA;AACtD,CAAC;AAED,SAAgB,aAAa,CAAC,MAAc;IAC1C,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,sBAAc,CAAC,CAAC,CAAA;AAC1D,CAAC;AAED,SAAgB,aAAa,CAAC,MAAc;IAC1C,OAAO,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,sBAAc,CAAC,CAAA;AAC9C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aether-agent-sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Autonomous Agent Ecosystem SDK for Solana - A2A Protocol, x402 Payment Standard, and Agent-to-Agent Communication",
|
|
5
5
|
"main": "./dist/src/index.js",
|
|
6
6
|
"types": "./dist/src/index.d.ts",
|
|
@@ -29,6 +29,11 @@
|
|
|
29
29
|
"import": "./dist/src/marketplace/index.js",
|
|
30
30
|
"require": "./dist/src/marketplace/index.js",
|
|
31
31
|
"types": "./dist/src/marketplace/index.d.ts"
|
|
32
|
+
},
|
|
33
|
+
"./paygate": {
|
|
34
|
+
"import": "./dist/src/paygate/index.js",
|
|
35
|
+
"require": "./dist/src/paygate/index.js",
|
|
36
|
+
"types": "./dist/src/paygate/index.d.ts"
|
|
32
37
|
}
|
|
33
38
|
},
|
|
34
39
|
"files": [
|