@x402/aptos 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +74 -0
- package/dist/cjs/exact/client/index.d.ts +29 -0
- package/dist/cjs/exact/client/index.js +141 -0
- package/dist/cjs/exact/client/index.js.map +1 -0
- package/dist/cjs/exact/facilitator/index.d.ts +52 -0
- package/dist/cjs/exact/facilitator/index.js +373 -0
- package/dist/cjs/exact/facilitator/index.js.map +1 -0
- package/dist/cjs/exact/server/index.d.ts +67 -0
- package/dist/cjs/exact/server/index.js +143 -0
- package/dist/cjs/exact/server/index.js.map +1 -0
- package/dist/cjs/index.d.ts +116 -0
- package/dist/cjs/index.js +269 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/signer-DPT9P1NX.d.ts +59 -0
- package/dist/cjs/signer-DfwN1I5I.d.ts +59 -0
- package/dist/esm/chunk-6BMAMLXJ.mjs +93 -0
- package/dist/esm/chunk-6BMAMLXJ.mjs.map +1 -0
- package/dist/esm/chunk-D4UVBSUH.mjs +53 -0
- package/dist/esm/chunk-D4UVBSUH.mjs.map +1 -0
- package/dist/esm/chunk-FG4ANPDN.mjs +46 -0
- package/dist/esm/chunk-FG4ANPDN.mjs.map +1 -0
- package/dist/esm/exact/client/index.d.mts +29 -0
- package/dist/esm/exact/client/index.mjs +9 -0
- package/dist/esm/exact/client/index.mjs.map +1 -0
- package/dist/esm/exact/facilitator/index.d.mts +52 -0
- package/dist/esm/exact/facilitator/index.mjs +294 -0
- package/dist/esm/exact/facilitator/index.mjs.map +1 -0
- package/dist/esm/exact/server/index.d.mts +67 -0
- package/dist/esm/exact/server/index.mjs +116 -0
- package/dist/esm/exact/server/index.mjs.map +1 -0
- package/dist/esm/index.d.mts +116 -0
- package/dist/esm/index.mjs +105 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/signer-DPT9P1NX.d.mts +59 -0
- package/package.json +95 -0
package/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# @x402/aptos
|
|
2
|
+
|
|
3
|
+
Aptos implementation of the x402 payment protocol.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @x402/aptos
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @x402/aptos
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### Client
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { Account, Ed25519PrivateKey } from "@aptos-labs/ts-sdk";
|
|
19
|
+
import { ExactAptosScheme } from "@x402/aptos/exact/client";
|
|
20
|
+
|
|
21
|
+
// Create signer from private key
|
|
22
|
+
const privateKey = new Ed25519PrivateKey("0x...");
|
|
23
|
+
const account = Account.fromPrivateKey({ privateKey });
|
|
24
|
+
|
|
25
|
+
// Register scheme with client
|
|
26
|
+
client.register("aptos:*", new ExactAptosScheme(account));
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Facilitator
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { Account, Ed25519PrivateKey } from "@aptos-labs/ts-sdk";
|
|
33
|
+
import { ExactAptosScheme } from "@x402/aptos/exact/facilitator";
|
|
34
|
+
import { toFacilitatorAptosSigner } from "@x402/aptos";
|
|
35
|
+
|
|
36
|
+
// Create facilitator signer
|
|
37
|
+
const privateKey = new Ed25519PrivateKey("0x...");
|
|
38
|
+
const account = Account.fromPrivateKey({ privateKey });
|
|
39
|
+
const signer = toFacilitatorAptosSigner(account);
|
|
40
|
+
|
|
41
|
+
// Register scheme with facilitator
|
|
42
|
+
facilitator.register("aptos:2", new ExactAptosScheme(signer));
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Server
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { x402ResourceServer } from "@x402/core/server";
|
|
49
|
+
import { ExactAptosScheme } from "@x402/aptos/exact/server";
|
|
50
|
+
|
|
51
|
+
// Create and configure server
|
|
52
|
+
const server = new x402ResourceServer({ facilitatorUrl: "https://..." });
|
|
53
|
+
server.register("aptos:*", new ExactAptosScheme());
|
|
54
|
+
|
|
55
|
+
// Use parsePrice to convert amounts (e.g., "$1.00" or { amount: "1000000", asset: "0x..." })
|
|
56
|
+
// The scheme handles USDC conversion automatically
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Features
|
|
60
|
+
|
|
61
|
+
- **Sponsored Transactions**: Facilitators can pay gas fees on behalf of clients
|
|
62
|
+
- **Fungible Asset Transfers**: Uses Aptos's native `primary_fungible_store::transfer`
|
|
63
|
+
- **Network Support**: Mainnet (`aptos:1`) and Testnet (`aptos:2`)
|
|
64
|
+
|
|
65
|
+
## Testnet Resources
|
|
66
|
+
|
|
67
|
+
For testing on Aptos testnet, you can obtain test tokens from these faucets:
|
|
68
|
+
|
|
69
|
+
- **Test APT**: https://aptos.dev/network/faucet or through an account on [geomi.dev](https://geomi.dev/manage/faucet)
|
|
70
|
+
- **Test USDC**: https://faucet.circle.com/
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
Apache-2.0
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { SchemeNetworkClient, PaymentRequirements, PaymentPayload } from '@x402/core/types';
|
|
2
|
+
import { a as ClientAptosSigner, C as ClientAptosConfig } from '../../signer-DPT9P1NX.js';
|
|
3
|
+
import '@aptos-labs/ts-sdk';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Aptos client implementation for the Exact payment scheme.
|
|
7
|
+
*/
|
|
8
|
+
declare class ExactAptosScheme implements SchemeNetworkClient {
|
|
9
|
+
private readonly signer;
|
|
10
|
+
private readonly config?;
|
|
11
|
+
readonly scheme = "exact";
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new ExactAptosScheme instance.
|
|
14
|
+
*
|
|
15
|
+
* @param signer - The Aptos account for signing transactions
|
|
16
|
+
* @param config - Optional configuration with custom RPC URL
|
|
17
|
+
*/
|
|
18
|
+
constructor(signer: ClientAptosSigner, config?: ClientAptosConfig | undefined);
|
|
19
|
+
/**
|
|
20
|
+
* Creates a payment payload for the Exact scheme.
|
|
21
|
+
*
|
|
22
|
+
* @param x402Version - The x402 protocol version
|
|
23
|
+
* @param paymentRequirements - The payment requirements
|
|
24
|
+
* @returns Promise resolving to a payment payload
|
|
25
|
+
*/
|
|
26
|
+
createPaymentPayload(x402Version: number, paymentRequirements: PaymentRequirements): Promise<Pick<PaymentPayload, "x402Version" | "payload">>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { ExactAptosScheme };
|
|
@@ -0,0 +1,141 @@
|
|
|
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/client/index.ts
|
|
21
|
+
var client_exports = {};
|
|
22
|
+
__export(client_exports, {
|
|
23
|
+
ExactAptosScheme: () => ExactAptosScheme
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(client_exports);
|
|
26
|
+
|
|
27
|
+
// src/exact/client/scheme.ts
|
|
28
|
+
var import_ts_sdk3 = require("@aptos-labs/ts-sdk");
|
|
29
|
+
|
|
30
|
+
// src/constants.ts
|
|
31
|
+
var import_ts_sdk = require("@aptos-labs/ts-sdk");
|
|
32
|
+
var APTOS_MAINNET_CAIP2 = "aptos:1";
|
|
33
|
+
var APTOS_TESTNET_CAIP2 = "aptos:2";
|
|
34
|
+
var APTOS_ADDRESS_REGEX = /^0x[a-fA-F0-9]{64}$/;
|
|
35
|
+
function getAptosNetwork(network) {
|
|
36
|
+
switch (network) {
|
|
37
|
+
case APTOS_MAINNET_CAIP2:
|
|
38
|
+
return import_ts_sdk.Network.MAINNET;
|
|
39
|
+
case APTOS_TESTNET_CAIP2:
|
|
40
|
+
return import_ts_sdk.Network.TESTNET;
|
|
41
|
+
default:
|
|
42
|
+
throw new Error(`Unsupported Aptos network: ${network}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function getAptosRpcUrl(network) {
|
|
46
|
+
return import_ts_sdk.NetworkToNodeAPI[network];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/utils.ts
|
|
50
|
+
var import_ts_sdk2 = require("@aptos-labs/ts-sdk");
|
|
51
|
+
function encodeAptosPayload(transactionBytes, authenticatorBytes) {
|
|
52
|
+
const payload = {
|
|
53
|
+
transaction: Array.from(transactionBytes),
|
|
54
|
+
senderAuthenticator: Array.from(authenticatorBytes)
|
|
55
|
+
};
|
|
56
|
+
return Buffer.from(JSON.stringify(payload)).toString("base64");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/exact/client/scheme.ts
|
|
60
|
+
var ExactAptosScheme = class {
|
|
61
|
+
/**
|
|
62
|
+
* Creates a new ExactAptosScheme instance.
|
|
63
|
+
*
|
|
64
|
+
* @param signer - The Aptos account for signing transactions
|
|
65
|
+
* @param config - Optional configuration with custom RPC URL
|
|
66
|
+
*/
|
|
67
|
+
constructor(signer, config) {
|
|
68
|
+
this.signer = signer;
|
|
69
|
+
this.config = config;
|
|
70
|
+
this.scheme = "exact";
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Creates a payment payload for the Exact scheme.
|
|
74
|
+
*
|
|
75
|
+
* @param x402Version - The x402 protocol version
|
|
76
|
+
* @param paymentRequirements - The payment requirements
|
|
77
|
+
* @returns Promise resolving to a payment payload
|
|
78
|
+
*/
|
|
79
|
+
async createPaymentPayload(x402Version, paymentRequirements) {
|
|
80
|
+
if (!this.signer.accountAddress) {
|
|
81
|
+
throw new Error("Aptos account address is required");
|
|
82
|
+
}
|
|
83
|
+
if (!paymentRequirements.asset) {
|
|
84
|
+
throw new Error("Asset is required");
|
|
85
|
+
}
|
|
86
|
+
if (!paymentRequirements.asset.match(APTOS_ADDRESS_REGEX)) {
|
|
87
|
+
throw new Error("Invalid asset address");
|
|
88
|
+
}
|
|
89
|
+
if (!paymentRequirements.payTo) {
|
|
90
|
+
throw new Error("Pay-to address is required");
|
|
91
|
+
}
|
|
92
|
+
if (!paymentRequirements.payTo.match(APTOS_ADDRESS_REGEX)) {
|
|
93
|
+
throw new Error("Invalid pay-to address");
|
|
94
|
+
}
|
|
95
|
+
if (!paymentRequirements.amount) {
|
|
96
|
+
throw new Error("Amount is required");
|
|
97
|
+
}
|
|
98
|
+
if (!paymentRequirements.amount.match(/^[0-9]+$/)) {
|
|
99
|
+
throw new Error("Amount must be a number");
|
|
100
|
+
}
|
|
101
|
+
const aptosNetwork = getAptosNetwork(paymentRequirements.network);
|
|
102
|
+
const rpcUrl = this.config?.rpcUrl || getAptosRpcUrl(aptosNetwork);
|
|
103
|
+
const aptosConfig = new import_ts_sdk3.AptosConfig({
|
|
104
|
+
network: aptosNetwork,
|
|
105
|
+
fullnode: rpcUrl
|
|
106
|
+
});
|
|
107
|
+
const aptos = new import_ts_sdk3.Aptos(aptosConfig);
|
|
108
|
+
const feePayer = paymentRequirements.extra?.feePayer;
|
|
109
|
+
const isSponsored = typeof feePayer === "string";
|
|
110
|
+
const builtTransaction = await aptos.transaction.build.simple({
|
|
111
|
+
sender: this.signer.accountAddress,
|
|
112
|
+
data: {
|
|
113
|
+
function: "0x1::primary_fungible_store::transfer",
|
|
114
|
+
typeArguments: ["0x1::fungible_asset::Metadata"],
|
|
115
|
+
functionArguments: [
|
|
116
|
+
paymentRequirements.asset,
|
|
117
|
+
paymentRequirements.payTo,
|
|
118
|
+
paymentRequirements.amount
|
|
119
|
+
]
|
|
120
|
+
},
|
|
121
|
+
withFeePayer: isSponsored
|
|
122
|
+
});
|
|
123
|
+
const transaction = isSponsored ? new import_ts_sdk3.SimpleTransaction(builtTransaction.rawTransaction, import_ts_sdk3.AccountAddress.from(feePayer)) : builtTransaction;
|
|
124
|
+
const senderAuthenticator = this.signer.signTransactionWithAuthenticator(transaction);
|
|
125
|
+
const transactionBytes = transaction.bcsToBytes();
|
|
126
|
+
const authenticatorBytes = senderAuthenticator.bcsToBytes();
|
|
127
|
+
const base64Transaction = encodeAptosPayload(transactionBytes, authenticatorBytes);
|
|
128
|
+
const payload = {
|
|
129
|
+
transaction: base64Transaction
|
|
130
|
+
};
|
|
131
|
+
return {
|
|
132
|
+
x402Version,
|
|
133
|
+
payload
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
138
|
+
0 && (module.exports = {
|
|
139
|
+
ExactAptosScheme
|
|
140
|
+
});
|
|
141
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/exact/client/index.ts","../../../../src/exact/client/scheme.ts","../../../../src/constants.ts","../../../../src/utils.ts"],"sourcesContent":["export { ExactAptosScheme } from \"./scheme\";\n","import { AccountAddress, Aptos, AptosConfig, SimpleTransaction } from \"@aptos-labs/ts-sdk\";\nimport type { PaymentPayload, PaymentRequirements, SchemeNetworkClient } from \"@x402/core/types\";\nimport { APTOS_ADDRESS_REGEX, getAptosNetwork, getAptosRpcUrl } from \"../../constants\";\nimport type { ClientAptosSigner, ClientAptosConfig } from \"../../signer\";\nimport type { ExactAptosPayload } from \"../../types\";\nimport { encodeAptosPayload } from \"../../utils\";\n\n/**\n * Aptos client implementation for the Exact payment scheme.\n */\nexport class ExactAptosScheme implements SchemeNetworkClient {\n readonly scheme = \"exact\";\n\n /**\n * Creates a new ExactAptosScheme instance.\n *\n * @param signer - The Aptos account for signing transactions\n * @param config - Optional configuration with custom RPC URL\n */\n constructor(\n private readonly signer: ClientAptosSigner,\n private readonly config?: ClientAptosConfig,\n ) {}\n\n /**\n * Creates a payment payload for the Exact scheme.\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<Pick<PaymentPayload, \"x402Version\" | \"payload\">> {\n if (!this.signer.accountAddress) {\n throw new Error(\"Aptos account address is required\");\n }\n if (!paymentRequirements.asset) {\n throw new Error(\"Asset is required\");\n }\n if (!paymentRequirements.asset.match(APTOS_ADDRESS_REGEX)) {\n throw new Error(\"Invalid asset address\");\n }\n if (!paymentRequirements.payTo) {\n throw new Error(\"Pay-to address is required\");\n }\n if (!paymentRequirements.payTo.match(APTOS_ADDRESS_REGEX)) {\n throw new Error(\"Invalid pay-to address\");\n }\n if (!paymentRequirements.amount) {\n throw new Error(\"Amount is required\");\n }\n if (!paymentRequirements.amount.match(/^[0-9]+$/)) {\n throw new Error(\"Amount must be a number\");\n }\n\n const aptosNetwork = getAptosNetwork(paymentRequirements.network);\n const rpcUrl = this.config?.rpcUrl || getAptosRpcUrl(aptosNetwork);\n const aptosConfig = new AptosConfig({\n network: aptosNetwork,\n fullnode: rpcUrl,\n });\n const aptos = new Aptos(aptosConfig);\n\n const feePayer = paymentRequirements.extra?.feePayer;\n const isSponsored = typeof feePayer === \"string\";\n\n const builtTransaction = await aptos.transaction.build.simple({\n sender: this.signer.accountAddress,\n data: {\n function: \"0x1::primary_fungible_store::transfer\",\n typeArguments: [\"0x1::fungible_asset::Metadata\"],\n functionArguments: [\n paymentRequirements.asset,\n paymentRequirements.payTo,\n paymentRequirements.amount,\n ],\n },\n withFeePayer: isSponsored,\n });\n\n // For sponsored transactions, set the actual fee payer address (SDK uses 0x0 placeholder)\n const transaction = isSponsored\n ? new SimpleTransaction(builtTransaction.rawTransaction, AccountAddress.from(feePayer))\n : builtTransaction;\n\n const senderAuthenticator = this.signer.signTransactionWithAuthenticator(transaction);\n const transactionBytes = transaction.bcsToBytes();\n const authenticatorBytes = senderAuthenticator.bcsToBytes();\n const base64Transaction = encodeAptosPayload(transactionBytes, authenticatorBytes);\n\n const payload: ExactAptosPayload = {\n transaction: base64Transaction,\n };\n\n return {\n x402Version,\n payload,\n };\n }\n}\n","import { Network, NetworkToNodeAPI } from \"@aptos-labs/ts-sdk\";\n\n/**\n * CAIP-2 network identifier for Aptos Mainnet\n */\nexport const APTOS_MAINNET_CAIP2 = \"aptos:1\";\n\n/**\n * CAIP-2 network identifier for Aptos Testnet\n */\nexport const APTOS_TESTNET_CAIP2 = \"aptos:2\";\n\n/**\n * Regex pattern for validating Aptos addresses\n * Matches 64 hex characters with 0x prefix\n */\nexport const APTOS_ADDRESS_REGEX = /^0x[a-fA-F0-9]{64}$/;\n\n/**\n * The primary fungible store transfer function\n */\nexport const TRANSFER_FUNCTION = \"0x1::primary_fungible_store::transfer\";\n\n/**\n * Maximum gas amount allowed for sponsored transactions to prevent gas draining attacks.\n * The Aptos SDK defaults to 200000 for simple transactions, so we allow some headroom.\n */\nexport const MAX_GAS_AMOUNT = 500000n;\n\n/**\n * Maps CAIP-2 network identifiers to Aptos chain IDs.\n *\n * @param network - The CAIP-2 network identifier (e.g., \"aptos:1\")\n * @returns The corresponding chain ID\n */\nexport function getAptosChainId(network: string): number {\n switch (network) {\n case APTOS_MAINNET_CAIP2:\n return 1;\n case APTOS_TESTNET_CAIP2:\n return 2;\n default:\n throw new Error(`Unsupported Aptos network: ${network}`);\n }\n}\n\n/**\n * Default USDC fungible asset metadata address on mainnet.\n */\nexport const USDC_MAINNET_FA = \"0xbae207659db88bea0cbead6da0ed00aac12edcdda169e591cd41c94180b46f3b\";\n\n/**\n * Default USDC fungible asset metadata address on testnet.\n */\nexport const USDC_TESTNET_FA = \"0x69091fbab5f7d635ee7ac5098cf0c1efbe31d68fec0f2cd565e8d168daf52832\";\n\n/**\n * Maps CAIP-2 network identifiers to Aptos SDK Network enum.\n *\n * @param network - The CAIP-2 network identifier (e.g., \"aptos:1\")\n * @returns The corresponding Aptos SDK Network enum value\n */\nexport function getAptosNetwork(network: string): Network {\n switch (network) {\n case APTOS_MAINNET_CAIP2:\n return Network.MAINNET;\n case APTOS_TESTNET_CAIP2:\n return Network.TESTNET;\n default:\n throw new Error(`Unsupported Aptos network: ${network}`);\n }\n}\n\n/**\n * Gets the default RPC URL for the given Aptos network.\n *\n * @param network - The Aptos SDK Network enum value\n * @returns The default RPC URL for the network\n */\nexport function getAptosRpcUrl(network: Network): string {\n return NetworkToNodeAPI[network];\n}\n","import {\n Deserializer,\n SimpleTransaction,\n AccountAuthenticator,\n TransactionPayloadEntryFunction,\n TransactionPayload,\n EntryFunction,\n Aptos,\n AptosConfig,\n} from \"@aptos-labs/ts-sdk\";\nimport type { DecodedAptosPayload } from \"./types\";\nimport { getAptosNetwork, getAptosRpcUrl } from \"./constants\";\n\n/**\n * Deserialize an Aptos transaction and authenticator from the payment payload.\n *\n * @param transactionBase64 - The base64 encoded transaction payload\n * @returns The deserialized transaction and authenticator\n */\nexport function deserializeAptosPayment(transactionBase64: string): {\n transaction: SimpleTransaction;\n senderAuthenticator: AccountAuthenticator;\n entryFunction?: EntryFunction;\n} {\n // Decode the base64 payload\n const decoded = Buffer.from(transactionBase64, \"base64\").toString(\"utf8\");\n const parsed: DecodedAptosPayload = JSON.parse(decoded);\n\n // Deserialize the transaction bytes\n const transactionBytes = Uint8Array.from(parsed.transaction);\n const transaction = SimpleTransaction.deserialize(new Deserializer(transactionBytes));\n\n // Deserialize the authenticator bytes\n const authBytes = Uint8Array.from(parsed.senderAuthenticator);\n const senderAuthenticator = AccountAuthenticator.deserialize(new Deserializer(authBytes));\n\n // Only Entry Function transactions are supported\n if (!isEntryFunctionPayload(transaction.rawTransaction.payload)) {\n return { transaction, senderAuthenticator };\n }\n\n const entryFunction = transaction.rawTransaction.payload.entryFunction;\n\n return { transaction, senderAuthenticator, entryFunction };\n}\n\n/**\n * Checks if it's an entry function payload.\n *\n * @param payload - The payload to check\n * @returns True if it's an entry function payload\n */\nexport function isEntryFunctionPayload(\n payload: TransactionPayload,\n): payload is TransactionPayloadEntryFunction {\n return \"entryFunction\" in payload;\n}\n\n/**\n * Create an Aptos SDK client for the given network\n *\n * @param network - CAIP-2 network identifier (e.g., \"aptos:1\")\n * @param rpcUrl - Optional custom RPC URL\n * @returns Aptos SDK client\n */\nexport function createAptosClient(network: string, rpcUrl?: string): Aptos {\n const aptosNetwork = getAptosNetwork(network);\n const fullnodeUrl = rpcUrl || getAptosRpcUrl(aptosNetwork);\n\n const config = new AptosConfig({\n network: aptosNetwork,\n fullnode: fullnodeUrl,\n });\n\n return new Aptos(config);\n}\n\n/**\n * Encode an Aptos payment payload to base64\n *\n * @param transactionBytes - The serialized transaction bytes\n * @param authenticatorBytes - The serialized authenticator bytes\n * @returns Base64 encoded payload\n */\nexport function encodeAptosPayload(\n transactionBytes: Uint8Array,\n authenticatorBytes: Uint8Array,\n): string {\n const payload: DecodedAptosPayload = {\n transaction: Array.from(transactionBytes),\n senderAuthenticator: Array.from(authenticatorBytes),\n };\n return Buffer.from(JSON.stringify(payload)).toString(\"base64\");\n}\n"],"mappings":"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","names":["import_ts_sdk","import_ts_sdk"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { SchemeNetworkFacilitator, PaymentPayload, PaymentRequirements, VerifyResponse, SettleResponse } from '@x402/core/types';
|
|
2
|
+
import { F as FacilitatorAptosSigner } from '../../signer-DPT9P1NX.js';
|
|
3
|
+
import '@aptos-labs/ts-sdk';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Aptos facilitator implementation for the Exact payment scheme.
|
|
7
|
+
*/
|
|
8
|
+
declare class ExactAptosScheme implements SchemeNetworkFacilitator {
|
|
9
|
+
private readonly signer;
|
|
10
|
+
private readonly sponsorTransactions;
|
|
11
|
+
readonly scheme = "exact";
|
|
12
|
+
readonly caipFamily = "aptos:*";
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new ExactAptosFacilitator instance.
|
|
15
|
+
*
|
|
16
|
+
* @param signer - The Aptos facilitator signer for transaction submission
|
|
17
|
+
* @param sponsorTransactions - Whether to sponsor transactions (pay gas fees). Defaults to true.
|
|
18
|
+
*/
|
|
19
|
+
constructor(signer: FacilitatorAptosSigner, sponsorTransactions?: boolean);
|
|
20
|
+
/**
|
|
21
|
+
* Get mechanism-specific extra data for the supported kinds endpoint.
|
|
22
|
+
*
|
|
23
|
+
* @param _ - The network identifier (unused)
|
|
24
|
+
* @returns Extra data with fee payer address, or undefined if sponsorship is disabled
|
|
25
|
+
*/
|
|
26
|
+
getExtra(_: string): Record<string, unknown> | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Get signer addresses used by this facilitator.
|
|
29
|
+
*
|
|
30
|
+
* @param _ - The network identifier (unused)
|
|
31
|
+
* @returns Array of fee payer addresses
|
|
32
|
+
*/
|
|
33
|
+
getSigners(_: string): string[];
|
|
34
|
+
/**
|
|
35
|
+
* Verifies a payment payload.
|
|
36
|
+
*
|
|
37
|
+
* @param payload - The payment payload to verify
|
|
38
|
+
* @param requirements - The payment requirements
|
|
39
|
+
* @returns Promise resolving to verification response
|
|
40
|
+
*/
|
|
41
|
+
verify(payload: PaymentPayload, requirements: PaymentRequirements): Promise<VerifyResponse>;
|
|
42
|
+
/**
|
|
43
|
+
* Settles a payment by submitting the transaction.
|
|
44
|
+
*
|
|
45
|
+
* @param payload - The payment payload to settle
|
|
46
|
+
* @param requirements - The payment requirements
|
|
47
|
+
* @returns Promise resolving to settlement response
|
|
48
|
+
*/
|
|
49
|
+
settle(payload: PaymentPayload, requirements: PaymentRequirements): Promise<SettleResponse>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { ExactAptosScheme };
|