@armory-sh/base 0.2.13 → 0.2.16
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/dist/data/tokens.d.ts +40 -0
- package/dist/encoding/x402.d.ts +15 -26
- package/dist/encoding.d.ts +19 -12
- package/dist/fixtures/payloads.d.ts +3 -5
- package/dist/fixtures/requirements.d.ts +4 -4
- package/dist/index.d.ts +8 -8
- package/dist/index.js +534 -446
- package/dist/types/{simple.d.ts → api.d.ts} +4 -4
- package/dist/types/protocol.d.ts +13 -70
- package/dist/types/v2.d.ts +5 -1
- package/dist/types/x402.d.ts +4 -5
- package/dist/validation.d.ts +2 -10
- package/package.json +3 -6
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { CustomToken } from "../types/networks";
|
|
2
|
+
export declare const USDC_BASE: CustomToken;
|
|
3
|
+
export declare const EURC_BASE: CustomToken;
|
|
4
|
+
export declare const USDC_BASE_SEPOLIA: CustomToken;
|
|
5
|
+
export declare const USDC_SKALE_BASE: CustomToken;
|
|
6
|
+
export declare const SKL_SKALE_BASE: CustomToken;
|
|
7
|
+
export declare const USDT_SKALE_BASE: CustomToken;
|
|
8
|
+
export declare const WBTC_SKALE_BASE: CustomToken;
|
|
9
|
+
export declare const WETH_SKALE_BASE: CustomToken;
|
|
10
|
+
export declare const SKL_SKALE_BASE_SEPOLIA: CustomToken;
|
|
11
|
+
export declare const USDC_SKALE_BASE_SEPOLIA: CustomToken;
|
|
12
|
+
export declare const USDT_SKALE_BASE_SEPOLIA: CustomToken;
|
|
13
|
+
export declare const WBTC_SKALE_BASE_SEPOLIA: CustomToken;
|
|
14
|
+
export declare const WETH_SKALE_BASE_SEPOLIA: CustomToken;
|
|
15
|
+
export declare const TOKENS: {
|
|
16
|
+
readonly USDC_BASE: CustomToken;
|
|
17
|
+
readonly USDC_BASE_SEPOLIA: CustomToken;
|
|
18
|
+
readonly EURC_BASE: CustomToken;
|
|
19
|
+
readonly USDC_SKALE_BASE: CustomToken;
|
|
20
|
+
readonly USDT_SKALE_BASE: CustomToken;
|
|
21
|
+
readonly WBTC_SKALE_BASE: CustomToken;
|
|
22
|
+
readonly WETH_SKALE_BASE: CustomToken;
|
|
23
|
+
readonly SKL_SKALE_BASE: CustomToken;
|
|
24
|
+
readonly SKL_SKALE_BASE_SEPOLIA: CustomToken;
|
|
25
|
+
readonly USDC_SKALE_BASE_SEPOLIA: CustomToken;
|
|
26
|
+
readonly USDT_SKALE_BASE_SEPOLIA: CustomToken;
|
|
27
|
+
readonly WBTC_SKALE_BASE_SEPOLIA: CustomToken;
|
|
28
|
+
readonly WETH_SKALE_BASE_SEPOLIA: CustomToken;
|
|
29
|
+
};
|
|
30
|
+
declare function getToken(chainId: number, contractAddress: string): CustomToken | undefined;
|
|
31
|
+
declare function getAllTokens(): CustomToken[];
|
|
32
|
+
declare function getTokensBySymbol(symbol: string): CustomToken[];
|
|
33
|
+
declare function getTokensByChain(chainId: number): CustomToken[];
|
|
34
|
+
export declare function getUSDCTokens(): CustomToken[];
|
|
35
|
+
export declare function getEURCTokens(): CustomToken[];
|
|
36
|
+
export declare function getSKLTokens(): CustomToken[];
|
|
37
|
+
export declare function getUSDTTokens(): CustomToken[];
|
|
38
|
+
export declare function getWBTCTokens(): CustomToken[];
|
|
39
|
+
export declare function getWETHTokens(): CustomToken[];
|
|
40
|
+
export { getToken, getAllTokens, getTokensBySymbol, getTokensByChain };
|
package/dist/encoding/x402.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* X402 Protocol Encoding - Coinbase Compatible
|
|
2
|
+
* X402 Protocol Encoding - V2 Only (Coinbase Compatible)
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Payment payloads are JSON-encoded for transport in HTTP headers.
|
|
5
|
+
* Matches the Coinbase x402 v2 SDK format.
|
|
6
6
|
*/
|
|
7
|
-
import type { PaymentPayload,
|
|
7
|
+
import type { PaymentPayload, X402Response, PaymentPayloadV2, PaymentRequirements, SettlementResponse } from "../types/x402";
|
|
8
8
|
/**
|
|
9
9
|
* Safe Base64 encode (URL-safe, no padding)
|
|
10
10
|
*/
|
|
@@ -14,20 +14,19 @@ export declare function safeBase64Encode(str: string): string;
|
|
|
14
14
|
*/
|
|
15
15
|
export declare function safeBase64Decode(str: string): string;
|
|
16
16
|
/**
|
|
17
|
-
* Encode payment payload to
|
|
18
|
-
* All versions use Base64 encoding for compatibility
|
|
17
|
+
* Encode payment payload to JSON string
|
|
19
18
|
*/
|
|
20
|
-
export declare function encodePayment(payload: PaymentPayload |
|
|
19
|
+
export declare function encodePayment(payload: PaymentPayload | PaymentPayloadV2): string;
|
|
21
20
|
/**
|
|
22
|
-
* Decode payment payload from
|
|
21
|
+
* Decode payment payload from JSON string
|
|
23
22
|
*/
|
|
24
23
|
export declare function decodePayment(encoded: string): PaymentPayload;
|
|
25
24
|
/**
|
|
26
|
-
* Encode settlement response to
|
|
25
|
+
* Encode settlement response to JSON string
|
|
27
26
|
*/
|
|
28
27
|
export declare function encodeSettlementResponse(response: SettlementResponse): string;
|
|
29
28
|
/**
|
|
30
|
-
* Decode settlement response from
|
|
29
|
+
* Decode settlement response from JSON string
|
|
31
30
|
*/
|
|
32
31
|
export declare function decodeSettlementResponse(encoded: string): SettlementResponse;
|
|
33
32
|
/**
|
|
@@ -38,40 +37,30 @@ export declare function encodeX402Response(response: X402Response): string;
|
|
|
38
37
|
* Decode X402 error response
|
|
39
38
|
*/
|
|
40
39
|
export declare function decodeX402Response(encoded: string): X402Response;
|
|
41
|
-
/**
|
|
42
|
-
* Unified X402 headers - Coinbase compatible
|
|
43
|
-
*/
|
|
44
|
-
export declare const X402_HEADERS: {
|
|
45
|
-
readonly PAYMENT: "X-PAYMENT";
|
|
46
|
-
readonly PAYMENT_RESPONSE: "X-PAYMENT-RESPONSE";
|
|
47
|
-
readonly PAYMENT_REQUIRED: "X-PAYMENT-REQUIRED";
|
|
48
|
-
};
|
|
49
40
|
/**
|
|
50
41
|
* Detect payment version from headers
|
|
51
42
|
* Returns null if no payment header found
|
|
52
43
|
*
|
|
53
|
-
*
|
|
54
|
-
* and legacy format (X-PAYMENT for v1, PAYMENT-SIGNATURE for v2)
|
|
44
|
+
* V2-only: checks for PAYMENT-SIGNATURE header
|
|
55
45
|
*/
|
|
56
46
|
export declare function detectPaymentVersion(headers: Headers): number | null;
|
|
57
47
|
/**
|
|
58
|
-
* Extract payment from headers
|
|
48
|
+
* Extract payment from V2 headers
|
|
59
49
|
*/
|
|
60
50
|
export declare function extractPaymentFromHeaders(headers: Headers): PaymentPayload | null;
|
|
61
51
|
/**
|
|
62
|
-
* Create payment required headers
|
|
52
|
+
* Create payment required headers (V2 format)
|
|
63
53
|
*/
|
|
64
54
|
export declare function createPaymentRequiredHeaders(requirements: PaymentRequirements | PaymentRequirements[]): Record<string, string>;
|
|
65
55
|
/**
|
|
66
|
-
* Create settlement response headers
|
|
56
|
+
* Create settlement response headers (V2 format)
|
|
67
57
|
*/
|
|
68
58
|
export declare function createSettlementHeaders(settlement: SettlementResponse): Record<string, string>;
|
|
69
59
|
/**
|
|
70
|
-
* Type
|
|
60
|
+
* Type guard for legacy V2 payload (without x402Version)
|
|
71
61
|
*/
|
|
72
|
-
export declare function isLegacyV1(payload: unknown): payload is PaymentPayloadV1;
|
|
73
62
|
export declare function isLegacyV2(payload: unknown): payload is PaymentPayloadV2;
|
|
74
63
|
/**
|
|
75
|
-
* Decode settlement from headers (
|
|
64
|
+
* Decode settlement from headers (V2 only)
|
|
76
65
|
*/
|
|
77
66
|
export declare function decodeSettlement(headers: Headers): SettlementResponse;
|
package/dist/encoding.d.ts
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
|
-
import type { PaymentPayloadV1, SettlementResponseV1 } from "./types/v1";
|
|
2
|
-
import { V1_HEADERS } from "./types/v1";
|
|
3
1
|
import type { PaymentPayloadV2, SettlementResponseV2 } from "./types/v2";
|
|
4
2
|
import { V2_HEADERS } from "./types/v2";
|
|
5
|
-
export {
|
|
6
|
-
export type PaymentPayload =
|
|
7
|
-
export type SettlementResponse =
|
|
8
|
-
export declare const encodePaymentV1: (payload: PaymentPayloadV1) => string;
|
|
9
|
-
export declare const decodePaymentV1: (encoded: string) => PaymentPayloadV1;
|
|
10
|
-
export declare const encodeSettlementV1: (response: SettlementResponseV1) => string;
|
|
11
|
-
export declare const decodeSettlementV1: (encoded: string) => SettlementResponseV1;
|
|
3
|
+
export { V2_HEADERS };
|
|
4
|
+
export type PaymentPayload = PaymentPayloadV2;
|
|
5
|
+
export type SettlementResponse = SettlementResponseV2;
|
|
12
6
|
export declare const encodePaymentV2: (payload: PaymentPayloadV2) => string;
|
|
13
7
|
export declare const decodePaymentV2: (encoded: string) => PaymentPayloadV2;
|
|
14
8
|
export declare const encodeSettlementV2: (response: SettlementResponseV2) => string;
|
|
15
9
|
export declare const decodeSettlementV2: (encoded: string) => SettlementResponseV2;
|
|
16
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Always returns 2 for V2-only mode
|
|
12
|
+
*/
|
|
13
|
+
export declare const detectPaymentVersion: (headers: Headers) => 2 | null;
|
|
14
|
+
/**
|
|
15
|
+
* Decode payment from headers (V2 only)
|
|
16
|
+
*/
|
|
17
17
|
export declare const decodePayment: (headers: Headers) => PaymentPayload;
|
|
18
|
+
/**
|
|
19
|
+
* Decode settlement from headers (V2 only)
|
|
20
|
+
*/
|
|
18
21
|
export declare const decodeSettlement: (headers: Headers) => SettlementResponse;
|
|
19
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Type guard for V2 payload
|
|
24
|
+
*/
|
|
20
25
|
export declare const isPaymentV2: (payload: PaymentPayload) => payload is PaymentPayloadV2;
|
|
21
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Type guard for V2 settlement
|
|
28
|
+
*/
|
|
22
29
|
export declare const isSettlementV2: (response: SettlementResponse) => response is SettlementResponseV2;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Mock Payment Payloads for Testing
|
|
2
|
+
* Mock Payment Payloads for Testing (V2 Only)
|
|
3
3
|
*/
|
|
4
|
-
import type {
|
|
5
|
-
export declare const TEST_PRIVATE_KEY = "
|
|
4
|
+
import type { X402PayloadV2, PaymentPayloadV2 } from "@armory-sh/base";
|
|
5
|
+
export declare const TEST_PRIVATE_KEY = "0x0000000000000000000000000000000000000000000000000000000000000000001";
|
|
6
6
|
export declare const TEST_PAYER_ADDRESS = "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb1";
|
|
7
7
|
export declare const TEST_PAY_TO_ADDRESS = "0x1234567890123456789012345678901234567890";
|
|
8
8
|
export declare const TEST_CONTRACT_ADDRESS = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
|
|
9
|
-
export declare const createX402V1Payload: (nonce?: string) => X402PaymentPayloadV1;
|
|
10
|
-
export declare const createFaremeterPayload: (nonce?: string) => X402PaymentPayloadV1;
|
|
11
9
|
export declare const createX402V2Payload: (nonce?: string) => PaymentPayloadV2;
|
|
12
10
|
export declare const createLegacyV2Payload: (nonce?: string) => X402PayloadV2;
|
|
13
11
|
export declare const INVALID_PAYLOADS: {
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Mock Payment Requirements for Testing
|
|
2
|
+
* Mock Payment Requirements for Testing (V2 Only)
|
|
3
3
|
*/
|
|
4
|
-
import type {
|
|
5
|
-
export declare const MOCK_X402_V1_REQUIREMENTS: X402PaymentRequirementsV1;
|
|
6
|
-
export declare const createX402V1Requirements: (overrides?: Partial<X402PaymentRequirementsV1>) => X402PaymentRequirementsV1;
|
|
4
|
+
import type { PaymentRequirementsV2 } from "@armory-sh/base";
|
|
7
5
|
export declare const MOCK_X402_V2_REQUIREMENTS: PaymentRequirementsV2;
|
|
8
6
|
export declare const createX402V2Requirements: (overrides?: Partial<PaymentRequirementsV2>) => PaymentRequirementsV2;
|
|
9
7
|
export declare const INVALID_REQUIREMENTS: {
|
|
@@ -14,6 +12,8 @@ export declare const INVALID_REQUIREMENTS: {
|
|
|
14
12
|
asset: import("@armory-sh/base").Address;
|
|
15
13
|
payTo: import("@armory-sh/base").Address;
|
|
16
14
|
maxTimeoutSeconds: number;
|
|
15
|
+
name?: string;
|
|
16
|
+
version?: string;
|
|
17
17
|
extra?: import("@armory-sh/base").Extensions;
|
|
18
18
|
};
|
|
19
19
|
readonly invalidNetwork: {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
export type { Address as X402Address, Hex, X402Version, Scheme, Network as X402Network, ExactEvmAuthorization, ExactEvmPayload, PaymentPayload as X402PaymentPayload, UnsignedPaymentPayload as X402UnsignedPaymentPayload, PaymentRequirements as X402PaymentRequirements, SettlementResponse as X402SettlementResponse, VerifyResponse, X402Response,
|
|
1
|
+
export type { Address as X402Address, Hex, X402Version, Scheme, Network as X402Network, ExactEvmAuthorization, ExactEvmPayload, PaymentPayload as X402PaymentPayload, UnsignedPaymentPayload as X402UnsignedPaymentPayload, PaymentRequirements as X402PaymentRequirements, SettlementResponse as X402SettlementResponse, VerifyResponse, X402Response, PaymentPayloadV2 as X402PayloadV2, LegacyPaymentPayload as X402LegacyPayload, } from "./types/x402";
|
|
2
2
|
export { X402_VERSION, SCHEMES, isPaymentPayload, isExactEvmPayload, legacyToPaymentPayload, } from "./types/x402";
|
|
3
|
-
export { safeBase64Encode, safeBase64Decode, encodePayment, decodePayment, encodeSettlementResponse, decodeSettlementResponse, encodeX402Response, decodeX402Response,
|
|
3
|
+
export { safeBase64Encode, safeBase64Decode, encodePayment, decodePayment, encodeSettlementResponse, decodeSettlementResponse, encodeX402Response, decodeX402Response, detectPaymentVersion, extractPaymentFromHeaders, createPaymentRequiredHeaders, createSettlementHeaders, isLegacyV2, } from "./encoding/x402";
|
|
4
4
|
export { createNonce, toAtomicUnits, fromAtomicUnits, caip2ToNetwork, networkToCaip2, getCurrentTimestamp, isValidAddress, normalizeAddress, } from "./utils/x402";
|
|
5
|
-
export type { PaymentPayloadV1, PaymentRequirementsV1, SettlementResponseV1, X402PaymentPayloadV1, X402PaymentRequiredV1, X402PaymentRequirementsV1, X402SettlementResponseV1, X402SchemePayloadV1, EIP3009AuthorizationV1, LegacyPaymentPayloadV1, LegacyPaymentRequirementsV1, LegacySettlementResponseV1, } from "./types/v1";
|
|
6
|
-
export { V1_HEADERS, encodeX402PaymentRequiredV1, decodeX402PaymentRequiredV1, encodeX402PaymentPayloadV1, decodeX402PaymentPayloadV1, encodeX402SettlementResponseV1, decodeX402SettlementResponseV1, isX402PaymentRequiredV1, isX402PaymentPayloadV1, isLegacyPaymentPayloadV1, encodePaymentPayloadLegacy, decodePaymentPayloadLegacy, encodeSettlementResponseLegacy, decodeSettlementResponseLegacy, } from "./types/v1";
|
|
7
|
-
export { encodePaymentPayloadLegacy as encodePaymentPayload, decodePaymentPayloadLegacy as decodePaymentPayload } from "./types/v1";
|
|
8
5
|
export type { CAIP2Network as CAIP2ChainId, CAIPAssetId, Address, Signature, PayToV2, Extensions, PaymentPayloadV2, PaymentRequirementsV2, SettlementResponseV2, PaymentRequiredV2, ResourceInfo, EIP3009Authorization, SchemePayloadV2, } from "./types/v2";
|
|
9
6
|
export { V2_HEADERS, isCAIP2ChainId, isCAIPAssetId, isAddress, isPaymentRequiredV2, isPaymentPayloadV2, assetIdToAddress, addressToAssetId, parseSignature as parseSignatureV2, combineSignature as combineSignatureV2, } from "./types/v2";
|
|
10
7
|
export type { PaymentPayload, PaymentRequirements, SettlementResponse, PaymentRequired, } from "./types/protocol";
|
|
11
|
-
export {
|
|
8
|
+
export { isX402V2Payload, isX402V2Requirements, isX402V2Settlement, isX402V2PaymentRequired, isLegacyV2Payload, isSettlementSuccessful, getTxHash, PAYMENT_SIGNATURE_HEADER, PAYMENT_RESPONSE_HEADER, PAYMENT_REQUIRED_HEADER, } from "./types/protocol";
|
|
12
9
|
export type { NetworkConfig, CustomToken } from "./types/networks";
|
|
13
10
|
export { NETWORKS, getNetworkConfig, getNetworkByChainId, getMainnets, getTestnets, registerToken, getCustomToken, getAllCustomTokens, unregisterToken, isCustomToken, } from "./types/networks";
|
|
11
|
+
export { TOKENS, USDC_BASE, EURC_BASE, USDC_BASE_SEPOLIA, USDC_SKALE_BASE, SKL_SKALE_BASE, USDT_SKALE_BASE, WBTC_SKALE_BASE, WETH_SKALE_BASE, SKL_SKALE_BASE_SEPOLIA, USDC_SKALE_BASE_SEPOLIA, USDT_SKALE_BASE_SEPOLIA, WBTC_SKALE_BASE_SEPOLIA, WETH_SKALE_BASE_SEPOLIA, getToken, getAllTokens, getTokensBySymbol, getTokensByChain, getUSDCTokens, getEURCTokens, getSKLTokens, getUSDTTokens, getWBTCTokens, getWETHTokens, } from "./data/tokens";
|
|
14
12
|
export type { TransferWithAuthorizationParams, ReceiveWithAuthorizationParams, BalanceOfParams, BalanceOfReturnType, NameReturnType, SymbolReturnType, ERC20Abi, } from "./abi/erc20";
|
|
15
13
|
export { ERC20_ABI } from "./abi/erc20";
|
|
16
14
|
export type { TypedDataDomain, EIP712Domain, TransferWithAuthorization, TypedDataField, EIP712Types, } from "./eip712";
|
|
17
15
|
export { EIP712_TYPES, USDC_DOMAIN, createEIP712Domain, createTransferWithAuthorization, validateTransferWithAuthorization, } from "./eip712";
|
|
18
16
|
export { resolveNetwork, resolveToken, resolveFacilitator, checkFacilitatorSupport, validatePaymentConfig, validateAcceptConfig, getAvailableNetworks, getAvailableTokens, isValidationError, isResolvedNetwork, isResolvedToken, createError, normalizeNetworkName, } from "./validation";
|
|
19
|
-
export {
|
|
20
|
-
export type { NetworkId, TokenId, FacilitatorConfig, FacilitatorVerifyResult, FacilitatorSettleResult, SettlementMode, PayToAddress, AcceptPaymentOptions, PricingConfig, PaymentResult, PaymentError, PaymentErrorCode, ArmoryPaymentResult, ResolvedNetwork, ResolvedToken, ResolvedFacilitator, ResolvedPaymentConfig, ValidationError, } from "./types/
|
|
17
|
+
export { encodePaymentV2, decodePaymentV2, encodeSettlementV2, decodeSettlementV2, isPaymentV2, isSettlementV2, } from "./encoding";
|
|
18
|
+
export type { NetworkId, TokenId, FacilitatorConfig, FacilitatorVerifyResult, FacilitatorSettleResult, SettlementMode, PayToAddress, AcceptPaymentOptions, PricingConfig, PaymentResult, PaymentError, PaymentErrorCode, ArmoryPaymentResult, ResolvedNetwork, ResolvedToken, ResolvedFacilitator, ResolvedPaymentConfig, ValidationError, } from "./types/api";
|
|
19
|
+
export { createX402V2Payload, createLegacyV2Payload, INVALID_PAYLOADS, TEST_PAYER_ADDRESS, TEST_PAY_TO_ADDRESS, TEST_CONTRACT_ADDRESS, TEST_PRIVATE_KEY, } from "./fixtures/payloads";
|
|
20
|
+
export { DEFAULT_PAYMENT_CONFIG, type TestPaymentConfig } from "./fixtures/config";
|