x402-express-mantle 1.0.0 → 1.0.2

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 (125) hide show
  1. package/README.md +19 -1
  2. package/lib/cjs/index.d.ts +119 -81
  3. package/lib/cjs/index.js +3 -3
  4. package/lib/esm/index.d.mts +5 -5
  5. package/lib/esm/index.mjs +3 -3
  6. package/package.json +4 -3
  7. package/lib/cjs/client/index.d.ts +0 -243
  8. package/lib/cjs/client/index.js +0 -413
  9. package/lib/cjs/client/index.js.map +0 -1
  10. package/lib/cjs/exact/client/index.d.ts +0 -37
  11. package/lib/cjs/exact/client/index.js +0 -281
  12. package/lib/cjs/exact/client/index.js.map +0 -1
  13. package/lib/cjs/exact/facilitator/index.d.ts +0 -110
  14. package/lib/cjs/exact/facilitator/index.js +0 -714
  15. package/lib/cjs/exact/facilitator/index.js.map +0 -1
  16. package/lib/cjs/exact/server/index.d.ts +0 -87
  17. package/lib/cjs/exact/server/index.js +0 -209
  18. package/lib/cjs/exact/server/index.js.map +0 -1
  19. package/lib/cjs/exact/v1/client/index.d.ts +0 -33
  20. package/lib/cjs/exact/v1/client/index.js +0 -169
  21. package/lib/cjs/exact/v1/client/index.js.map +0 -1
  22. package/lib/cjs/exact/v1/facilitator/index.d.ts +0 -71
  23. package/lib/cjs/exact/v1/facilitator/index.js +0 -384
  24. package/lib/cjs/exact/v1/facilitator/index.js.map +0 -1
  25. package/lib/cjs/facilitator/index.d.ts +0 -192
  26. package/lib/cjs/facilitator/index.js +0 -398
  27. package/lib/cjs/facilitator/index.js.map +0 -1
  28. package/lib/cjs/http/index.d.ts +0 -52
  29. package/lib/cjs/http/index.js +0 -827
  30. package/lib/cjs/http/index.js.map +0 -1
  31. package/lib/cjs/mechanisms-CzuGzYsS.d.ts +0 -270
  32. package/lib/cjs/scheme-MoBRXFM8.d.ts +0 -29
  33. package/lib/cjs/server/index.d.ts +0 -2
  34. package/lib/cjs/server/index.js +0 -1305
  35. package/lib/cjs/server/index.js.map +0 -1
  36. package/lib/cjs/signer-5OVDxViv.d.ts +0 -79
  37. package/lib/cjs/signer-BMkbhFYE.d.ts +0 -123
  38. package/lib/cjs/types/index.d.ts +0 -1
  39. package/lib/cjs/types/index.js +0 -66
  40. package/lib/cjs/types/index.js.map +0 -1
  41. package/lib/cjs/types/v1/index.d.ts +0 -1
  42. package/lib/cjs/types/v1/index.js +0 -19
  43. package/lib/cjs/types/v1/index.js.map +0 -1
  44. package/lib/cjs/utils/index.d.ts +0 -48
  45. package/lib/cjs/utils/index.js +0 -116
  46. package/lib/cjs/utils/index.js.map +0 -1
  47. package/lib/cjs/v1/index.d.ts +0 -12
  48. package/lib/cjs/v1/index.js +0 -180
  49. package/lib/cjs/v1/index.js.map +0 -1
  50. package/lib/cjs/x402HTTPResourceServer-D1YtlH_r.d.ts +0 -719
  51. package/lib/esm/chunk-3CEIVWNN.mjs +0 -339
  52. package/lib/esm/chunk-3CEIVWNN.mjs.map +0 -1
  53. package/lib/esm/chunk-BJTO5JO5.mjs +0 -11
  54. package/lib/esm/chunk-BJTO5JO5.mjs.map +0 -1
  55. package/lib/esm/chunk-EEA7DKZI.mjs +0 -111
  56. package/lib/esm/chunk-EEA7DKZI.mjs.map +0 -1
  57. package/lib/esm/chunk-FOUXRQAV.mjs +0 -88
  58. package/lib/esm/chunk-FOUXRQAV.mjs.map +0 -1
  59. package/lib/esm/chunk-IKSTWKEM.mjs +0 -157
  60. package/lib/esm/chunk-IKSTWKEM.mjs.map +0 -1
  61. package/lib/esm/chunk-JYZWCLMP.mjs +0 -305
  62. package/lib/esm/chunk-JYZWCLMP.mjs.map +0 -1
  63. package/lib/esm/chunk-PNSAJQCF.mjs +0 -108
  64. package/lib/esm/chunk-PNSAJQCF.mjs.map +0 -1
  65. package/lib/esm/chunk-PSA4YVU2.mjs +0 -92
  66. package/lib/esm/chunk-PSA4YVU2.mjs.map +0 -1
  67. package/lib/esm/chunk-QLXM7BIB.mjs +0 -23
  68. package/lib/esm/chunk-QLXM7BIB.mjs.map +0 -1
  69. package/lib/esm/chunk-TDLQZ6MP.mjs +0 -86
  70. package/lib/esm/chunk-TDLQZ6MP.mjs.map +0 -1
  71. package/lib/esm/chunk-VE37GDG2.mjs +0 -7
  72. package/lib/esm/chunk-VE37GDG2.mjs.map +0 -1
  73. package/lib/esm/chunk-WWACQNRQ.mjs +0 -7
  74. package/lib/esm/chunk-WWACQNRQ.mjs.map +0 -1
  75. package/lib/esm/chunk-X4W4S5RB.mjs +0 -39
  76. package/lib/esm/chunk-X4W4S5RB.mjs.map +0 -1
  77. package/lib/esm/chunk-Z4QX3O5V.mjs +0 -748
  78. package/lib/esm/chunk-Z4QX3O5V.mjs.map +0 -1
  79. package/lib/esm/chunk-ZYXTTU74.mjs +0 -88
  80. package/lib/esm/chunk-ZYXTTU74.mjs.map +0 -1
  81. package/lib/esm/client/index.d.mts +0 -243
  82. package/lib/esm/client/index.mjs +0 -260
  83. package/lib/esm/client/index.mjs.map +0 -1
  84. package/lib/esm/exact/client/index.d.mts +0 -37
  85. package/lib/esm/exact/client/index.mjs +0 -36
  86. package/lib/esm/exact/client/index.mjs.map +0 -1
  87. package/lib/esm/exact/facilitator/index.d.mts +0 -110
  88. package/lib/esm/exact/facilitator/index.mjs +0 -350
  89. package/lib/esm/exact/facilitator/index.mjs.map +0 -1
  90. package/lib/esm/exact/server/index.d.mts +0 -87
  91. package/lib/esm/exact/server/index.mjs +0 -129
  92. package/lib/esm/exact/server/index.mjs.map +0 -1
  93. package/lib/esm/exact/v1/client/index.d.mts +0 -33
  94. package/lib/esm/exact/v1/client/index.mjs +0 -8
  95. package/lib/esm/exact/v1/client/index.mjs.map +0 -1
  96. package/lib/esm/exact/v1/facilitator/index.d.mts +0 -71
  97. package/lib/esm/exact/v1/facilitator/index.mjs +0 -8
  98. package/lib/esm/exact/v1/facilitator/index.mjs.map +0 -1
  99. package/lib/esm/facilitator/index.d.mts +0 -192
  100. package/lib/esm/facilitator/index.mjs +0 -373
  101. package/lib/esm/facilitator/index.mjs.map +0 -1
  102. package/lib/esm/http/index.d.mts +0 -52
  103. package/lib/esm/http/index.mjs +0 -29
  104. package/lib/esm/http/index.mjs.map +0 -1
  105. package/lib/esm/mechanisms-CzuGzYsS.d.mts +0 -270
  106. package/lib/esm/scheme-fjF-9LhT.d.mts +0 -29
  107. package/lib/esm/server/index.d.mts +0 -2
  108. package/lib/esm/server/index.mjs +0 -563
  109. package/lib/esm/server/index.mjs.map +0 -1
  110. package/lib/esm/signer-5OVDxViv.d.mts +0 -79
  111. package/lib/esm/signer-BMkbhFYE.d.mts +0 -123
  112. package/lib/esm/types/index.d.mts +0 -1
  113. package/lib/esm/types/index.mjs +0 -10
  114. package/lib/esm/types/index.mjs.map +0 -1
  115. package/lib/esm/types/v1/index.d.mts +0 -1
  116. package/lib/esm/types/v1/index.mjs +0 -1
  117. package/lib/esm/types/v1/index.mjs.map +0 -1
  118. package/lib/esm/utils/index.d.mts +0 -48
  119. package/lib/esm/utils/index.mjs +0 -20
  120. package/lib/esm/utils/index.mjs.map +0 -1
  121. package/lib/esm/v1/index.d.mts +0 -12
  122. package/lib/esm/v1/index.mjs +0 -13
  123. package/lib/esm/v1/index.mjs.map +0 -1
  124. package/lib/esm/x402HTTPResourceServer-BIfIK5HS.d.mts +0 -719
  125. package/src/index.js +0 -4
@@ -1,169 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/exact/v1/client/index.ts
21
- var client_exports = {};
22
- __export(client_exports, {
23
- ExactSvmSchemeV1: () => ExactSvmSchemeV1
24
- });
25
- module.exports = __toCommonJS(client_exports);
26
-
27
- // src/exact/v1/client/scheme.ts
28
- var import_compute_budget = require("@solana-program/compute-budget");
29
- var import_token2 = require("@solana-program/token");
30
- var import_token_20222 = require("@solana-program/token-2022");
31
- var import_kit2 = require("@solana/kit");
32
-
33
- // src/constants.ts
34
- var DEVNET_RPC_URL = "https://api.devnet.solana.com";
35
- var TESTNET_RPC_URL = "https://api.testnet.solana.com";
36
- var MAINNET_RPC_URL = "https://api.mainnet-beta.solana.com";
37
- var DEFAULT_COMPUTE_UNIT_PRICE_MICROLAMPORTS = 1;
38
- var DEFAULT_COMPUTE_UNIT_LIMIT = 6500;
39
- var SOLANA_MAINNET_CAIP2 = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
40
- var SOLANA_DEVNET_CAIP2 = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
41
- var SOLANA_TESTNET_CAIP2 = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z";
42
- var V1_TO_V2_NETWORK_MAP = {
43
- solana: SOLANA_MAINNET_CAIP2,
44
- "solana-devnet": SOLANA_DEVNET_CAIP2,
45
- "solana-testnet": SOLANA_TESTNET_CAIP2
46
- };
47
-
48
- // src/utils.ts
49
- var import_kit = require("@solana/kit");
50
- var import_token = require("@solana-program/token");
51
- var import_token_2022 = require("@solana-program/token-2022");
52
- function normalizeNetwork(network) {
53
- if (network.includes(":")) {
54
- const supported = [SOLANA_MAINNET_CAIP2, SOLANA_DEVNET_CAIP2, SOLANA_TESTNET_CAIP2];
55
- if (!supported.includes(network)) {
56
- throw new Error(`Unsupported SVM network: ${network}`);
57
- }
58
- return network;
59
- }
60
- const caip2Network = V1_TO_V2_NETWORK_MAP[network];
61
- if (!caip2Network) {
62
- throw new Error(`Unsupported SVM network: ${network}`);
63
- }
64
- return caip2Network;
65
- }
66
- function createRpcClient(network, customRpcUrl) {
67
- const caip2Network = normalizeNetwork(network);
68
- switch (caip2Network) {
69
- case SOLANA_DEVNET_CAIP2: {
70
- const url = customRpcUrl || DEVNET_RPC_URL;
71
- return (0, import_kit.createSolanaRpc)((0, import_kit.devnet)(url));
72
- }
73
- case SOLANA_TESTNET_CAIP2: {
74
- const url = customRpcUrl || TESTNET_RPC_URL;
75
- return (0, import_kit.createSolanaRpc)((0, import_kit.testnet)(url));
76
- }
77
- case SOLANA_MAINNET_CAIP2: {
78
- const url = customRpcUrl || MAINNET_RPC_URL;
79
- return (0, import_kit.createSolanaRpc)((0, import_kit.mainnet)(url));
80
- }
81
- default:
82
- throw new Error(`Unsupported network: ${network}`);
83
- }
84
- }
85
-
86
- // src/exact/v1/client/scheme.ts
87
- var ExactSvmSchemeV1 = class {
88
- /**
89
- * Creates a new ExactSvmClientV1 instance.
90
- *
91
- * @param signer - The SVM signer for client operations
92
- * @param config - Optional configuration with custom RPC URL
93
- * @returns ExactSvmClientV1 instance
94
- */
95
- constructor(signer, config) {
96
- this.signer = signer;
97
- this.config = config;
98
- this.scheme = "exact";
99
- }
100
- /**
101
- * Creates a payment payload for the Exact scheme (V1).
102
- *
103
- * @param x402Version - The x402 protocol version
104
- * @param paymentRequirements - The payment requirements
105
- * @returns Promise resolving to a payment payload
106
- */
107
- async createPaymentPayload(x402Version, paymentRequirements) {
108
- const selectedV1 = paymentRequirements;
109
- const rpc = createRpcClient(selectedV1.network, this.config?.rpcUrl);
110
- const tokenMint = await (0, import_token_20222.fetchMint)(rpc, selectedV1.asset);
111
- const tokenProgramAddress = tokenMint.programAddress;
112
- if (tokenProgramAddress.toString() !== import_token2.TOKEN_PROGRAM_ADDRESS.toString() && tokenProgramAddress.toString() !== import_token_20222.TOKEN_2022_PROGRAM_ADDRESS.toString()) {
113
- throw new Error("Asset was not created by a known token program");
114
- }
115
- const [sourceATA] = await (0, import_token_20222.findAssociatedTokenPda)({
116
- mint: selectedV1.asset,
117
- owner: this.signer.address,
118
- tokenProgram: tokenProgramAddress
119
- });
120
- const [destinationATA] = await (0, import_token_20222.findAssociatedTokenPda)({
121
- mint: selectedV1.asset,
122
- owner: selectedV1.payTo,
123
- tokenProgram: tokenProgramAddress
124
- });
125
- const transferIx = (0, import_token_20222.getTransferCheckedInstruction)(
126
- {
127
- source: sourceATA,
128
- mint: selectedV1.asset,
129
- destination: destinationATA,
130
- authority: this.signer,
131
- amount: BigInt(selectedV1.maxAmountRequired),
132
- decimals: tokenMint.data.decimals
133
- },
134
- { programAddress: tokenProgramAddress }
135
- );
136
- const feePayer = selectedV1.extra?.feePayer;
137
- if (!feePayer) {
138
- throw new Error("feePayer is required in paymentRequirements.extra for SVM transactions");
139
- }
140
- const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();
141
- const tx = (0, import_kit2.pipe)(
142
- (0, import_kit2.createTransactionMessage)({ version: 0 }),
143
- (tx2) => (0, import_compute_budget.setTransactionMessageComputeUnitPrice)(DEFAULT_COMPUTE_UNIT_PRICE_MICROLAMPORTS, tx2),
144
- (tx2) => (0, import_kit2.setTransactionMessageFeePayer)(feePayer, tx2),
145
- (tx2) => (0, import_kit2.prependTransactionMessageInstruction)(
146
- (0, import_compute_budget.getSetComputeUnitLimitInstruction)({ units: DEFAULT_COMPUTE_UNIT_LIMIT }),
147
- tx2
148
- ),
149
- (tx2) => (0, import_kit2.appendTransactionMessageInstructions)([transferIx], tx2),
150
- (tx2) => (0, import_kit2.setTransactionMessageLifetimeUsingBlockhash)(latestBlockhash, tx2)
151
- );
152
- const signedTransaction = await (0, import_kit2.partiallySignTransactionMessageWithSigners)(tx);
153
- const base64EncodedWireTransaction = (0, import_kit2.getBase64EncodedWireTransaction)(signedTransaction);
154
- const payload = {
155
- transaction: base64EncodedWireTransaction
156
- };
157
- return {
158
- x402Version,
159
- scheme: selectedV1.scheme,
160
- network: selectedV1.network,
161
- payload
162
- };
163
- }
164
- };
165
- // Annotate the CommonJS export names for ESM import in node:
166
- 0 && (module.exports = {
167
- ExactSvmSchemeV1
168
- });
169
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../../src/exact/v1/client/index.ts","../../../../../src/exact/v1/client/scheme.ts","../../../../../src/constants.ts","../../../../../src/utils.ts"],"sourcesContent":["export { ExactSvmSchemeV1 } from \"./scheme\";\n","import {\n getSetComputeUnitLimitInstruction,\n setTransactionMessageComputeUnitPrice,\n} from \"@solana-program/compute-budget\";\nimport { TOKEN_PROGRAM_ADDRESS } from \"@solana-program/token\";\nimport {\n fetchMint,\n findAssociatedTokenPda,\n getTransferCheckedInstruction,\n TOKEN_2022_PROGRAM_ADDRESS,\n} from \"@solana-program/token-2022\";\nimport {\n appendTransactionMessageInstructions,\n createTransactionMessage,\n getBase64EncodedWireTransaction,\n partiallySignTransactionMessageWithSigners,\n pipe,\n prependTransactionMessageInstruction,\n setTransactionMessageFeePayer,\n setTransactionMessageLifetimeUsingBlockhash,\n type Address,\n} from \"@solana/kit\";\nimport type {\n Network,\n PaymentPayload,\n PaymentRequirements,\n SchemeNetworkClient,\n} from \"@x402/core/types\";\nimport type { PaymentRequirementsV1 } from \"@x402/core/types/v1\";\nimport {\n DEFAULT_COMPUTE_UNIT_LIMIT,\n DEFAULT_COMPUTE_UNIT_PRICE_MICROLAMPORTS,\n} from \"../../../constants\";\nimport type { ClientSvmConfig, ClientSvmSigner } from \"../../../signer\";\nimport type { ExactSvmPayloadV1 } from \"../../../types\";\nimport { createRpcClient } from \"../../../utils\";\n\n/**\n * SVM client implementation for the Exact payment scheme (V1).\n */\nexport class ExactSvmSchemeV1 implements SchemeNetworkClient {\n readonly scheme = \"exact\";\n\n /**\n * Creates a new ExactSvmClientV1 instance.\n *\n * @param signer - The SVM signer for client operations\n * @param config - Optional configuration with custom RPC URL\n * @returns ExactSvmClientV1 instance\n */\n constructor(\n private readonly signer: ClientSvmSigner,\n private readonly config?: ClientSvmConfig,\n ) {}\n\n /**\n * Creates a payment payload for the Exact scheme (V1).\n *\n * @param x402Version - The x402 protocol version\n * @param paymentRequirements - The payment requirements\n * @returns Promise resolving to a payment payload\n */\n async createPaymentPayload(\n x402Version: number,\n paymentRequirements: PaymentRequirements,\n ): Promise<\n Pick<PaymentPayload, \"x402Version\" | \"payload\"> & { scheme: string; network: Network }\n > {\n const selectedV1 = paymentRequirements as unknown as PaymentRequirementsV1;\n const rpc = createRpcClient(selectedV1.network, this.config?.rpcUrl);\n\n const tokenMint = await fetchMint(rpc, selectedV1.asset as Address);\n const tokenProgramAddress = tokenMint.programAddress;\n\n if (\n tokenProgramAddress.toString() !== TOKEN_PROGRAM_ADDRESS.toString() &&\n tokenProgramAddress.toString() !== TOKEN_2022_PROGRAM_ADDRESS.toString()\n ) {\n throw new Error(\"Asset was not created by a known token program\");\n }\n\n const [sourceATA] = await findAssociatedTokenPda({\n mint: selectedV1.asset as Address,\n owner: this.signer.address,\n tokenProgram: tokenProgramAddress,\n });\n\n const [destinationATA] = await findAssociatedTokenPda({\n mint: selectedV1.asset as Address,\n owner: selectedV1.payTo as Address,\n tokenProgram: tokenProgramAddress,\n });\n\n const transferIx = getTransferCheckedInstruction(\n {\n source: sourceATA,\n mint: selectedV1.asset as Address,\n destination: destinationATA,\n authority: this.signer,\n amount: BigInt(selectedV1.maxAmountRequired),\n decimals: tokenMint.data.decimals,\n },\n { programAddress: tokenProgramAddress },\n );\n\n // Facilitator must provide feePayer to cover transaction fees\n const feePayer = selectedV1.extra?.feePayer as Address;\n if (!feePayer) {\n throw new Error(\"feePayer is required in paymentRequirements.extra for SVM transactions\");\n }\n\n const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();\n\n const tx = pipe(\n createTransactionMessage({ version: 0 }),\n tx => setTransactionMessageComputeUnitPrice(DEFAULT_COMPUTE_UNIT_PRICE_MICROLAMPORTS, tx),\n tx => setTransactionMessageFeePayer(feePayer, tx),\n tx =>\n prependTransactionMessageInstruction(\n getSetComputeUnitLimitInstruction({ units: DEFAULT_COMPUTE_UNIT_LIMIT }),\n tx,\n ),\n tx => appendTransactionMessageInstructions([transferIx], tx),\n tx => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),\n );\n\n const signedTransaction = await partiallySignTransactionMessageWithSigners(tx);\n const base64EncodedWireTransaction = getBase64EncodedWireTransaction(signedTransaction);\n\n const payload: ExactSvmPayloadV1 = {\n transaction: base64EncodedWireTransaction,\n };\n\n return {\n x402Version,\n scheme: selectedV1.scheme,\n network: selectedV1.network,\n payload,\n };\n }\n}\n","/**\n * Token program addresses for SPL Token and Token-2022\n * These addresses are the same across all Solana networks (mainnet, devnet, testnet)\n */\nexport const TOKEN_PROGRAM_ADDRESS = \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\";\nexport const TOKEN_2022_PROGRAM_ADDRESS = \"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb\";\nexport const COMPUTE_BUDGET_PROGRAM_ADDRESS = \"ComputeBudget111111111111111111111111111111\";\n\n/**\n * Default RPC URLs for Solana networks\n */\nexport const DEVNET_RPC_URL = \"https://api.devnet.solana.com\";\nexport const TESTNET_RPC_URL = \"https://api.testnet.solana.com\";\nexport const MAINNET_RPC_URL = \"https://api.mainnet-beta.solana.com\";\nexport const DEVNET_WS_URL = \"wss://api.devnet.solana.com\";\nexport const TESTNET_WS_URL = \"wss://api.testnet.solana.com\";\nexport const MAINNET_WS_URL = \"wss://api.mainnet-beta.solana.com\";\n\n/**\n * USDC token mint addresses (default stablecoin)\n */\nexport const USDC_MAINNET_ADDRESS = \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\";\nexport const USDC_DEVNET_ADDRESS = \"4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU\";\nexport const USDC_TESTNET_ADDRESS = \"4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU\"; // Same as devnet\n\n/**\n * Compute budget configuration\n * All prices are in microlamports (1 lamport = 1,000,000 microlamports)\n */\nexport const DEFAULT_COMPUTE_UNIT_PRICE_MICROLAMPORTS = 1;\nexport const MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS = 5_000_000; // 5 lamports\nexport const DEFAULT_COMPUTE_UNIT_LIMIT = 6500;\n\n/**\n * Solana address validation regex (base58, 32-44 characters)\n */\nexport const SVM_ADDRESS_REGEX = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;\n\n/**\n * CAIP-2 network identifiers for Solana (V2)\n */\nexport const SOLANA_MAINNET_CAIP2 = \"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp\";\nexport const SOLANA_DEVNET_CAIP2 = \"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1\";\nexport const SOLANA_TESTNET_CAIP2 = \"solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z\";\n\n/**\n * V1 to V2 network identifier mappings (for backwards compatibility)\n * V1 used simple names like solana, V2 uses CAIP-2\n */\nexport const V1_TO_V2_NETWORK_MAP: Record<string, string> = {\n solana: SOLANA_MAINNET_CAIP2,\n \"solana-devnet\": SOLANA_DEVNET_CAIP2,\n \"solana-testnet\": SOLANA_TESTNET_CAIP2,\n};\n","import {\n getBase64Encoder,\n getTransactionDecoder,\n getCompiledTransactionMessageDecoder,\n type Transaction,\n createSolanaRpc,\n devnet,\n testnet,\n mainnet,\n type RpcDevnet,\n type SolanaRpcApiDevnet,\n type RpcTestnet,\n type SolanaRpcApiTestnet,\n type RpcMainnet,\n type SolanaRpcApiMainnet,\n} from \"@solana/kit\";\nimport { TOKEN_PROGRAM_ADDRESS } from \"@solana-program/token\";\nimport { TOKEN_2022_PROGRAM_ADDRESS } from \"@solana-program/token-2022\";\nimport type { Network } from \"@x402/core/types\";\nimport {\n SVM_ADDRESS_REGEX,\n DEVNET_RPC_URL,\n TESTNET_RPC_URL,\n MAINNET_RPC_URL,\n USDC_MAINNET_ADDRESS,\n USDC_DEVNET_ADDRESS,\n USDC_TESTNET_ADDRESS,\n SOLANA_MAINNET_CAIP2,\n SOLANA_DEVNET_CAIP2,\n SOLANA_TESTNET_CAIP2,\n V1_TO_V2_NETWORK_MAP,\n} from \"./constants\";\nimport type { ExactSvmPayloadV1 } from \"./types\";\n\n/**\n * Normalize network identifier to CAIP-2 format\n * Handles both V1 names (solana, solana-devnet) and V2 CAIP-2 format\n *\n * @param network - Network identifier (V1 or V2 format)\n * @returns CAIP-2 network identifier\n */\nexport function normalizeNetwork(network: Network): string {\n // If it's already CAIP-2 format (contains \":\"), validate it's supported\n if (network.includes(\":\")) {\n const supported = [SOLANA_MAINNET_CAIP2, SOLANA_DEVNET_CAIP2, SOLANA_TESTNET_CAIP2];\n if (!supported.includes(network)) {\n throw new Error(`Unsupported SVM network: ${network}`);\n }\n return network;\n }\n\n // Otherwise, it's a V1 network name, convert to CAIP-2\n const caip2Network = V1_TO_V2_NETWORK_MAP[network];\n if (!caip2Network) {\n throw new Error(`Unsupported SVM network: ${network}`);\n }\n return caip2Network;\n}\n\n/**\n * Validate Solana address format\n *\n * @param address - Base58 encoded address string\n * @returns true if address is valid, false otherwise\n */\nexport function validateSvmAddress(address: string): boolean {\n return SVM_ADDRESS_REGEX.test(address);\n}\n\n/**\n * Decode a base64 encoded transaction from an SVM payload\n *\n * @param svmPayload - The SVM payload containing a base64 encoded transaction\n * @returns Decoded Transaction object\n */\nexport function decodeTransactionFromPayload(svmPayload: ExactSvmPayloadV1): Transaction {\n try {\n const base64Encoder = getBase64Encoder();\n const transactionBytes = base64Encoder.encode(svmPayload.transaction);\n const transactionDecoder = getTransactionDecoder();\n return transactionDecoder.decode(transactionBytes);\n } catch (error) {\n console.error(\"Error decoding transaction:\", error);\n throw new Error(\"invalid_exact_svm_payload_transaction\");\n }\n}\n\n/**\n * Extract the token sender (owner of the source token account) from a TransferChecked instruction\n *\n * @param transaction - The decoded transaction\n * @returns The token payer address as a base58 string\n */\nexport function getTokenPayerFromTransaction(transaction: Transaction): string {\n const compiled = getCompiledTransactionMessageDecoder().decode(transaction.messageBytes);\n const staticAccounts = compiled.staticAccounts ?? [];\n const instructions = compiled.instructions ?? [];\n\n for (const ix of instructions) {\n const programIndex = ix.programAddressIndex;\n const programAddress = staticAccounts[programIndex].toString();\n\n // Check if this is a token program instruction\n if (\n programAddress === TOKEN_PROGRAM_ADDRESS.toString() ||\n programAddress === TOKEN_2022_PROGRAM_ADDRESS.toString()\n ) {\n const accountIndices: number[] = ix.accountIndices ?? [];\n // TransferChecked account order: [source, mint, destination, owner, ...]\n if (accountIndices.length >= 4) {\n const ownerIndex = accountIndices[3];\n const ownerAddress = staticAccounts[ownerIndex].toString();\n if (ownerAddress) return ownerAddress;\n }\n }\n }\n\n return \"\";\n}\n\n/**\n * Create an RPC client for the specified network\n *\n * @param network - Network identifier (CAIP-2 or V1 format)\n * @param customRpcUrl - Optional custom RPC URL\n * @returns RPC client for the specified network\n */\nexport function createRpcClient(\n network: Network,\n customRpcUrl?: string,\n):\n | RpcDevnet<SolanaRpcApiDevnet>\n | RpcTestnet<SolanaRpcApiTestnet>\n | RpcMainnet<SolanaRpcApiMainnet> {\n const caip2Network = normalizeNetwork(network);\n\n switch (caip2Network) {\n case SOLANA_DEVNET_CAIP2: {\n const url = customRpcUrl || DEVNET_RPC_URL;\n return createSolanaRpc(devnet(url)) as RpcDevnet<SolanaRpcApiDevnet>;\n }\n case SOLANA_TESTNET_CAIP2: {\n const url = customRpcUrl || TESTNET_RPC_URL;\n return createSolanaRpc(testnet(url)) as RpcTestnet<SolanaRpcApiTestnet>;\n }\n case SOLANA_MAINNET_CAIP2: {\n const url = customRpcUrl || MAINNET_RPC_URL;\n return createSolanaRpc(mainnet(url)) as RpcMainnet<SolanaRpcApiMainnet>;\n }\n default:\n throw new Error(`Unsupported network: ${network}`);\n }\n}\n\n/**\n * Get the default USDC mint address for a network\n *\n * @param network - Network identifier (CAIP-2 or V1 format)\n * @returns USDC mint address for the network\n */\nexport function getUsdcAddress(network: Network): string {\n const caip2Network = normalizeNetwork(network);\n\n switch (caip2Network) {\n case SOLANA_MAINNET_CAIP2:\n return USDC_MAINNET_ADDRESS;\n case SOLANA_DEVNET_CAIP2:\n return USDC_DEVNET_ADDRESS;\n case SOLANA_TESTNET_CAIP2:\n return USDC_TESTNET_ADDRESS;\n default:\n throw new Error(`No USDC address configured for network: ${network}`);\n }\n}\n\n/**\n * Convert a decimal amount to token smallest units\n *\n * @param decimalAmount - The decimal amount (e.g., \"0.10\")\n * @param decimals - The number of decimals for the token (e.g., 6 for USDC)\n * @returns The amount in smallest units as a string\n */\nexport function convertToTokenAmount(decimalAmount: string, decimals: number): string {\n const amount = parseFloat(decimalAmount);\n if (isNaN(amount)) {\n throw new Error(`Invalid amount: ${decimalAmount}`);\n }\n // Convert to smallest unit (e.g., for USDC with 6 decimals: 0.10 * 10^6 = 100000)\n const [intPart, decPart = \"\"] = String(amount).split(\".\");\n const paddedDec = decPart.padEnd(decimals, \"0\").slice(0, decimals);\n const tokenAmount = (intPart + paddedDec).replace(/^0+/, \"\") || \"0\";\n return tokenAmount;\n}\n"],"mappings":"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","names":["import_token","import_token_2022","import_kit","tx"]}
@@ -1,71 +0,0 @@
1
- import { SchemeNetworkFacilitator, PaymentPayload, PaymentRequirements, VerifyResponse, SettleResponse } from '@x402/core/types';
2
- import { F as FacilitatorSvmSigner } from '../../../signer-BMkbhFYE.js';
3
- import '@solana/kit';
4
-
5
- /**
6
- * SVM facilitator implementation for the Exact payment scheme (V1).
7
- */
8
- declare class ExactSvmSchemeV1 implements SchemeNetworkFacilitator {
9
- private readonly signer;
10
- readonly scheme = "exact";
11
- readonly caipFamily = "solana:*";
12
- /**
13
- * Creates a new ExactSvmFacilitatorV1 instance.
14
- *
15
- * @param signer - The SVM RPC client for facilitator operations
16
- * @returns ExactSvmFacilitatorV1 instance
17
- */
18
- constructor(signer: FacilitatorSvmSigner);
19
- /**
20
- * Get mechanism-specific extra data for the supported kinds endpoint.
21
- * For SVM, this includes a randomly selected fee payer address.
22
- * Random selection distributes load across multiple signers.
23
- *
24
- * @param _ - The network identifier (unused for SVM)
25
- * @returns Extra data with feePayer address
26
- */
27
- getExtra(_: string): Record<string, unknown> | undefined;
28
- /**
29
- * Get signer addresses used by this facilitator.
30
- * For SVM, returns all available fee payer addresses.
31
- *
32
- * @param _ - The network identifier (unused for SVM)
33
- * @returns Array of fee payer addresses
34
- */
35
- getSigners(_: string): string[];
36
- /**
37
- * Verifies a payment payload (V1).
38
- *
39
- * @param payload - The payment payload to verify
40
- * @param requirements - The payment requirements
41
- * @returns Promise resolving to verification response
42
- */
43
- verify(payload: PaymentPayload, requirements: PaymentRequirements): Promise<VerifyResponse>;
44
- /**
45
- * Settles a payment by submitting the transaction (V1).
46
- * Ensures the correct signer is used based on the feePayer specified in requirements.
47
- *
48
- * @param payload - The payment payload to settle
49
- * @param requirements - The payment requirements
50
- * @returns Promise resolving to settlement response
51
- */
52
- settle(payload: PaymentPayload, requirements: PaymentRequirements): Promise<SettleResponse>;
53
- /**
54
- * Verify compute limit instruction
55
- *
56
- * @param instruction - The compute limit instruction
57
- * @param instruction.programAddress - Program address
58
- * @param instruction.data - Instruction data bytes
59
- */
60
- private verifyComputeLimitInstruction;
61
- /**
62
- * Verify compute price instruction
63
- *
64
- * @param instruction - The compute price instruction
65
- * @param instruction.programAddress - Program address
66
- * @param instruction.data - Instruction data bytes
67
- */
68
- private verifyComputePriceInstruction;
69
- }
70
-
71
- export { ExactSvmSchemeV1 };
@@ -1,384 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/exact/v1/facilitator/index.ts
21
- var facilitator_exports = {};
22
- __export(facilitator_exports, {
23
- ExactSvmSchemeV1: () => ExactSvmSchemeV1
24
- });
25
- module.exports = __toCommonJS(facilitator_exports);
26
-
27
- // src/exact/v1/facilitator/scheme.ts
28
- var import_compute_budget = require("@solana-program/compute-budget");
29
- var import_token2 = require("@solana-program/token");
30
- var import_token_20222 = require("@solana-program/token-2022");
31
- var import_kit2 = require("@solana/kit");
32
-
33
- // src/constants.ts
34
- var MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS = 5e6;
35
-
36
- // src/utils.ts
37
- var import_kit = require("@solana/kit");
38
- var import_token = require("@solana-program/token");
39
- var import_token_2022 = require("@solana-program/token-2022");
40
- function decodeTransactionFromPayload(svmPayload) {
41
- try {
42
- const base64Encoder = (0, import_kit.getBase64Encoder)();
43
- const transactionBytes = base64Encoder.encode(svmPayload.transaction);
44
- const transactionDecoder = (0, import_kit.getTransactionDecoder)();
45
- return transactionDecoder.decode(transactionBytes);
46
- } catch (error) {
47
- console.error("Error decoding transaction:", error);
48
- throw new Error("invalid_exact_svm_payload_transaction");
49
- }
50
- }
51
- function getTokenPayerFromTransaction(transaction) {
52
- const compiled = (0, import_kit.getCompiledTransactionMessageDecoder)().decode(transaction.messageBytes);
53
- const staticAccounts = compiled.staticAccounts ?? [];
54
- const instructions = compiled.instructions ?? [];
55
- for (const ix of instructions) {
56
- const programIndex = ix.programAddressIndex;
57
- const programAddress = staticAccounts[programIndex].toString();
58
- if (programAddress === import_token.TOKEN_PROGRAM_ADDRESS.toString() || programAddress === import_token_2022.TOKEN_2022_PROGRAM_ADDRESS.toString()) {
59
- const accountIndices = ix.accountIndices ?? [];
60
- if (accountIndices.length >= 4) {
61
- const ownerIndex = accountIndices[3];
62
- const ownerAddress = staticAccounts[ownerIndex].toString();
63
- if (ownerAddress) return ownerAddress;
64
- }
65
- }
66
- }
67
- return "";
68
- }
69
-
70
- // src/exact/v1/facilitator/scheme.ts
71
- var ExactSvmSchemeV1 = class {
72
- /**
73
- * Creates a new ExactSvmFacilitatorV1 instance.
74
- *
75
- * @param signer - The SVM RPC client for facilitator operations
76
- * @returns ExactSvmFacilitatorV1 instance
77
- */
78
- constructor(signer) {
79
- this.signer = signer;
80
- this.scheme = "exact";
81
- this.caipFamily = "solana:*";
82
- }
83
- /**
84
- * Get mechanism-specific extra data for the supported kinds endpoint.
85
- * For SVM, this includes a randomly selected fee payer address.
86
- * Random selection distributes load across multiple signers.
87
- *
88
- * @param _ - The network identifier (unused for SVM)
89
- * @returns Extra data with feePayer address
90
- */
91
- getExtra(_) {
92
- const addresses = this.signer.getAddresses();
93
- const randomIndex = Math.floor(Math.random() * addresses.length);
94
- return {
95
- feePayer: addresses[randomIndex]
96
- };
97
- }
98
- /**
99
- * Get signer addresses used by this facilitator.
100
- * For SVM, returns all available fee payer addresses.
101
- *
102
- * @param _ - The network identifier (unused for SVM)
103
- * @returns Array of fee payer addresses
104
- */
105
- getSigners(_) {
106
- return [...this.signer.getAddresses()];
107
- }
108
- /**
109
- * Verifies a payment payload (V1).
110
- *
111
- * @param payload - The payment payload to verify
112
- * @param requirements - The payment requirements
113
- * @returns Promise resolving to verification response
114
- */
115
- async verify(payload, requirements) {
116
- const requirementsV1 = requirements;
117
- const payloadV1 = payload;
118
- const exactSvmPayload = payload.payload;
119
- if (payloadV1.scheme !== "exact" || requirements.scheme !== "exact") {
120
- return {
121
- isValid: false,
122
- invalidReason: "unsupported_scheme",
123
- payer: ""
124
- };
125
- }
126
- if (payloadV1.network !== requirements.network) {
127
- return {
128
- isValid: false,
129
- invalidReason: "network_mismatch",
130
- payer: ""
131
- };
132
- }
133
- if (!requirementsV1.extra?.feePayer || typeof requirementsV1.extra.feePayer !== "string") {
134
- return {
135
- isValid: false,
136
- invalidReason: "invalid_exact_svm_payload_missing_fee_payer",
137
- payer: ""
138
- };
139
- }
140
- const signerAddresses = this.signer.getAddresses().map((addr) => addr.toString());
141
- if (!signerAddresses.includes(requirementsV1.extra.feePayer)) {
142
- return {
143
- isValid: false,
144
- invalidReason: "fee_payer_not_managed_by_facilitator",
145
- payer: ""
146
- };
147
- }
148
- let transaction;
149
- try {
150
- transaction = decodeTransactionFromPayload(exactSvmPayload);
151
- } catch {
152
- return {
153
- isValid: false,
154
- invalidReason: "invalid_exact_svm_payload_transaction_could_not_be_decoded",
155
- payer: ""
156
- };
157
- }
158
- const compiled = (0, import_kit2.getCompiledTransactionMessageDecoder)().decode(transaction.messageBytes);
159
- const decompiled = (0, import_kit2.decompileTransactionMessage)(compiled);
160
- const instructions = decompiled.instructions ?? [];
161
- if (instructions.length !== 3) {
162
- return {
163
- isValid: false,
164
- invalidReason: "invalid_exact_svm_payload_transaction_instructions_length",
165
- payer: ""
166
- };
167
- }
168
- try {
169
- this.verifyComputeLimitInstruction(instructions[0]);
170
- this.verifyComputePriceInstruction(instructions[1]);
171
- } catch (error) {
172
- const errorMessage = error instanceof Error ? error.message : String(error);
173
- return {
174
- isValid: false,
175
- invalidReason: errorMessage,
176
- payer: ""
177
- };
178
- }
179
- const payer = getTokenPayerFromTransaction(transaction);
180
- if (!payer) {
181
- return {
182
- isValid: false,
183
- invalidReason: "invalid_exact_svm_payload_no_transfer_instruction",
184
- payer: ""
185
- };
186
- }
187
- const transferIx = instructions[2];
188
- const programAddress = transferIx.programAddress.toString();
189
- if (programAddress !== import_token2.TOKEN_PROGRAM_ADDRESS.toString() && programAddress !== import_token_20222.TOKEN_2022_PROGRAM_ADDRESS.toString()) {
190
- return {
191
- isValid: false,
192
- invalidReason: "invalid_exact_svm_payload_no_transfer_instruction",
193
- payer
194
- };
195
- }
196
- let parsedTransfer;
197
- try {
198
- if (programAddress === import_token2.TOKEN_PROGRAM_ADDRESS.toString()) {
199
- parsedTransfer = (0, import_token2.parseTransferCheckedInstruction)(transferIx);
200
- } else {
201
- parsedTransfer = (0, import_token_20222.parseTransferCheckedInstruction)(transferIx);
202
- }
203
- } catch {
204
- return {
205
- isValid: false,
206
- invalidReason: "invalid_exact_svm_payload_no_transfer_instruction",
207
- payer
208
- };
209
- }
210
- const authorityAddress = parsedTransfer.accounts.authority.address.toString();
211
- if (signerAddresses.includes(authorityAddress)) {
212
- return {
213
- isValid: false,
214
- invalidReason: "invalid_exact_svm_payload_transaction_fee_payer_transferring_funds",
215
- payer
216
- };
217
- }
218
- const mintAddress = parsedTransfer.accounts.mint.address.toString();
219
- if (mintAddress !== requirements.asset) {
220
- return {
221
- isValid: false,
222
- invalidReason: "invalid_exact_svm_payload_mint_mismatch",
223
- payer
224
- };
225
- }
226
- const destATA = parsedTransfer.accounts.destination.address.toString();
227
- try {
228
- const [expectedDestATA] = await (0, import_token_20222.findAssociatedTokenPda)({
229
- mint: requirements.asset,
230
- owner: requirements.payTo,
231
- tokenProgram: programAddress === import_token2.TOKEN_PROGRAM_ADDRESS.toString() ? import_token2.TOKEN_PROGRAM_ADDRESS : import_token_20222.TOKEN_2022_PROGRAM_ADDRESS
232
- });
233
- if (destATA !== expectedDestATA.toString()) {
234
- return {
235
- isValid: false,
236
- invalidReason: "invalid_exact_svm_payload_recipient_mismatch",
237
- payer
238
- };
239
- }
240
- } catch {
241
- return {
242
- isValid: false,
243
- invalidReason: "invalid_exact_svm_payload_recipient_mismatch",
244
- payer
245
- };
246
- }
247
- const amount = parsedTransfer.data.amount;
248
- if (amount < BigInt(requirementsV1.maxAmountRequired)) {
249
- return {
250
- isValid: false,
251
- invalidReason: "invalid_exact_svm_payload_amount_insufficient",
252
- payer
253
- };
254
- }
255
- try {
256
- const feePayer = requirementsV1.extra.feePayer;
257
- const fullySignedTransaction = await this.signer.signTransaction(
258
- exactSvmPayload.transaction,
259
- feePayer,
260
- requirements.network
261
- );
262
- await this.signer.simulateTransaction(fullySignedTransaction, requirements.network);
263
- } catch (error) {
264
- const errorMessage = error instanceof Error ? error.message : String(error);
265
- return {
266
- isValid: false,
267
- invalidReason: `transaction_simulation_failed: ${errorMessage}`,
268
- payer
269
- };
270
- }
271
- return {
272
- isValid: true,
273
- invalidReason: void 0,
274
- payer
275
- };
276
- }
277
- /**
278
- * Settles a payment by submitting the transaction (V1).
279
- * Ensures the correct signer is used based on the feePayer specified in requirements.
280
- *
281
- * @param payload - The payment payload to settle
282
- * @param requirements - The payment requirements
283
- * @returns Promise resolving to settlement response
284
- */
285
- async settle(payload, requirements) {
286
- const payloadV1 = payload;
287
- const exactSvmPayload = payload.payload;
288
- const valid = await this.verify(payload, requirements);
289
- if (!valid.isValid) {
290
- return {
291
- success: false,
292
- network: payloadV1.network,
293
- transaction: "",
294
- errorReason: valid.invalidReason ?? "verification_failed",
295
- payer: valid.payer || ""
296
- };
297
- }
298
- try {
299
- const feePayer = requirements.extra.feePayer;
300
- const fullySignedTransaction = await this.signer.signTransaction(
301
- exactSvmPayload.transaction,
302
- feePayer,
303
- requirements.network
304
- );
305
- const signature = await this.signer.sendTransaction(
306
- fullySignedTransaction,
307
- requirements.network
308
- );
309
- await this.signer.confirmTransaction(signature, requirements.network);
310
- return {
311
- success: true,
312
- transaction: signature,
313
- network: payloadV1.network,
314
- payer: valid.payer
315
- };
316
- } catch (error) {
317
- console.error("Failed to settle transaction:", error);
318
- return {
319
- success: false,
320
- errorReason: "transaction_failed",
321
- transaction: "",
322
- network: payloadV1.network,
323
- payer: valid.payer || ""
324
- };
325
- }
326
- }
327
- /**
328
- * Verify compute limit instruction
329
- *
330
- * @param instruction - The compute limit instruction
331
- * @param instruction.programAddress - Program address
332
- * @param instruction.data - Instruction data bytes
333
- */
334
- verifyComputeLimitInstruction(instruction) {
335
- const programAddress = instruction.programAddress.toString();
336
- if (programAddress !== import_compute_budget.COMPUTE_BUDGET_PROGRAM_ADDRESS.toString() || !instruction.data || instruction.data[0] !== 2) {
337
- throw new Error(
338
- "invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction"
339
- );
340
- }
341
- try {
342
- (0, import_compute_budget.parseSetComputeUnitLimitInstruction)(instruction);
343
- } catch {
344
- throw new Error(
345
- "invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction"
346
- );
347
- }
348
- }
349
- /**
350
- * Verify compute price instruction
351
- *
352
- * @param instruction - The compute price instruction
353
- * @param instruction.programAddress - Program address
354
- * @param instruction.data - Instruction data bytes
355
- */
356
- verifyComputePriceInstruction(instruction) {
357
- const programAddress = instruction.programAddress.toString();
358
- if (programAddress !== import_compute_budget.COMPUTE_BUDGET_PROGRAM_ADDRESS.toString() || !instruction.data || instruction.data[0] !== 3) {
359
- throw new Error(
360
- "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction"
361
- );
362
- }
363
- try {
364
- const parsedInstruction = (0, import_compute_budget.parseSetComputeUnitPriceInstruction)(instruction);
365
- if (parsedInstruction.microLamports > BigInt(MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS)) {
366
- throw new Error(
367
- "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction_too_high"
368
- );
369
- }
370
- } catch (error) {
371
- if (error instanceof Error && error.message.includes("too_high")) {
372
- throw error;
373
- }
374
- throw new Error(
375
- "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction"
376
- );
377
- }
378
- }
379
- };
380
- // Annotate the CommonJS export names for ESM import in node:
381
- 0 && (module.exports = {
382
- ExactSvmSchemeV1
383
- });
384
- //# sourceMappingURL=index.js.map