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

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 = {}) {
@@ -577,6 +596,7 @@ exports.configurePricing = configurePricing;
577
596
  exports.createCreditSession = createCreditSession;
578
597
  exports.createPaymentFlow = createPaymentFlow;
579
598
  exports.createPaymentReference = createPaymentReference;
599
+ exports.createX402AuthorizationHeader = createX402AuthorizationHeader;
580
600
  exports.executeAgentPayment = executeAgentPayment;
581
601
  exports.formatPriceDisplay = formatPriceDisplay;
582
602
  exports.formatPriceSync = formatPriceSync;
package/dist/index.d.cts CHANGED
@@ -2,7 +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
- 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
7
  export { CustomPriceProvider, PriceConfig, PriceData, clearPriceCache, configurePricing, formatPriceDisplay, formatPriceSync, getProviders, getSolPrice, lamportsToUsd, usdToLamports } from './pricing/index.cjs';
8
8
  import '@solana/web3.js';
package/dist/index.d.ts CHANGED
@@ -2,7 +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
- 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
7
  export { CustomPriceProvider, PriceConfig, PriceData, clearPriceCache, configurePricing, formatPriceDisplay, formatPriceSync, getProviders, getSolPrice, lamportsToUsd, usdToLamports } from './pricing/index.js';
8
8
  import '@solana/web3.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 = {}) {
@@ -568,4 +587,4 @@ function getProviders() {
568
587
  return PROVIDERS.map((p) => ({ name: p.name, url: p.url }));
569
588
  }
570
589
 
571
- export { addCredits, buildSolanaPayUrl, clearPriceCache, configurePricing, createCreditSession, createPaymentFlow, createPaymentReference, executeAgentPayment, formatPriceDisplay, formatPriceSync, generateAgentKeypair, getAgentBalance, getProviders, getRemainingCredits, getSolPrice, hasAgentSufficientBalance, keypairFromBase58, lamportsToUsd, usdToLamports, useCredit, validateCreditSession };
590
+ export { addCredits, buildSolanaPayUrl, clearPriceCache, configurePricing, createCreditSession, createPaymentFlow, createPaymentReference, createX402AuthorizationHeader, executeAgentPayment, formatPriceDisplay, formatPriceSync, generateAgentKeypair, getAgentBalance, getProviders, getRemainingCredits, getSolPrice, hasAgentSufficientBalance, keypairFromBase58, lamportsToUsd, usdToLamports, useCredit, validateCreditSession };
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.4",
4
4
  "description": "Production-ready Solana micropayments library wrapper for official x402 SDK",
5
5
  "author": "AlleyBoss",
6
6
  "license": "MIT",