privacycash-x402 1.0.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.
Files changed (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +139 -0
  3. package/dist/examples/client-example.d.ts +13 -0
  4. package/dist/examples/client-example.d.ts.map +1 -0
  5. package/dist/examples/client-example.js +108 -0
  6. package/dist/examples/client-example.js.map +1 -0
  7. package/dist/examples/server-example.d.ts +13 -0
  8. package/dist/examples/server-example.d.ts.map +1 -0
  9. package/dist/examples/server-example.js +104 -0
  10. package/dist/examples/server-example.js.map +1 -0
  11. package/dist/src/client/index.d.ts +89 -0
  12. package/dist/src/client/index.d.ts.map +1 -0
  13. package/dist/src/client/index.js +259 -0
  14. package/dist/src/client/index.js.map +1 -0
  15. package/dist/src/config.d.ts +10 -0
  16. package/dist/src/config.d.ts.map +1 -0
  17. package/dist/src/config.js +16 -0
  18. package/dist/src/config.js.map +1 -0
  19. package/dist/src/errors/index.d.ts +81 -0
  20. package/dist/src/errors/index.d.ts.map +1 -0
  21. package/dist/src/errors/index.js +110 -0
  22. package/dist/src/errors/index.js.map +1 -0
  23. package/dist/src/index.d.ts +10 -0
  24. package/dist/src/index.d.ts.map +1 -0
  25. package/dist/src/index.js +47 -0
  26. package/dist/src/index.js.map +1 -0
  27. package/dist/src/models/keypair.d.ts +27 -0
  28. package/dist/src/models/keypair.d.ts.map +1 -0
  29. package/dist/src/models/keypair.js +48 -0
  30. package/dist/src/models/keypair.js.map +1 -0
  31. package/dist/src/models/utxo.d.ts +50 -0
  32. package/dist/src/models/utxo.d.ts.map +1 -0
  33. package/dist/src/models/utxo.js +86 -0
  34. package/dist/src/models/utxo.js.map +1 -0
  35. package/dist/src/server/index.d.ts +67 -0
  36. package/dist/src/server/index.d.ts.map +1 -0
  37. package/dist/src/server/index.js +266 -0
  38. package/dist/src/server/index.js.map +1 -0
  39. package/dist/src/types/index.d.ts +67 -0
  40. package/dist/src/types/index.d.ts.map +1 -0
  41. package/dist/src/types/index.js +3 -0
  42. package/dist/src/types/index.js.map +1 -0
  43. package/dist/src/utils/constants.d.ts +29 -0
  44. package/dist/src/utils/constants.d.ts.map +1 -0
  45. package/dist/src/utils/constants.js +65 -0
  46. package/dist/src/utils/constants.js.map +1 -0
  47. package/dist/src/utils/encryption.d.ts +108 -0
  48. package/dist/src/utils/encryption.d.ts.map +1 -0
  49. package/dist/src/utils/encryption.js +420 -0
  50. package/dist/src/utils/encryption.js.map +1 -0
  51. package/dist/src/utils/logger.d.ts +10 -0
  52. package/dist/src/utils/logger.d.ts.map +1 -0
  53. package/dist/src/utils/logger.js +40 -0
  54. package/dist/src/utils/logger.js.map +1 -0
  55. package/dist/src/utils/utils.d.ts +65 -0
  56. package/dist/src/utils/utils.d.ts.map +1 -0
  57. package/dist/src/utils/utils.js +214 -0
  58. package/dist/src/utils/utils.js.map +1 -0
  59. package/package.json +62 -0
@@ -0,0 +1,259 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.X402PaymentClient = void 0;
7
+ const web3_js_1 = require("@solana/web3.js");
8
+ const privacycash_1 = require("privacycash");
9
+ const hasher_rs_1 = require("@lightprotocol/hasher.rs");
10
+ const crypto_1 = __importDefault(require("crypto"));
11
+ const encryption_1 = require("../utils/encryption");
12
+ const errors_1 = require("../errors");
13
+ /**
14
+ * X402 Payment Client for Privacy Cash
15
+ * Handles private payments for API access using Privacy Cash protocol
16
+ *
17
+ * Supports mock mode for demos without real transactions
18
+ */
19
+ class X402PaymentClient {
20
+ constructor(config) {
21
+ this.client = null;
22
+ this.encryptionService = null;
23
+ this.initialized = false;
24
+ this.mockBalance = 0; // Mock balance in lamports
25
+ this.config = config;
26
+ this.connection = new web3_js_1.Connection(config.rpcUrl, 'confirmed');
27
+ this.keypair = config.keypair;
28
+ this.network = config.rpcUrl.includes('devnet') ? 'devnet' : 'mainnet-beta';
29
+ this.mockMode = config.mockMode ?? false;
30
+ }
31
+ /**
32
+ * Initialize the client - must be called before other operations
33
+ */
34
+ async initialize() {
35
+ if (this.initialized) {
36
+ return;
37
+ }
38
+ if (this.mockMode) {
39
+ console.log('Initializing Privacy Cash SDK (MOCK MODE)...');
40
+ console.log(' Transactions will be simulated, no real SOL required');
41
+ // Initialize encryption service from keypair
42
+ this.encryptionService = new encryption_1.EncryptionService();
43
+ this.encryptionService.deriveEncryptionKeyFromWallet(this.keypair);
44
+ this.initialized = true;
45
+ console.log('Privacy Cash SDK initialized (MOCK MODE)');
46
+ return;
47
+ }
48
+ console.log('Initializing Privacy Cash SDK...');
49
+ // Initialize WASM
50
+ await hasher_rs_1.WasmFactory.getInstance();
51
+ // Initialize encryption service from keypair
52
+ this.encryptionService = new encryption_1.EncryptionService();
53
+ this.encryptionService.deriveEncryptionKeyFromWallet(this.keypair);
54
+ // Initialize Privacy Cash client with keypair
55
+ this.client = new privacycash_1.PrivacyCash({
56
+ RPC_url: this.connection.rpcEndpoint,
57
+ owner: this.keypair,
58
+ });
59
+ this.initialized = true;
60
+ console.log('Privacy Cash SDK initialized');
61
+ }
62
+ /**
63
+ * Get current private balance
64
+ */
65
+ async getPrivateBalance() {
66
+ this.ensureInitialized();
67
+ if (this.mockMode) {
68
+ return {
69
+ lamports: this.mockBalance,
70
+ sol: this.mockBalance / web3_js_1.LAMPORTS_PER_SOL,
71
+ };
72
+ }
73
+ const balance = await this.client.getPrivateBalance();
74
+ return {
75
+ lamports: balance.lamports,
76
+ sol: balance.lamports / web3_js_1.LAMPORTS_PER_SOL,
77
+ };
78
+ }
79
+ /**
80
+ * Deposit SOL into Privacy Cash pool
81
+ */
82
+ async deposit(lamports) {
83
+ this.ensureInitialized();
84
+ console.log(`Depositing ${lamports / web3_js_1.LAMPORTS_PER_SOL} SOL into Privacy Cash pool...`);
85
+ if (this.mockMode) {
86
+ // Simulate deposit delay
87
+ await this.sleep(1500);
88
+ this.mockBalance += lamports;
89
+ const mockTx = this.generateMockTxId();
90
+ console.log('Deposit successful! (MOCK)');
91
+ console.log(`Transaction: ${mockTx}`);
92
+ return { tx: mockTx };
93
+ }
94
+ const result = await this.client.deposit({ lamports });
95
+ console.log('Deposit successful!');
96
+ console.log(`Transaction: ${result.tx}`);
97
+ return { tx: result.tx };
98
+ }
99
+ /**
100
+ * Generate payment headers for a quote
101
+ * Returns headers to include in request to protected endpoint
102
+ */
103
+ async generatePayment(quote) {
104
+ this.ensureInitialized();
105
+ // Get current balance
106
+ const balance = await this.getPrivateBalance();
107
+ // Check if we have enough balance
108
+ if (balance.lamports < quote.payment.amount) {
109
+ throw new errors_1.InsufficientBalanceError(quote.payment.amount, balance.lamports);
110
+ }
111
+ // Generate unique commitment
112
+ const commitment = this.generateCommitment();
113
+ const noteHash = this.hashNote(commitment);
114
+ // Generate balance proof
115
+ const balanceProof = this.generateBalanceProof(balance.lamports);
116
+ // Create x402 payload
117
+ const payload = {
118
+ x402Version: 1,
119
+ scheme: 'privacycash',
120
+ network: `solana-${this.network}`,
121
+ payload: {
122
+ noteHash,
123
+ commitment,
124
+ timestamp: Date.now(),
125
+ balanceProof,
126
+ },
127
+ };
128
+ const xPaymentHeader = Buffer.from(JSON.stringify(payload)).toString('base64');
129
+ // Deduct from mock balance if in mock mode
130
+ if (this.mockMode) {
131
+ this.mockBalance -= quote.payment.amount;
132
+ }
133
+ return {
134
+ 'X-Payment': xPaymentHeader,
135
+ 'X-Privacy-Commitment': commitment,
136
+ 'X-Wallet-Address': this.keypair.publicKey.toBase58(),
137
+ };
138
+ }
139
+ /**
140
+ * Full payment flow: request quote, ensure balance, pay, return response
141
+ */
142
+ async payForAccess(url) {
143
+ this.ensureInitialized();
144
+ console.log(`\nRequesting payment quote from ${url}...`);
145
+ // Step 1: Request quote (expect 402)
146
+ const quoteRes = await fetch(url);
147
+ if (quoteRes.status !== 402) {
148
+ // Already have access or error
149
+ if (quoteRes.ok) {
150
+ const data = await quoteRes.json();
151
+ return { success: true, data };
152
+ }
153
+ throw new Error(`Unexpected status: ${quoteRes.status}`);
154
+ }
155
+ const quote = (await quoteRes.json());
156
+ console.log('Payment Quote:', {
157
+ recipient: quote.payment.recipientWallet,
158
+ amount: `${quote.payment.amount / web3_js_1.LAMPORTS_PER_SOL} SOL`,
159
+ });
160
+ // Step 2: Check balance and deposit if needed
161
+ let balance = await this.getPrivateBalance();
162
+ console.log(`Current private balance: ${balance.sol} SOL`);
163
+ if (balance.lamports < quote.payment.amount) {
164
+ console.log('Insufficient balance, depositing...');
165
+ await this.deposit(quote.payment.amount);
166
+ balance = await this.getPrivateBalance();
167
+ console.log(`New private balance: ${balance.sol} SOL`);
168
+ }
169
+ // Step 3: Generate payment headers
170
+ const headers = await this.generatePayment(quote);
171
+ // Step 4: Make paid request
172
+ console.log('Sending payment...');
173
+ const paidRes = await fetch(url, { headers });
174
+ if (!paidRes.ok) {
175
+ const errorData = await paidRes.json();
176
+ throw new Error(`Payment failed: ${JSON.stringify(errorData)}`);
177
+ }
178
+ const response = (await paidRes.json());
179
+ console.log('Payment verified! Access granted.');
180
+ return {
181
+ success: true,
182
+ data: response.data,
183
+ paymentDetails: response.paymentDetails,
184
+ };
185
+ }
186
+ /**
187
+ * Generate balance proof for server verification
188
+ */
189
+ generateBalanceProof(balance) {
190
+ const proof = {
191
+ balance,
192
+ timestamp: Date.now(),
193
+ wallet: this.keypair.publicKey.toBase58(),
194
+ };
195
+ return Buffer.from(JSON.stringify(proof)).toString('base64');
196
+ }
197
+ /**
198
+ * Generate unique commitment for this payment
199
+ */
200
+ generateCommitment() {
201
+ const data = `${this.keypair.publicKey.toBase58()}-${Date.now()}-${Math.random()}`;
202
+ return crypto_1.default.createHash('sha256').update(data).digest('hex');
203
+ }
204
+ /**
205
+ * Hash the commitment for x402 header
206
+ */
207
+ hashNote(note) {
208
+ return crypto_1.default.createHash('sha256').update(note).digest('hex');
209
+ }
210
+ /**
211
+ * Ensure client is initialized
212
+ */
213
+ ensureInitialized() {
214
+ if (!this.initialized) {
215
+ throw new Error('Client not initialized. Call initialize() first.');
216
+ }
217
+ if (!this.mockMode && !this.client) {
218
+ throw new Error('Client not initialized. Call initialize() first.');
219
+ }
220
+ }
221
+ /**
222
+ * Generate mock transaction ID
223
+ */
224
+ generateMockTxId() {
225
+ return crypto_1.default.randomBytes(32).toString('base64').replace(/[^a-zA-Z0-9]/g, '').substring(0, 44);
226
+ }
227
+ /**
228
+ * Sleep helper
229
+ */
230
+ sleep(ms) {
231
+ return new Promise(resolve => setTimeout(resolve, ms));
232
+ }
233
+ /**
234
+ * Check if running in mock mode
235
+ */
236
+ isMockMode() {
237
+ return this.mockMode;
238
+ }
239
+ /**
240
+ * Get the underlying Privacy Cash client (for advanced usage)
241
+ */
242
+ getPrivacyCashClient() {
243
+ return this.client;
244
+ }
245
+ /**
246
+ * Get the encryption service (for advanced usage)
247
+ */
248
+ getEncryptionService() {
249
+ return this.encryptionService;
250
+ }
251
+ /**
252
+ * Get the public key
253
+ */
254
+ getPublicKey() {
255
+ return this.keypair.publicKey;
256
+ }
257
+ }
258
+ exports.X402PaymentClient = X402PaymentClient;
259
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":";;;;;;AAAA,6CAIyB;AACzB,6CAA0C;AAC1C,wDAAuD;AACvD,oDAA4B;AAU5B,oDAAwD;AACxD,sCAAqD;AAErD;;;;;GAKG;AACH,MAAa,iBAAiB;IAW5B,YAAY,MAAwB;QAP5B,WAAM,GAAuB,IAAI,CAAC;QAClC,sBAAiB,GAA6B,IAAI,CAAC;QACnD,gBAAW,GAAY,KAAK,CAAC;QAG7B,gBAAW,GAAW,CAAC,CAAC,CAAC,2BAA2B;QAG1D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,IAAI,oBAAU,CAAC,MAAM,C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,EAAE,EAAE,CAAC,CAAC,CAAC;IACzD,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,oBAAoB;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,oBAAoB;QAClB,OAAO,IAAI,CAAC,iBAAiB,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;IAChC,CAAC;CACF;AAzSD,8CAySC"}
@@ -0,0 +1,10 @@
1
+ type Config = {
2
+ withdraw_fee_rate: number;
3
+ withdraw_rent_fee: number;
4
+ deposit_fee_rate: number;
5
+ usdc_withdraw_rent_fee: number;
6
+ rent_fees: any;
7
+ };
8
+ export declare function getConfig<K extends keyof Config>(key: K): Promise<Config[K]>;
9
+ export {};
10
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAEA,KAAK,MAAM,GAAG;IACV,iBAAiB,EAAE,MAAM,CAAA;IACzB,iBAAiB,EAAE,MAAM,CAAA;IACzB,gBAAgB,EAAE,MAAM,CAAA;IACxB,sBAAsB,EAAE,MAAM,CAAA;IAC9B,SAAS,EAAE,GAAG,CAAA;CACjB,CAAA;AAID,wBAAsB,SAAS,CAAC,CAAC,SAAS,MAAM,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CASlF"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getConfig = getConfig;
4
+ const constants_1 = require("./utils/constants");
5
+ let config;
6
+ async function getConfig(key) {
7
+ if (!config) {
8
+ const res = await fetch(constants_1.RELAYER_API_URL + '/config');
9
+ config = (await res.json());
10
+ }
11
+ if (typeof config[key] == 'undefined') {
12
+ throw new Error(`can not get ${key} from ${constants_1.RELAYER_API_URL}/config`);
13
+ }
14
+ return config[key];
15
+ }
16
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";;AAYA,8BASC;AArBD,iDAAoD;AAUpD,IAAI,MAA0B,CAAA;AAEvB,KAAK,UAAU,SAAS,CAAyB,GAAM;IAC1D,IAAI,CAAC,MAAM,EAAE,CAAC;QACV,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,2BAAe,GAAG,SAAS,CAAC,CAAA;QACpD,MAAM,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAW,CAAA;IACzC,CAAC;IACD,IAAI,OAAO,MAAO,CAAC,GAAG,CAAC,IAAI,WAAW,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,eAAe,GAAG,SAAS,2BAAe,SAAS,CAAC,CAAA;IACxE,CAAC;IACD,OAAO,MAAO,CAAC,GAAG,CAAC,CAAA;AACvB,CAAC"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Base error class for x402 payment errors
3
+ */
4
+ export declare class X402Error extends Error {
5
+ readonly code: string;
6
+ readonly statusCode: number;
7
+ constructor(message: string, code: string, statusCode?: number);
8
+ toJSON(): {
9
+ error: string;
10
+ code: string;
11
+ statusCode: number;
12
+ };
13
+ }
14
+ /**
15
+ * Thrown when user has insufficient private balance for payment
16
+ */
17
+ export declare class InsufficientBalanceError extends X402Error {
18
+ readonly required: number;
19
+ readonly available: number;
20
+ constructor(required: number, available?: number);
21
+ toJSON(): {
22
+ required: number;
23
+ available: number;
24
+ hint: string;
25
+ error: string;
26
+ code: string;
27
+ statusCode: number;
28
+ };
29
+ }
30
+ /**
31
+ * Thrown when a commitment has already been used (double-spend attempt)
32
+ */
33
+ export declare class DoubleSpendError extends X402Error {
34
+ readonly commitment: string;
35
+ constructor(commitment: string);
36
+ toJSON(): {
37
+ commitment: string;
38
+ hint: string;
39
+ error: string;
40
+ code: string;
41
+ statusCode: number;
42
+ };
43
+ }
44
+ /**
45
+ * Thrown when payment verification fails
46
+ */
47
+ export declare class InvalidPaymentError extends X402Error {
48
+ readonly reason: string;
49
+ constructor(reason: string);
50
+ toJSON(): {
51
+ reason: string;
52
+ error: string;
53
+ code: string;
54
+ statusCode: number;
55
+ };
56
+ }
57
+ /**
58
+ * Thrown when balance proof is expired or invalid
59
+ */
60
+ export declare class ExpiredBalanceProofError extends X402Error {
61
+ readonly proofTimestamp: number;
62
+ readonly currentTimestamp: number;
63
+ constructor(proofTimestamp: number);
64
+ toJSON(): {
65
+ proofTimestamp: number;
66
+ currentTimestamp: number;
67
+ hint: string;
68
+ error: string;
69
+ code: string;
70
+ statusCode: number;
71
+ };
72
+ }
73
+ /**
74
+ * Thrown when network/scheme mismatch occurs
75
+ */
76
+ export declare class NetworkMismatchError extends X402Error {
77
+ readonly expected: string;
78
+ readonly received: string;
79
+ constructor(expected: string, received: string);
80
+ }
81
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/errors/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAClC,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,UAAU,EAAE,MAAM,CAAC;gBAEvB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,GAAE,MAAY;IAOnE,MAAM;;;;;CAOP;AAED;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,SAAS;IACrD,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,SAAgB,SAAS,EAAE,MAAM,CAAC;gBAEtB,QAAQ,EAAE,MAAM,EAAE,SAAS,GAAE,MAAU;IAWnD,MAAM;;;;;;;;CAQP;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,SAAS;IAC7C,SAAgB,UAAU,EAAE,MAAM,CAAC;gBAEvB,UAAU,EAAE,MAAM;IAU9B,MAAM;;;;;;;CAOP;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,SAAS;IAChD,SAAgB,MAAM,EAAE,MAAM,CAAC;gBAEnB,MAAM,EAAE,MAAM;IAM1B,MAAM;;;;;;CAMP;AAED;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,SAAS;IACrD,SAAgB,cAAc,EAAE,MAAM,CAAC;IACvC,SAAgB,gBAAgB,EAAE,MAAM,CAAC;gBAE7B,cAAc,EAAE,MAAM;IAWlC,MAAM;;;;;;;;CAQP;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,SAAS;IACjD,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,SAAgB,QAAQ,EAAE,MAAM,CAAC;gBAErB,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAU/C"}
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NetworkMismatchError = exports.ExpiredBalanceProofError = exports.InvalidPaymentError = exports.DoubleSpendError = exports.InsufficientBalanceError = exports.X402Error = void 0;
4
+ /**
5
+ * Base error class for x402 payment errors
6
+ */
7
+ class X402Error extends Error {
8
+ constructor(message, code, statusCode = 400) {
9
+ super(message);
10
+ this.name = 'X402Error';
11
+ this.code = code;
12
+ this.statusCode = statusCode;
13
+ }
14
+ toJSON() {
15
+ return {
16
+ error: this.message,
17
+ code: this.code,
18
+ statusCode: this.statusCode,
19
+ };
20
+ }
21
+ }
22
+ exports.X402Error = X402Error;
23
+ /**
24
+ * Thrown when user has insufficient private balance for payment
25
+ */
26
+ class InsufficientBalanceError extends X402Error {
27
+ constructor(required, available = 0) {
28
+ super(`Insufficient private balance. Required: ${required} lamports, Available: ${available} lamports`, 'INSUFFICIENT_BALANCE', 402);
29
+ this.name = 'InsufficientBalanceError';
30
+ this.required = required;
31
+ this.available = available;
32
+ }
33
+ toJSON() {
34
+ return {
35
+ ...super.toJSON(),
36
+ required: this.required,
37
+ available: this.available,
38
+ hint: 'Please deposit more SOL into Privacy Cash pool',
39
+ };
40
+ }
41
+ }
42
+ exports.InsufficientBalanceError = InsufficientBalanceError;
43
+ /**
44
+ * Thrown when a commitment has already been used (double-spend attempt)
45
+ */
46
+ class DoubleSpendError extends X402Error {
47
+ constructor(commitment) {
48
+ super('Commitment already used. This payment has already been redeemed.', 'DOUBLE_SPEND', 402);
49
+ this.name = 'DoubleSpendError';
50
+ this.commitment = commitment;
51
+ }
52
+ toJSON() {
53
+ return {
54
+ ...super.toJSON(),
55
+ commitment: this.commitment.substring(0, 20) + '...',
56
+ hint: 'Generate a new payment commitment',
57
+ };
58
+ }
59
+ }
60
+ exports.DoubleSpendError = DoubleSpendError;
61
+ /**
62
+ * Thrown when payment verification fails
63
+ */
64
+ class InvalidPaymentError extends X402Error {
65
+ constructor(reason) {
66
+ super(`Invalid payment: ${reason}`, 'INVALID_PAYMENT', 400);
67
+ this.name = 'InvalidPaymentError';
68
+ this.reason = reason;
69
+ }
70
+ toJSON() {
71
+ return {
72
+ ...super.toJSON(),
73
+ reason: this.reason,
74
+ };
75
+ }
76
+ }
77
+ exports.InvalidPaymentError = InvalidPaymentError;
78
+ /**
79
+ * Thrown when balance proof is expired or invalid
80
+ */
81
+ class ExpiredBalanceProofError extends X402Error {
82
+ constructor(proofTimestamp) {
83
+ super('Balance proof has expired. Please generate a new payment.', 'EXPIRED_BALANCE_PROOF', 402);
84
+ this.name = 'ExpiredBalanceProofError';
85
+ this.proofTimestamp = proofTimestamp;
86
+ this.currentTimestamp = Date.now();
87
+ }
88
+ toJSON() {
89
+ return {
90
+ ...super.toJSON(),
91
+ proofTimestamp: this.proofTimestamp,
92
+ currentTimestamp: this.currentTimestamp,
93
+ hint: 'Balance proofs are valid for 5 minutes',
94
+ };
95
+ }
96
+ }
97
+ exports.ExpiredBalanceProofError = ExpiredBalanceProofError;
98
+ /**
99
+ * Thrown when network/scheme mismatch occurs
100
+ */
101
+ class NetworkMismatchError extends X402Error {
102
+ constructor(expected, received) {
103
+ super(`Network mismatch. Expected: ${expected}, Received: ${received}`, 'NETWORK_MISMATCH', 400);
104
+ this.name = 'NetworkMismatchError';
105
+ this.expected = expected;
106
+ this.received = received;
107
+ }
108
+ }
109
+ exports.NetworkMismatchError = NetworkMismatchError;
110
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/errors/index.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAa,SAAU,SAAQ,KAAK;IAIlC,YAAY,OAAe,EAAE,IAAY,EAAE,aAAqB,GAAG;QACjE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED,MAAM;QACJ,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,OAAO;YACnB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,UAAU,EAAE,IAAI,CAAC,UAAU;SAC5B,CAAC;IACJ,CAAC;CACF;AAlBD,8BAkBC;AAED;;GAEG;AACH,MAAa,wBAAyB,SAAQ,SAAS;IAIrD,YAAY,QAAgB,EAAE,YAAoB,CAAC;QACjD,KAAK,CACH,2CAA2C,QAAQ,yBAAyB,SAAS,WAAW,EAChG,sBAAsB,EACtB,GAAG,CACJ,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;QACvC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,MAAM;QACJ,OAAO;YACL,GAAG,KAAK,CAAC,MAAM,EAAE;YACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,SAAS,EA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GAAG,KAAK,CAAC,MAAM,EAAE;YACjB,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;YACvC,IAAI,EAAE,wCAAwC;SAC/C,CAAC;IACJ,CAAC;CACF;AAvBD,4DAuBC;AAED;;GAEG;AACH,MAAa,oBAAqB,SAAQ,SAAS;IAIjD,YAAY,QAAgB,EAAE,QAAgB;QAC5C,KAAK,CACH,+BAA+B,QAAQ,eAAe,QAAQ,EAAE,EAChE,kBAAkB,EAClB,GAAG,CACJ,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAdD,oDAcC"}
@@ -0,0 +1,10 @@
1
+ export { X402PaymentServer, createX402Middleware } from './server';
2
+ export { X402PaymentClient } from './client';
3
+ export * from './types';
4
+ export * from './errors';
5
+ export { EncryptionService } from './utils/encryption';
6
+ export { logger, setLogger } from './utils/logger';
7
+ export { PROGRAM_ID, RELAYER_API_URL, SIGN_MESSAGE, tokens, BALANCE_PROOF_VALIDITY_MS, } from './utils/constants';
8
+ export { Utxo } from './models/utxo';
9
+ export { Keypair } from './models/keypair';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAGnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAG7C,cAAc,SAAS,CAAC;AAGxB,cAAc,UAAU,CAAC;AAGzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EACL,UAAU,EACV,eAAe,EACf,YAAY,EACZ,MAAM,EACN,yBAAyB,GAC1B,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ // Main SDK exports
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.Keypair = exports.Utxo = exports.BALANCE_PROOF_VALIDITY_MS = exports.tokens = exports.SIGN_MESSAGE = exports.RELAYER_API_URL = exports.PROGRAM_ID = exports.setLogger = exports.logger = exports.EncryptionService = exports.X402PaymentClient = exports.createX402Middleware = exports.X402PaymentServer = void 0;
19
+ // Server
20
+ var server_1 = require("./server");
21
+ Object.defineProperty(exports, "X402PaymentServer", { enumerable: true, get: function () { return server_1.X402PaymentServer; } });
22
+ Object.defineProperty(exports, "createX402Middleware", { enumerable: true, get: function () { return server_1.createX402Middleware; } });
23
+ // Client
24
+ var client_1 = require("./client");
25
+ Object.defineProperty(exports, "X402PaymentClient", { enumerable: true, get: function () { return client_1.X402PaymentClient; } });
26
+ // Types
27
+ __exportStar(require("./types"), exports);
28
+ // Errors
29
+ __exportStar(require("./errors"), exports);
30
+ // Utils
31
+ var encryption_1 = require("./utils/encryption");
32
+ Object.defineProperty(exports, "EncryptionService", { enumerable: true, get: function () { return encryption_1.EncryptionService; } });
33
+ var logger_1 = require("./utils/logger");
34
+ Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return logger_1.logger; } });
35
+ Object.defineProperty(exports, "setLogger", { enumerable: true, get: function () { return logger_1.setLogger; } });
36
+ var constants_1 = require("./utils/constants");
37
+ Object.defineProperty(exports, "PROGRAM_ID", { enumerable: true, get: function () { return constants_1.PROGRAM_ID; } });
38
+ Object.defineProperty(exports, "RELAYER_API_URL", { enumerable: true, get: function () { return constants_1.RELAYER_API_URL; } });
39
+ Object.defineProperty(exports, "SIGN_MESSAGE", { enumerable: true, get: function () { return constants_1.SIGN_MESSAGE; } });
40
+ Object.defineProperty(exports, "tokens", { enumerable: true, get: function () { return constants_1.tokens; } });
41
+ Object.defineProperty(exports, "BALANCE_PROOF_VALIDITY_MS", { enumerable: true, get: function () { return constants_1.BALANCE_PROOF_VALIDITY_MS; } });
42
+ // Models (for advanced usage)
43
+ var utxo_1 = require("./models/utxo");
44
+ Object.defineProperty(exports, "Utxo", { enumerable: true, get: function () { return utxo_1.Utxo; } });
45
+ var keypair_1 = require("./models/keypair");
46
+ Object.defineProperty(exports, "Keypair", { enumerable: true, get: function () { return keypair_1.Keypair; } });
47
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,mBAAmB;;;;;;;;;;;;;;;;;AAEnB,SAAS;AACT,mCAAmE;AAA1D,2GAAA,iBAAiB,OAAA;AAAE,8GAAA,oBAAoB,OAAA;AAEhD,SAAS;AACT,mCAA6C;AAApC,2GAAA,iBAAiB,OAAA;AAE1B,QAAQ;AACR,0CAAwB;AAExB,SAAS;AACT,2CAAyB;AAEzB,QAAQ;AACR,iDAAuD;AAA9C,+GAAA,iBAAiB,OAAA;AAC1B,yCAAmD;AAA1C,gGAAA,MAAM,OAAA;AAAE,mGAAA,SAAS,OAAA;AAC1B,+CAM2B;AALzB,uGAAA,UAAU,OAAA;AACV,4GAAA,eAAe,OAAA;AACf,yGAAA,YAAY,OAAA;AACZ,mGAAA,MAAM,OAAA;AACN,sHAAA,yBAAyB,OAAA;AAG3B,8BAA8B;AAC9B,sCAAqC;AAA5B,4FAAA,IAAI,OAAA;AACb,4CAA2C;AAAlC,kGAAA,OAAO,OAAA"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Keypair module for ZK Cash
3
+ *
4
+ * Provides cryptographic keypair functionality for the ZK Cash system
5
+ * Based on: https://github.com/tornadocash/tornado-nova
6
+ */
7
+ import BN from 'bn.js';
8
+ import * as hasher from '@lightprotocol/hasher.rs';
9
+ /**
10
+ * Simplified version of Keypair
11
+ */
12
+ export declare class Keypair {
13
+ privkey: BN;
14
+ pubkey: BN;
15
+ private lightWasm;
16
+ constructor(privkeyHex: string, lightWasm: hasher.LightWasm);
17
+ /**
18
+ * Sign a message using keypair private key
19
+ *
20
+ * @param {string|number|BigNumber} commitment a hex string with commitment
21
+ * @param {string|number|BigNumber} merklePath a hex string with merkle path
22
+ * @returns {BigNumber} a hex string with signature
23
+ */
24
+ sign(commitment: string, merklePath: string): string;
25
+ static generateNew(lightWasm: hasher.LightWasm): Promise<Keypair>;
26
+ }
27
+ //# sourceMappingURL=keypair.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keypair.d.ts","sourceRoot":"","sources":["../../../src/models/keypair.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,OAAO,CAAC;AAEvB,OAAO,KAAK,MAAM,MAAM,0BAA0B,CAAC;AAOnD;;GAEG;AACH,qBAAa,OAAO;IACT,OAAO,EAAE,EAAE,CAAC;IACZ,MAAM,EAAE,EAAE,CAAC;IAClB,OAAO,CAAC,SAAS,CAAmB;gBAExB,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS;IAQ3D;;;;;;MAME;IACF,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM;WAIvC,WAAW,CAAC,SAAS,EAAE,MAAM,CAAC,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC;CAQ1E"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ /**
3
+ * Keypair module for ZK Cash
4
+ *
5
+ * Provides cryptographic keypair functionality for the ZK Cash system
6
+ * Based on: https://github.com/tornadocash/tornado-nova
7
+ */
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Keypair = void 0;
13
+ const bn_js_1 = __importDefault(require("bn.js"));
14
+ const ethers_1 = require("ethers");
15
+ // Field size constant
16
+ const FIELD_SIZE = new bn_js_1.default('21888242871839275222246405745257275088548364400416034343698204186575808495617');
17
+ /**
18
+ * Simplified version of Keypair
19
+ */
20
+ class Keypair {
21
+ constructor(privkeyHex, lightWasm) {
22
+ const rawDecimal = BigInt(privkeyHex);
23
+ this.privkey = new bn_js_1.default((rawDecimal % BigInt(FIELD_SIZE.toString())).toString());
24
+ this.lightWasm = lightWasm;
25
+ // TODO: lazily compute pubkey
26
+ this.pubkey = new bn_js_1.default(this.lightWasm.poseidonHashString([this.privkey.toString()]));
27
+ }
28
+ /**
29
+ * Sign a message using keypair private key
30
+ *
31
+ * @param {string|number|BigNumber} commitment a hex string with commitment
32
+ * @param {string|number|BigNumber} merklePath a hex string with merkle path
33
+ * @returns {BigNumber} a hex string with signature
34
+ */
35
+ sign(commitment, merklePath) {
36
+ return this.lightWasm.poseidonHashString([this.privkey.toString(), commitment, merklePath]);
37
+ }
38
+ static async generateNew(lightWasm) {
39
+ // Tornado Cash Nova uses ethers.js to generate a random private key
40
+ // We can't generate Solana keypairs because it won't fit in the field size
41
+ // It's OK to use ethereum secret keys, because the secret key is only used for the proof generation.
42
+ // Namely, it's used to guarantee the uniqueness of the nullifier.
43
+ const wallet = ethers_1.ethers.Wallet.createRandom();
44
+ return new Keypair(wallet.privateKey, lightWasm);
45
+ }
46
+ }
47
+ exports.Keypair = Keypair;
48
+ //# sourceMappingURL=keypair.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keypair.js","sourceRoot":"","sources":["../../../src/models/keypair.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AAEH,kDAAuB;AACvB,mCAAgC;AAGhC,sBAAsB;AACtB,MAAM,UAAU,GAAG,IAAI,eAAE,CACrB,+EAA+E,CAClF,CAAC;AAEF;;GAEG;AACH,MAAa,OAAO;IAKhB,YAAY,UAAkB,EAAE,SAA2B;QACvD,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;QACtC,IAAI,CAAC,OAAO,GAAG,IAAI,eAAE,CAAC,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC/E,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,8BAA8B;QAC9B,IAAI,CAAC,MAAM,GAAG,IAAI,eAAE,CAAC,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC;IACvF,CAAC;IAED;;;;;;MAME;IACF,IAAI,CAAC,UAAkB,EAAE,UAAkB;QACvC,OAAO,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;IAChG,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,SAA2B;QAChD,oEAAoE;QACpE,2EAA2E;QAC3E,qGAAqG;QACrG,kEAAkE;QAClE,MAAM,MAAM,GAAG,eAAM,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;QAC5C,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;IACrD,CAAC;CACJ;AAhCD,0BAgCC"}