@lunora/x402 1.0.0-alpha.4 → 1.0.0-alpha.41
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/LICENSE.md +18 -0
- package/README.md +18 -0
- package/dist/charge/index.d.mts +155 -95
- package/dist/charge/index.d.ts +155 -95
- package/dist/charge/index.mjs +1 -7
- package/dist/index.d.mts +2 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.mjs +1 -2
- package/dist/packem_shared/DEFAULT_ALLOWED_ASSETS-hq1xeZL6.mjs +1 -0
- package/dist/packem_shared/DEFAULT_FACILITATOR_URL-CPJNUMvi.mjs +1 -0
- package/dist/packem_shared/EVM_NETWORKS-C5yyzK27.mjs +1 -0
- package/dist/packem_shared/createChargeMiddleware-CURPSr23.mjs +1 -0
- package/dist/packem_shared/createFacilitatorClient-piLSnKs5.mjs +1 -0
- package/dist/packem_shared/createPayFetch-lyg7i3Js.mjs +1 -0
- package/dist/packem_shared/createProcedureChargeGate-Ki_K8dQE.mjs +1 -0
- package/dist/packem_shared/index.d-CzQaqaP6.d.mts +533 -0
- package/dist/packem_shared/index.d-CzQaqaP6.d.ts +533 -0
- package/dist/packem_shared/optional-peer-BBhVxozi.mjs +1 -0
- package/dist/packem_shared/registerWallet-DvCt0Q7M.mjs +1 -0
- package/dist/packem_shared/toPaymentEventRow-DTXuTDh0.mjs +1 -0
- package/dist/packem_shared/withX402-CJcBVHdI.mjs +1 -0
- package/dist/pay/index.d.mts +61 -61
- package/dist/pay/index.d.ts +61 -61
- package/dist/pay/index.mjs +1 -21
- package/package.json +21 -9
- package/dist/packem_shared/DEFAULT_FACILITATOR_URL-Cbz6kIqa.mjs +0 -4
- package/dist/packem_shared/DEFAULT_STABLECOIN_DECIMALS-CpW619nu.mjs +0 -90
- package/dist/packem_shared/EVM_NETWORKS-BhnYWUQ4.mjs +0 -26
- package/dist/packem_shared/config.d-5Nqi5iox.d.mts +0 -404
- package/dist/packem_shared/config.d-5Nqi5iox.d.ts +0 -404
- package/dist/packem_shared/createChargeMiddleware-D3yhOpFs.mjs +0 -162
- package/dist/packem_shared/createFacilitatorClient-rXHBnCZm.mjs +0 -16
- package/dist/packem_shared/createPayFetch-BeT05njL.mjs +0 -17
- package/dist/packem_shared/createProcedureChargeGate-eh9yv36U.mjs +0 -21
- package/dist/packem_shared/registerWallet-I4pVwq65.mjs +0 -109
- package/dist/packem_shared/toPaymentEventRow-DW4O9N7Y.mjs +0 -22
- package/dist/packem_shared/withX402-DILL2DvD.mjs +0 -15
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { LunoraError } from '@lunora/errors';
|
|
2
|
-
import { toCaip2, isEvmNetwork } from './EVM_NETWORKS-BhnYWUQ4.mjs';
|
|
3
|
-
|
|
4
|
-
const HEX_PRIVATE_KEY = /^0x[0-9a-fA-F]{64}$/;
|
|
5
|
-
const requireSecret = async (getSecret, name) => {
|
|
6
|
-
const value = await getSecret(name);
|
|
7
|
-
if (value === void 0 || value.length === 0) {
|
|
8
|
-
throw new LunoraError("ENV_INVALID", `x402 pay: secret "${name}" is not set — the agent wallet has no key to sign with.`);
|
|
9
|
-
}
|
|
10
|
-
return value;
|
|
11
|
-
};
|
|
12
|
-
const assertSignerFamily = (signer, evm) => {
|
|
13
|
-
const looksEvm = signer.address.startsWith("0x");
|
|
14
|
-
if (evm && !looksEvm) {
|
|
15
|
-
throw new LunoraError("ENV_INVALID", `x402 pay: the supplied signer address "${signer.address}" is not an EVM (0x…) address, but the network is EVM.`);
|
|
16
|
-
}
|
|
17
|
-
if (!evm && looksEvm) {
|
|
18
|
-
throw new LunoraError("ENV_INVALID", `x402 pay: the supplied signer address "${signer.address}" is an EVM (0x…) address, but the network is Solana.`);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
const resolveCdpEvmAccount = async (signer, getSecret) => {
|
|
22
|
-
let cdpModule;
|
|
23
|
-
try {
|
|
24
|
-
cdpModule = await import('@coinbase/cdp-sdk');
|
|
25
|
-
} catch {
|
|
26
|
-
throw new LunoraError(
|
|
27
|
-
"ENV_INVALID",
|
|
28
|
-
'x402 pay: CDP-managed custody needs the optional @coinbase/cdp-sdk peer — install it, or use "raw-key"/"signer" custody instead.'
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
const [apiKeyId, apiKeySecret, walletSecret] = await Promise.all([
|
|
32
|
-
requireSecret(getSecret, signer.apiKeyIdSecretName ?? "CDP_API_KEY_ID"),
|
|
33
|
-
requireSecret(getSecret, signer.apiKeySecretName ?? "CDP_API_KEY_SECRET"),
|
|
34
|
-
requireSecret(getSecret, signer.walletSecretName ?? "CDP_WALLET_SECRET")
|
|
35
|
-
]);
|
|
36
|
-
const cdp = new cdpModule.CdpClient({ apiKeyId, apiKeySecret, walletSecret });
|
|
37
|
-
return cdp.evm.getOrCreateAccount({ name: signer.account });
|
|
38
|
-
};
|
|
39
|
-
const resolveEvmAccount = async (privateKey) => {
|
|
40
|
-
const key = privateKey.startsWith("0x") ? privateKey : `0x${privateKey}`;
|
|
41
|
-
if (!HEX_PRIVATE_KEY.test(key)) {
|
|
42
|
-
throw new LunoraError("ENV_INVALID", "x402 pay: the EVM wallet key must be a 32-byte hex private key (64 hex chars, optional 0x prefix).");
|
|
43
|
-
}
|
|
44
|
-
const { privateKeyToAccount } = await import('viem/accounts');
|
|
45
|
-
return privateKeyToAccount(key);
|
|
46
|
-
};
|
|
47
|
-
const resolveSvmSigner = async (secret) => {
|
|
48
|
-
const trimmed = secret.trim();
|
|
49
|
-
const { createKeyPairSignerFromBytes, createKeyPairSignerFromPrivateKeyBytes, getBase58Encoder } = await import('@solana/kit');
|
|
50
|
-
let bytes;
|
|
51
|
-
if (trimmed.startsWith("[")) {
|
|
52
|
-
let parsed;
|
|
53
|
-
try {
|
|
54
|
-
parsed = JSON.parse(trimmed);
|
|
55
|
-
} catch {
|
|
56
|
-
throw new LunoraError("ENV_INVALID", "x402 pay: the Solana wallet key looks like a JSON byte array but is not valid JSON.");
|
|
57
|
-
}
|
|
58
|
-
if (!Array.isArray(parsed) || parsed.some((entry) => typeof entry !== "number")) {
|
|
59
|
-
throw new LunoraError("ENV_INVALID", "x402 pay: the Solana wallet key JSON must be an array of byte values.");
|
|
60
|
-
}
|
|
61
|
-
bytes = Uint8Array.from(parsed);
|
|
62
|
-
} else {
|
|
63
|
-
try {
|
|
64
|
-
bytes = Uint8Array.from(getBase58Encoder().encode(trimmed));
|
|
65
|
-
} catch {
|
|
66
|
-
throw new LunoraError("ENV_INVALID", "x402 pay: the Solana wallet key must be a base58 secret key or a JSON byte array.");
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (bytes.length === 64) {
|
|
70
|
-
return createKeyPairSignerFromBytes(bytes);
|
|
71
|
-
}
|
|
72
|
-
if (bytes.length === 32) {
|
|
73
|
-
return createKeyPairSignerFromPrivateKeyBytes(bytes);
|
|
74
|
-
}
|
|
75
|
-
throw new LunoraError(
|
|
76
|
-
"ENV_INVALID",
|
|
77
|
-
`x402 pay: the Solana wallet key must decode to 32 or 64 bytes (got ${String(bytes.length)}). Provide a base58 secret key or a JSON byte array.`
|
|
78
|
-
);
|
|
79
|
-
};
|
|
80
|
-
const registerWallet = async (client, config, deps) => {
|
|
81
|
-
const network = toCaip2(config.network);
|
|
82
|
-
const { signer } = config;
|
|
83
|
-
const evm = isEvmNetwork(config.network);
|
|
84
|
-
let account;
|
|
85
|
-
if (signer.type === "signer") {
|
|
86
|
-
assertSignerFamily(signer.signer, evm);
|
|
87
|
-
account = signer.signer;
|
|
88
|
-
} else if (signer.type === "cdp") {
|
|
89
|
-
if (!evm) {
|
|
90
|
-
throw new LunoraError(
|
|
91
|
-
"NOT_IMPLEMENTED",
|
|
92
|
-
`x402 pay: CDP-managed Solana custody (account "${signer.account}") is not wired — a CDP Solana account is not a @solana/kit signer. Build a @solana/kit signer around it and pass it via the { type: "signer" } escape hatch, or use "raw-key".`
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
account = await resolveCdpEvmAccount(signer, deps.getSecret);
|
|
96
|
-
} else {
|
|
97
|
-
const secret = await requireSecret(deps.getSecret, signer.secretName);
|
|
98
|
-
account = evm ? await resolveEvmAccount(secret) : await resolveSvmSigner(secret);
|
|
99
|
-
}
|
|
100
|
-
if (evm) {
|
|
101
|
-
const { registerExactEvmScheme } = await import('@x402/evm/exact/client');
|
|
102
|
-
registerExactEvmScheme(client, { networks: [network], signer: account });
|
|
103
|
-
} else {
|
|
104
|
-
const { registerExactSvmScheme } = await import('@x402/svm/exact/client');
|
|
105
|
-
registerExactSvmScheme(client, { networks: [network], signer: account });
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
export { registerWallet, resolveEvmAccount, resolveSvmSigner };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const toReceipt = (settlement, context) => {
|
|
2
|
-
return {
|
|
3
|
-
amount: settlement.amount ?? settlement.requirements.amount,
|
|
4
|
-
asset: settlement.requirements.asset,
|
|
5
|
-
from: settlement.payer,
|
|
6
|
-
network: settlement.network,
|
|
7
|
-
resource: context.resource,
|
|
8
|
-
to: settlement.requirements.payTo,
|
|
9
|
-
ts: context.ts,
|
|
10
|
-
tx: settlement.transaction
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
const toPaymentEventRow = (receipt) => {
|
|
14
|
-
return {
|
|
15
|
-
processedAt: receipt.ts,
|
|
16
|
-
provider: "x402",
|
|
17
|
-
providerEventId: receipt.tx,
|
|
18
|
-
type: "x402.settled"
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export { toPaymentEventRow, toReceipt };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { createChargeMiddleware } from './createChargeMiddleware-D3yhOpFs.mjs';
|
|
2
|
-
|
|
3
|
-
const withX402 = (config, handler) => {
|
|
4
|
-
let pending;
|
|
5
|
-
return async (context, request) => {
|
|
6
|
-
pending ??= createChargeMiddleware(config).catch((error) => {
|
|
7
|
-
pending = void 0;
|
|
8
|
-
throw error;
|
|
9
|
-
});
|
|
10
|
-
const middleware = await pending;
|
|
11
|
-
return middleware.handle(request, () => handler(context, request));
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export { withX402 };
|