@alleyboss/micropay-solana-x402-paywall 3.0.3 → 3.0.5

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.
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ var http = require('@x402/core/http');
4
+
3
5
  // src/client/types.ts
4
6
  var TOKEN_MINTS = {
5
7
  /** USDC on mainnet */
@@ -91,7 +93,26 @@ function createPaymentReference() {
91
93
  }
92
94
  return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
93
95
  }
96
+ function createX402AuthorizationHeader(signature, paymentRequiredHeader) {
97
+ const cleanHeader = paymentRequiredHeader.replace(/^[Xx]402\s+/, "");
98
+ const required = http.decodePaymentRequiredHeader(cleanHeader);
99
+ const accepts = Array.isArray(required.accepts) ? required.accepts[0] : required.accepts;
100
+ const payload = {
101
+ accepted: accepts,
102
+ client: {
103
+ scheme: accepts.scheme,
104
+ // TypeScript knows this exists on PaymentRequirements
105
+ network: accepts.network
106
+ },
107
+ payment: {
108
+ signature
109
+ }
110
+ };
111
+ const token = http.encodePaymentSignatureHeader(payload);
112
+ return `x402 ${token}`;
113
+ }
94
114
 
95
115
  exports.buildSolanaPayUrl = buildSolanaPayUrl;
96
116
  exports.createPaymentFlow = createPaymentFlow;
97
117
  exports.createPaymentReference = createPaymentReference;
118
+ exports.createX402AuthorizationHeader = createX402AuthorizationHeader;
@@ -118,4 +118,12 @@ declare function createPaymentFlow(config: PaymentFlowConfig): {
118
118
  */
119
119
  declare function createPaymentReference(): string;
120
120
 
121
- export { type PaymentFlowConfig, type SolanaPayUrlParams, buildSolanaPayUrl, createPaymentFlow, createPaymentReference };
121
+ /**
122
+ * Creates the Authorization header value for x402 authentication
123
+ *
124
+ * @param signature - The payment signature/proof
125
+ * @param paymentRequiredHeader - The WWW-Authenticate header value from the 402 response
126
+ */
127
+ declare function createX402AuthorizationHeader(signature: string, paymentRequiredHeader: string): string;
128
+
129
+ export { type PaymentFlowConfig, type SolanaPayUrlParams, buildSolanaPayUrl, createPaymentFlow, createPaymentReference, createX402AuthorizationHeader };
@@ -118,4 +118,12 @@ declare function createPaymentFlow(config: PaymentFlowConfig): {
118
118
  */
119
119
  declare function createPaymentReference(): string;
120
120
 
121
- export { type PaymentFlowConfig, type SolanaPayUrlParams, buildSolanaPayUrl, createPaymentFlow, createPaymentReference };
121
+ /**
122
+ * Creates the Authorization header value for x402 authentication
123
+ *
124
+ * @param signature - The payment signature/proof
125
+ * @param paymentRequiredHeader - The WWW-Authenticate header value from the 402 response
126
+ */
127
+ declare function createX402AuthorizationHeader(signature: string, paymentRequiredHeader: string): string;
128
+
129
+ export { type PaymentFlowConfig, type SolanaPayUrlParams, buildSolanaPayUrl, createPaymentFlow, createPaymentReference, createX402AuthorizationHeader };
@@ -1,3 +1,5 @@
1
+ import { decodePaymentRequiredHeader, encodePaymentSignatureHeader } from '@x402/core/http';
2
+
1
3
  // src/client/types.ts
2
4
  var TOKEN_MINTS = {
3
5
  /** USDC on mainnet */
@@ -89,5 +91,23 @@ function createPaymentReference() {
89
91
  }
90
92
  return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
91
93
  }
94
+ function createX402AuthorizationHeader(signature, paymentRequiredHeader) {
95
+ const cleanHeader = paymentRequiredHeader.replace(/^[Xx]402\s+/, "");
96
+ const required = decodePaymentRequiredHeader(cleanHeader);
97
+ const accepts = Array.isArray(required.accepts) ? required.accepts[0] : required.accepts;
98
+ const payload = {
99
+ accepted: accepts,
100
+ client: {
101
+ scheme: accepts.scheme,
102
+ // TypeScript knows this exists on PaymentRequirements
103
+ network: accepts.network
104
+ },
105
+ payment: {
106
+ signature
107
+ }
108
+ };
109
+ const token = encodePaymentSignatureHeader(payload);
110
+ return `x402 ${token}`;
111
+ }
92
112
 
93
- export { buildSolanaPayUrl, createPaymentFlow, createPaymentReference };
113
+ export { buildSolanaPayUrl, createPaymentFlow, createPaymentReference, createX402AuthorizationHeader };
package/dist/index.cjs CHANGED
@@ -4,6 +4,7 @@ var core = require('@x402/core');
4
4
  var types = require('@x402/core/types');
5
5
  var client = require('@x402/core/client');
6
6
  var svm = require('@x402/svm');
7
+ var http = require('@x402/core/http');
7
8
  var web3_js = require('@solana/web3.js');
8
9
  var jose = require('jose');
9
10
 
@@ -100,6 +101,24 @@ function createPaymentReference() {
100
101
  }
101
102
  return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
102
103
  }
104
+ function createX402AuthorizationHeader(signature, paymentRequiredHeader) {
105
+ const cleanHeader = paymentRequiredHeader.replace(/^[Xx]402\s+/, "");
106
+ const required = http.decodePaymentRequiredHeader(cleanHeader);
107
+ const accepts = Array.isArray(required.accepts) ? required.accepts[0] : required.accepts;
108
+ const payload = {
109
+ accepted: accepts,
110
+ client: {
111
+ scheme: accepts.scheme,
112
+ // TypeScript knows this exists on PaymentRequirements
113
+ network: accepts.network
114
+ },
115
+ payment: {
116
+ signature
117
+ }
118
+ };
119
+ const token = http.encodePaymentSignatureHeader(payload);
120
+ return `x402 ${token}`;
121
+ }
103
122
  var DEFAULT_COMPUTE_UNITS = 2e5;
104
123
  var DEFAULT_MICRO_LAMPORTS = 1e3;
105
124
  function createPriorityFeeInstructions(config2 = {}) {
@@ -440,6 +459,11 @@ async function getRemainingCredits(token, secret) {
440
459
  };
441
460
  }
442
461
 
462
+ // src/pricing/utils.ts
463
+ function lamportsToSol(lamports) {
464
+ return Number(lamports) / 1e9;
465
+ }
466
+
443
467
  // src/pricing/index.ts
444
468
  var cachedPrice = null;
445
469
  var config = {};
@@ -577,6 +601,7 @@ exports.configurePricing = configurePricing;
577
601
  exports.createCreditSession = createCreditSession;
578
602
  exports.createPaymentFlow = createPaymentFlow;
579
603
  exports.createPaymentReference = createPaymentReference;
604
+ exports.createX402AuthorizationHeader = createX402AuthorizationHeader;
580
605
  exports.executeAgentPayment = executeAgentPayment;
581
606
  exports.formatPriceDisplay = formatPriceDisplay;
582
607
  exports.formatPriceSync = formatPriceSync;
@@ -587,6 +612,7 @@ exports.getRemainingCredits = getRemainingCredits;
587
612
  exports.getSolPrice = getSolPrice;
588
613
  exports.hasAgentSufficientBalance = hasAgentSufficientBalance;
589
614
  exports.keypairFromBase58 = keypairFromBase58;
615
+ exports.lamportsToSol = lamportsToSol;
590
616
  exports.lamportsToUsd = lamportsToUsd;
591
617
  exports.usdToLamports = usdToLamports;
592
618
  exports.useCredit = useCredit;
package/dist/index.d.cts CHANGED
@@ -2,8 +2,8 @@ export * from '@x402/core';
2
2
  export * from '@x402/core/types';
3
3
  export * from '@x402/core/client';
4
4
  export * from '@x402/svm';
5
- export { PaymentFlowConfig, SolanaPayUrlParams, buildSolanaPayUrl, createPaymentFlow, createPaymentReference } from './client/index.cjs';
5
+ export { PaymentFlowConfig, SolanaPayUrlParams, buildSolanaPayUrl, createPaymentFlow, createPaymentReference, createX402AuthorizationHeader } from './client/index.cjs';
6
6
  export { AgentPaymentResult, CreditSessionClaims, CreditSessionConfig, CreditSessionData, CreditValidation, ExecuteAgentPaymentParams, UseCreditResult, addCredits, createCreditSession, executeAgentPayment, generateAgentKeypair, getAgentBalance, getRemainingCredits, hasAgentSufficientBalance, keypairFromBase58, useCredit, validateCreditSession } from './agent/index.cjs';
7
- export { CustomPriceProvider, PriceConfig, PriceData, clearPriceCache, configurePricing, formatPriceDisplay, formatPriceSync, getProviders, getSolPrice, lamportsToUsd, usdToLamports } from './pricing/index.cjs';
7
+ export { CustomPriceProvider, PriceConfig, PriceData, clearPriceCache, configurePricing, formatPriceDisplay, formatPriceSync, getProviders, getSolPrice, lamportsToSol, lamportsToUsd, usdToLamports } from './pricing/index.cjs';
8
8
  import '@solana/web3.js';
9
9
  import './types-BWYQMw03.cjs';
package/dist/index.d.ts CHANGED
@@ -2,8 +2,8 @@ export * from '@x402/core';
2
2
  export * from '@x402/core/types';
3
3
  export * from '@x402/core/client';
4
4
  export * from '@x402/svm';
5
- export { PaymentFlowConfig, SolanaPayUrlParams, buildSolanaPayUrl, createPaymentFlow, createPaymentReference } from './client/index.js';
5
+ export { PaymentFlowConfig, SolanaPayUrlParams, buildSolanaPayUrl, createPaymentFlow, createPaymentReference, createX402AuthorizationHeader } from './client/index.js';
6
6
  export { AgentPaymentResult, CreditSessionClaims, CreditSessionConfig, CreditSessionData, CreditValidation, ExecuteAgentPaymentParams, UseCreditResult, addCredits, createCreditSession, executeAgentPayment, generateAgentKeypair, getAgentBalance, getRemainingCredits, hasAgentSufficientBalance, keypairFromBase58, useCredit, validateCreditSession } from './agent/index.js';
7
- export { CustomPriceProvider, PriceConfig, PriceData, clearPriceCache, configurePricing, formatPriceDisplay, formatPriceSync, getProviders, getSolPrice, lamportsToUsd, usdToLamports } from './pricing/index.js';
7
+ export { CustomPriceProvider, PriceConfig, PriceData, clearPriceCache, configurePricing, formatPriceDisplay, formatPriceSync, getProviders, getSolPrice, lamportsToSol, lamportsToUsd, usdToLamports } from './pricing/index.js';
8
8
  import '@solana/web3.js';
9
9
  import './types-BWYQMw03.js';
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@ export * from '@x402/core';
2
2
  export * from '@x402/core/types';
3
3
  export * from '@x402/core/client';
4
4
  export * from '@x402/svm';
5
+ import { decodePaymentRequiredHeader, encodePaymentSignatureHeader } from '@x402/core/http';
5
6
  import { PublicKey, SystemProgram, LAMPORTS_PER_SOL, Keypair, TransactionMessage, VersionedTransaction, ComputeBudgetProgram } from '@solana/web3.js';
6
7
  import { SignJWT, jwtVerify } from 'jose';
7
8
 
@@ -98,6 +99,24 @@ function createPaymentReference() {
98
99
  }
99
100
  return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
100
101
  }
102
+ function createX402AuthorizationHeader(signature, paymentRequiredHeader) {
103
+ const cleanHeader = paymentRequiredHeader.replace(/^[Xx]402\s+/, "");
104
+ const required = decodePaymentRequiredHeader(cleanHeader);
105
+ const accepts = Array.isArray(required.accepts) ? required.accepts[0] : required.accepts;
106
+ const payload = {
107
+ accepted: accepts,
108
+ client: {
109
+ scheme: accepts.scheme,
110
+ // TypeScript knows this exists on PaymentRequirements
111
+ network: accepts.network
112
+ },
113
+ payment: {
114
+ signature
115
+ }
116
+ };
117
+ const token = encodePaymentSignatureHeader(payload);
118
+ return `x402 ${token}`;
119
+ }
101
120
  var DEFAULT_COMPUTE_UNITS = 2e5;
102
121
  var DEFAULT_MICRO_LAMPORTS = 1e3;
103
122
  function createPriorityFeeInstructions(config2 = {}) {
@@ -438,6 +457,11 @@ async function getRemainingCredits(token, secret) {
438
457
  };
439
458
  }
440
459
 
460
+ // src/pricing/utils.ts
461
+ function lamportsToSol(lamports) {
462
+ return Number(lamports) / 1e9;
463
+ }
464
+
441
465
  // src/pricing/index.ts
442
466
  var cachedPrice = null;
443
467
  var config = {};
@@ -568,4 +592,4 @@ function getProviders() {
568
592
  return PROVIDERS.map((p) => ({ name: p.name, url: p.url }));
569
593
  }
570
594
 
571
- export { addCredits, buildSolanaPayUrl, clearPriceCache, configurePricing, createCreditSession, createPaymentFlow, createPaymentReference, executeAgentPayment, formatPriceDisplay, formatPriceSync, generateAgentKeypair, getAgentBalance, getProviders, getRemainingCredits, getSolPrice, hasAgentSufficientBalance, keypairFromBase58, lamportsToUsd, usdToLamports, useCredit, validateCreditSession };
595
+ export { addCredits, buildSolanaPayUrl, clearPriceCache, configurePricing, createCreditSession, createPaymentFlow, createPaymentReference, createX402AuthorizationHeader, executeAgentPayment, formatPriceDisplay, formatPriceSync, generateAgentKeypair, getAgentBalance, getProviders, getRemainingCredits, getSolPrice, hasAgentSufficientBalance, keypairFromBase58, lamportsToSol, lamportsToUsd, usdToLamports, useCredit, validateCreditSession };
@@ -1,5 +1,10 @@
1
1
  'use strict';
2
2
 
3
+ // src/pricing/utils.ts
4
+ function lamportsToSol(lamports) {
5
+ return Number(lamports) / 1e9;
6
+ }
7
+
3
8
  // src/pricing/index.ts
4
9
  var cachedPrice = null;
5
10
  var config = {};
@@ -136,5 +141,6 @@ exports.formatPriceDisplay = formatPriceDisplay;
136
141
  exports.formatPriceSync = formatPriceSync;
137
142
  exports.getProviders = getProviders;
138
143
  exports.getSolPrice = getSolPrice;
144
+ exports.lamportsToSol = lamportsToSol;
139
145
  exports.lamportsToUsd = lamportsToUsd;
140
146
  exports.usdToLamports = usdToLamports;
@@ -1,3 +1,5 @@
1
+ declare function lamportsToSol(lamports: bigint | number): number;
2
+
1
3
  /**
2
4
  * Price data from API
3
5
  */
@@ -100,12 +102,10 @@ declare function formatPriceSync(lamports: bigint, solPrice: number): {
100
102
  * Clear the price cache (for testing or manual refresh)
101
103
  */
102
104
  declare function clearPriceCache(): void;
103
- /**
104
- * Get list of available built-in providers
105
- */
105
+
106
106
  declare function getProviders(): {
107
107
  name: string;
108
108
  url: string;
109
109
  }[];
110
110
 
111
- export { type CustomPriceProvider, type PriceConfig, type PriceData, clearPriceCache, configurePricing, formatPriceDisplay, formatPriceSync, getProviders, getSolPrice, lamportsToUsd, usdToLamports };
111
+ export { type CustomPriceProvider, type PriceConfig, type PriceData, clearPriceCache, configurePricing, formatPriceDisplay, formatPriceSync, getProviders, getSolPrice, lamportsToSol, lamportsToUsd, usdToLamports };
@@ -1,3 +1,5 @@
1
+ declare function lamportsToSol(lamports: bigint | number): number;
2
+
1
3
  /**
2
4
  * Price data from API
3
5
  */
@@ -100,12 +102,10 @@ declare function formatPriceSync(lamports: bigint, solPrice: number): {
100
102
  * Clear the price cache (for testing or manual refresh)
101
103
  */
102
104
  declare function clearPriceCache(): void;
103
- /**
104
- * Get list of available built-in providers
105
- */
105
+
106
106
  declare function getProviders(): {
107
107
  name: string;
108
108
  url: string;
109
109
  }[];
110
110
 
111
- export { type CustomPriceProvider, type PriceConfig, type PriceData, clearPriceCache, configurePricing, formatPriceDisplay, formatPriceSync, getProviders, getSolPrice, lamportsToUsd, usdToLamports };
111
+ export { type CustomPriceProvider, type PriceConfig, type PriceData, clearPriceCache, configurePricing, formatPriceDisplay, formatPriceSync, getProviders, getSolPrice, lamportsToSol, lamportsToUsd, usdToLamports };
@@ -1,3 +1,8 @@
1
+ // src/pricing/utils.ts
2
+ function lamportsToSol(lamports) {
3
+ return Number(lamports) / 1e9;
4
+ }
5
+
1
6
  // src/pricing/index.ts
2
7
  var cachedPrice = null;
3
8
  var config = {};
@@ -128,4 +133,4 @@ function getProviders() {
128
133
  return PROVIDERS.map((p) => ({ name: p.name, url: p.url }));
129
134
  }
130
135
 
131
- export { clearPriceCache, configurePricing, formatPriceDisplay, formatPriceSync, getProviders, getSolPrice, lamportsToUsd, usdToLamports };
136
+ export { clearPriceCache, configurePricing, formatPriceDisplay, formatPriceSync, getProviders, getSolPrice, lamportsToSol, lamportsToUsd, usdToLamports };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alleyboss/micropay-solana-x402-paywall",
3
- "version": "3.0.3",
3
+ "version": "3.0.5",
4
4
  "description": "Production-ready Solana micropayments library wrapper for official x402 SDK",
5
5
  "author": "AlleyBoss",
6
6
  "license": "MIT",