@armory-sh/base 0.2.12 → 0.2.14

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.
@@ -31,6 +31,40 @@ export interface FacilitatorConfig {
31
31
  /** Tokens this facilitator supports (optional) */
32
32
  tokens?: TokenId[];
33
33
  }
34
+ /**
35
+ * Result from facilitator verification
36
+ */
37
+ export interface FacilitatorVerifyResult {
38
+ success: boolean;
39
+ payerAddress?: string;
40
+ balance?: string;
41
+ requiredAmount?: string;
42
+ error?: string;
43
+ }
44
+ /**
45
+ * Result from facilitator settlement
46
+ */
47
+ export interface FacilitatorSettleResult {
48
+ success: boolean;
49
+ txHash?: string;
50
+ error?: string;
51
+ }
52
+ /**
53
+ * Settlement mode - verify only, settle only, or both
54
+ */
55
+ export type SettlementMode = "verify" | "settle" | "async";
56
+ /**
57
+ * CAIP-2 chain ID type (e.g., eip155:8453)
58
+ */
59
+ export type CAIP2ChainId = `eip155:${string}`;
60
+ /**
61
+ * CAIP-2 asset ID type (e.g., eip155:8453/erc20:0xa0b8691...)
62
+ */
63
+ export type CAIP2AssetId = `eip155:${string}/erc20:${string}`;
64
+ /**
65
+ * Payment destination - address, CAIP-2 chain ID, or CAIP asset ID
66
+ */
67
+ export type PayToAddress = `0x${string}` | CAIP2ChainId | CAIP2AssetId;
34
68
  /**
35
69
  * Pricing configuration for a specific network/token/facilitator combination
36
70
  */
@@ -54,8 +88,8 @@ export interface AcceptPaymentOptions {
54
88
  tokens?: TokenId[];
55
89
  /** Facilitator(s) for payment verification/settlement */
56
90
  facilitators?: FacilitatorConfig | FacilitatorConfig[];
57
- /** Protocol version (default: auto-detect) */
58
- version?: 1 | 2 | "auto";
91
+ /** Protocol version (V2 only) */
92
+ version?: 2;
59
93
  /** Pricing configurations - if not provided, uses amount from top-level config */
60
94
  pricing?: PricingConfig[];
61
95
  }
@@ -138,8 +172,8 @@ export interface ResolvedPaymentConfig {
138
172
  token: ResolvedToken;
139
173
  /** Facilitator(s) to use */
140
174
  facilitators: ResolvedFacilitator[];
141
- /** Protocol version */
142
- version: 1 | 2 | "auto";
175
+ /** Protocol version (V2 only) */
176
+ version: 2;
143
177
  /** Recipient address */
144
178
  payTo: Address;
145
179
  /** Amount to charge */
File without changes
@@ -12,14 +12,14 @@ export interface CustomToken {
12
12
  version: string;
13
13
  contractAddress: `0x${string}`;
14
14
  chainId: number;
15
- decimals: number;
15
+ decimals?: number;
16
16
  }
17
17
  export declare const NETWORKS: Record<string, NetworkConfig>;
18
18
  export declare const getNetworkConfig: (name: string) => NetworkConfig | undefined;
19
19
  export declare const getNetworkByChainId: (chainId: number) => NetworkConfig | undefined;
20
20
  export declare const getMainnets: () => NetworkConfig[];
21
21
  export declare const getTestnets: () => NetworkConfig[];
22
- export declare const registerToken: (token: CustomToken) => CustomToken;
22
+ export declare const registerToken: (token: unknown) => CustomToken;
23
23
  export declare const getCustomToken: (chainId: number, contractAddress: string) => CustomToken | undefined;
24
24
  export declare const getAllCustomTokens: () => CustomToken[];
25
25
  export declare const unregisterToken: (chainId: number, contractAddress: string) => boolean;
@@ -1,107 +1,91 @@
1
1
  /**
2
- * Protocol Union Types and Version Detection
2
+ * Protocol Types - x402 V2 Only
3
3
  *
4
- * Handles both x402 V1 and V2 formats along with legacy Armory formats
4
+ * Simplified to support only x402 V2 format (Coinbase compatible)
5
5
  */
6
- import type { X402PaymentPayloadV1, X402PaymentRequiredV1, X402PaymentRequirementsV1, X402SettlementResponseV1, LegacyPaymentPayloadV1, LegacyPaymentRequirementsV1, LegacySettlementResponseV1 } from "./v1";
7
- import type { PaymentPayloadV2, PaymentRequirementsV2, SettlementResponseV2, PaymentRequiredV2 } from "./v2";
6
+ import type { PaymentPayloadV2, PaymentRequirementsV2, SettlementResponseV2, PaymentRequiredV2, Address } from "./v2";
7
+ export type PaymentPayload = PaymentPayloadV2;
8
+ export type PaymentRequirements = PaymentRequirementsV2;
9
+ export type SettlementResponse = SettlementResponseV2;
10
+ export type PaymentRequired = PaymentRequiredV2;
8
11
  /**
9
- * All x402 compatible payment payload types
12
+ * Configuration for connecting to a facilitator service
10
13
  */
11
- export type PaymentPayload = X402PaymentPayloadV1 | PaymentPayloadV2 | LegacyPaymentPayloadV1;
14
+ export interface FacilitatorConfig {
15
+ url: string;
16
+ createHeaders?: () => Record<string, string>;
17
+ }
12
18
  /**
13
- * All x402 compatible payment requirements types
19
+ * Result from facilitator verification
14
20
  */
15
- export type PaymentRequirements = X402PaymentRequirementsV1 | PaymentRequirementsV2 | LegacyPaymentRequirementsV1;
21
+ export interface FacilitatorVerifyResult {
22
+ success: boolean;
23
+ payerAddress?: string;
24
+ balance?: string;
25
+ requiredAmount?: string;
26
+ error?: string;
27
+ }
16
28
  /**
17
- * All x402 compatible settlement response types
29
+ * Result from facilitator settlement
18
30
  */
19
- export type SettlementResponse = X402SettlementResponseV1 | SettlementResponseV2 | LegacySettlementResponseV1;
31
+ export interface FacilitatorSettleResult {
32
+ success: boolean;
33
+ txHash?: string;
34
+ error?: string;
35
+ }
20
36
  /**
21
- * All x402 compatible payment required response types
37
+ * Settlement mode - verify only, settle only, or both
22
38
  */
23
- export type PaymentRequired = X402PaymentRequiredV1 | PaymentRequiredV2;
39
+ export type SettlementMode = "verify" | "settle" | "async";
24
40
  /**
25
- * Check if payload is x402 V1 format
41
+ * Payment destination - address, CAIP-2 chain ID, or CAIP asset ID
26
42
  */
27
- export declare function isX402V1Payload(obj: unknown): obj is X402PaymentPayloadV1;
43
+ export type PayToAddress = Address | CAIP2ChainId | CAIPAssetId;
28
44
  /**
29
- * Check if payload is x402 V2 format
45
+ * CAIP-2 chain ID type (e.g., eip155:8453)
30
46
  */
31
- export declare function isX402V2Payload(obj: unknown): obj is PaymentPayloadV2;
32
- /**
33
- * Check if payload is legacy Armory V1 format
34
- */
35
- export declare function isLegacyV1Payload(obj: unknown): obj is LegacyPaymentPayloadV1;
47
+ export type CAIP2ChainId = `eip155:${string}`;
36
48
  /**
37
- * Check if payload is legacy Armory V2 format
49
+ * CAIP-2 asset ID type (e.g., eip155:8453/erc20:0xa0b8691...)
38
50
  */
39
- export declare function isLegacyV2Payload(obj: unknown): boolean;
51
+ export type CAIPAssetId = `eip155:${string}/erc20:${string}`;
40
52
  /**
41
- * Get x402 version from payload
53
+ * Check if payload is x402 V2 format (Coinbase format)
42
54
  */
43
- export declare function getPaymentVersion(payload: PaymentPayload): 1 | 2;
55
+ export declare function isX402V2Payload(obj: unknown): obj is PaymentPayloadV2;
44
56
  /**
45
- * Check if requirements is x402 V1 format
57
+ * Check if payload is legacy Armory V2 format
46
58
  */
47
- export declare function isX402V1Requirements(obj: unknown): obj is X402PaymentRequirementsV1;
59
+ export declare function isLegacyV2Payload(obj: unknown): boolean;
48
60
  /**
49
61
  * Check if requirements is x402 V2 format
50
62
  */
51
63
  export declare function isX402V2Requirements(obj: unknown): obj is PaymentRequirementsV2;
52
- /**
53
- * Get x402 version from requirements
54
- */
55
- export declare function getRequirementsVersion(requirements: PaymentRequirements): 1 | 2;
56
- /**
57
- * Check if settlement response is x402 V1 format
58
- */
59
- export declare function isX402V1Settlement(obj: unknown): obj is X402SettlementResponseV1;
60
64
  /**
61
65
  * Check if settlement response is x402 V2 format
62
66
  */
63
67
  export declare function isX402V2Settlement(obj: unknown): obj is SettlementResponseV2;
64
- /**
65
- * Get x402 version from settlement response
66
- */
67
- export declare function getSettlementVersion(response: SettlementResponse): 1 | 2;
68
- /**
69
- * Check if payment required is x402 V1 format
70
- */
71
- export declare function isX402V1PaymentRequired(obj: unknown): obj is X402PaymentRequiredV1;
72
68
  /**
73
69
  * Check if payment required is x402 V2 format
74
70
  */
75
71
  export declare function isX402V2PaymentRequired(obj: unknown): obj is PaymentRequiredV2;
76
72
  /**
77
- * Get x402 version from payment required
73
+ * x402 V2 payment header name
78
74
  */
79
- export declare function getPaymentRequiredVersion(obj: PaymentRequired): 1 | 2;
75
+ export declare const PAYMENT_SIGNATURE_HEADER: "PAYMENT-SIGNATURE";
80
76
  /**
81
- * Get payment header name for version
77
+ * x402 V2 payment response header name
82
78
  */
83
- export declare function getPaymentHeaderName(version: 1 | 2): string;
79
+ export declare const PAYMENT_RESPONSE_HEADER: "PAYMENT-RESPONSE";
84
80
  /**
85
- * Get payment response header name for version
81
+ * x402 V2 payment required header name
86
82
  */
87
- export declare function getPaymentResponseHeaderName(version: 1 | 2): string;
88
- /**
89
- * Get payment required header name for version
90
- */
91
- export declare function getPaymentRequiredHeaderName(version: 1 | 2): string;
83
+ export declare const PAYMENT_REQUIRED_HEADER: "PAYMENT-REQUIRED";
92
84
  /**
93
85
  * Check if settlement was successful
94
86
  */
95
87
  export declare function isSettlementSuccessful(response: SettlementResponse): boolean;
96
88
  /**
97
- * Get transaction hash from settlement response
89
+ * Get transaction hash from settlement response (V2 only)
98
90
  */
99
91
  export declare function getTxHash(response: SettlementResponse): string | undefined;
100
- /**
101
- * @deprecated Use isX402V1Payload or isLegacyV1Payload instead
102
- */
103
- export declare function isV1(obj: unknown): boolean;
104
- /**
105
- * @deprecated Use isX402V2Payload or isLegacyV2Payload instead
106
- */
107
- export declare function isV2(obj: unknown): boolean;
@@ -18,6 +18,7 @@ export type PayToV2 = Address | {
18
18
  role?: string;
19
19
  callback?: string;
20
20
  };
21
+ export type PayToAddress = Address | PayToV2;
21
22
  export interface Extensions {
22
23
  [key: string]: unknown;
23
24
  }
@@ -49,7 +50,11 @@ export interface PaymentRequirementsV2 {
49
50
  payTo: Address;
50
51
  /** Maximum time allowed for payment completion */
51
52
  maxTimeoutSeconds: number;
52
- /** Scheme-specific additional information (token name, version, etc.) */
53
+ /** EIP-712 domain parameter: token name */
54
+ name?: string;
55
+ /** EIP-712 domain parameter: token version */
56
+ version?: string;
57
+ /** Scheme-specific additional information */
53
58
  extra?: Extensions;
54
59
  }
55
60
  /**
@@ -97,17 +102,19 @@ export interface SchemePayloadV2 {
97
102
  }
98
103
  /**
99
104
  * Payment payload sent by client
100
- * Matches x402 V2 PaymentPayload spec
105
+ * Matches x402 V2 PaymentPayload spec (Coinbase format)
101
106
  */
102
107
  export interface PaymentPayloadV2 {
103
108
  /** Protocol version identifier */
104
109
  x402Version: 2;
105
- /** Resource being accessed (echoed from server) */
106
- resource?: ResourceInfo;
107
- /** Selected payment requirement from server's accepts array */
108
- accepted: PaymentRequirementsV2;
110
+ /** Payment scheme (e.g., "exact") */
111
+ scheme: string;
112
+ /** Network identifier in CAIP-2 format */
113
+ network: string;
109
114
  /** Scheme-specific payment data */
110
115
  payload: SchemePayloadV2;
116
+ /** Resource being accessed (optional, echoed from server) */
117
+ resource?: ResourceInfo;
111
118
  /** Protocol extensions data */
112
119
  extensions?: Extensions;
113
120
  }
@@ -52,18 +52,17 @@ export interface UnsignedPaymentPayload {
52
52
  }
53
53
  /**
54
54
  * Payment requirements for 402 response
55
+ * Matches x402 SDK format
55
56
  */
56
57
  export interface PaymentRequirements {
57
58
  scheme: Scheme;
58
59
  network: Network;
59
- maxAmountRequired: string;
60
- resource: string;
61
- description: string;
62
- mimeType: string;
63
- outputSchema?: Record<string, unknown>;
60
+ amount: string;
64
61
  payTo: Address;
65
62
  maxTimeoutSeconds: number;
66
63
  asset: Address;
64
+ name?: string;
65
+ version?: string;
67
66
  extra?: Record<string, unknown>;
68
67
  }
69
68
  /**
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Test Utilities Index
3
+ *
4
+ * Re-exports commonly used test utilities
5
+ */
6
+ export * from "./mock-facilitator";
7
+ export * from "../../fixtures/config";
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Mock Facilitator for Testing
3
+ */
4
+ import type { PaymentPayload } from "@armory-sh/base";
5
+ export interface FacilitatorVerifyRequest {
6
+ payload: PaymentPayload;
7
+ requirements: Record<string, unknown>;
8
+ options?: Record<string, unknown>;
9
+ }
10
+ export interface FacilitatorVerifyResponse {
11
+ success: boolean;
12
+ payerAddress?: string;
13
+ balance?: string;
14
+ requiredAmount?: string;
15
+ error?: string;
16
+ }
17
+ export interface FacilitatorSettleRequest {
18
+ payload: PaymentPayload;
19
+ requirements: Record<string, unknown>;
20
+ }
21
+ export interface FacilitatorSettleResponse {
22
+ success: boolean;
23
+ txHash?: string;
24
+ error?: string;
25
+ }
26
+ export type AnyFacilitatorRequest = FacilitatorVerifyRequest | FacilitatorSettleRequest;
27
+ export type AnyFacilitatorResponse = FacilitatorVerifyResponse | FacilitatorSettleResponse;
28
+ export interface MockFacilitatorOptions {
29
+ port?: number;
30
+ alwaysVerify?: boolean;
31
+ alwaysSettle?: boolean;
32
+ verifyDelay?: number;
33
+ settleDelay?: number;
34
+ }
35
+ export declare const createMockFacilitator: (options?: MockFacilitatorOptions) => Promise<{
36
+ url: string;
37
+ close: () => Promise<void>;
38
+ }>;
@@ -2,50 +2,23 @@
2
2
  * Comprehensive validation for Armory configurations
3
3
  * Ensures networks, tokens, and facilitators are compatible
4
4
  */
5
- import type { NetworkId, TokenId, FacilitatorConfig, ResolvedNetwork, ResolvedToken, ResolvedFacilitator, ResolvedPaymentConfig, ValidationError, PaymentErrorCode } from "./types/simple.js";
5
+ import type { NetworkId, TokenId, FacilitatorConfig, ResolvedNetwork, ResolvedToken, ResolvedFacilitator, ResolvedPaymentConfig, ValidationError, PaymentErrorCode } from "./types/api";
6
6
  export declare const createError: (code: PaymentErrorCode, message: string, details?: Partial<ValidationError>) => ValidationError;
7
- /**
8
- * Normalize network name to match registry keys
9
- */
10
7
  export declare const normalizeNetworkName: (name: string) => string;
11
- /**
12
- * Resolve a network identifier to a network config
13
- */
14
- export declare const resolveNetwork: (input: NetworkId) => ResolvedNetwork | ValidationError;
15
- /**
16
- * Get all available network names
17
- */
8
+ export declare const resolveNetwork: (input: unknown) => ResolvedNetwork | ValidationError;
18
9
  export declare const getAvailableNetworks: () => string[];
19
- /**
20
- * Resolve a token identifier to a token config
21
- */
22
- export declare const resolveToken: (input: TokenId, network?: ResolvedNetwork) => ResolvedToken | ValidationError;
23
- /**
24
- * Get all available token symbols
25
- */
10
+ export declare const resolveToken: (input: unknown, network?: ResolvedNetwork) => ResolvedToken | ValidationError;
26
11
  export declare const getAvailableTokens: () => string[];
27
- /**
28
- * Resolve a facilitator configuration
29
- */
30
12
  export declare const resolveFacilitator: (input: FacilitatorConfig, supportedNetworks?: ResolvedNetwork[], supportedTokens?: ResolvedToken[]) => ResolvedFacilitator | ValidationError;
31
- /**
32
- * Check if a facilitator supports a specific network/token combination
33
- */
34
13
  export declare const checkFacilitatorSupport: (facilitator: ResolvedFacilitator, network: ResolvedNetwork, token: ResolvedToken) => ValidationError | {
35
14
  supported: true;
36
15
  };
37
- /**
38
- * Validate a complete payment configuration
39
- */
40
16
  export declare const validatePaymentConfig: (network: NetworkId, token: TokenId, facilitators?: FacilitatorConfig | FacilitatorConfig[], payTo?: string, amount?: string) => ResolvedPaymentConfig | ValidationError;
41
- /**
42
- * Validate multi-accept configuration (for merchants)
43
- */
44
17
  export declare const validateAcceptConfig: (options: {
45
18
  networks?: NetworkId[];
46
19
  tokens?: TokenId[];
47
20
  facilitators?: FacilitatorConfig | FacilitatorConfig[];
48
- version?: 1 | 2 | "auto";
21
+ version?: 2;
49
22
  }, payTo: string, amount: string) => {
50
23
  success: true;
51
24
  config: ResolvedPaymentConfig[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@armory-sh/base",
3
- "version": "0.2.12",
3
+ "version": "0.2.14",
4
4
  "license": "MIT",
5
5
  "author": "Sawyer Cutler <sawyer@dirtroad.dev>",
6
6
  "type": "module",
@@ -24,18 +24,17 @@
24
24
  "repository": {
25
25
  "type": "git",
26
26
  "url": "git+https://github.com/thegreataxios/armory.git",
27
- "directory": "packages/core"
28
- },
29
- "dependencies": {
30
- "viem": "2.45.0"
27
+ "directory": "packages/base"
31
28
  },
29
+ "dependencies": {},
32
30
  "devDependencies": {
33
31
  "@types/node": "^25.2.1",
34
32
  "bun-types": "latest",
35
33
  "typescript": "5.9.3"
36
34
  },
37
35
  "scripts": {
38
- "build": "tsup && tsc --emitDeclarationOnly",
39
- "test": "bun test"
36
+ "build": "rm -rf dist && tsup && tsc --emitDeclarationOnly",
37
+ "test": "bun test",
38
+ "typecheck": "tsc --noEmit"
40
39
  }
41
- }
40
+ }
@@ -1,5 +0,0 @@
1
- /**
2
- * Comprehensive unit tests for validation layer
3
- * Tests all input formats, cross-checks, and error messages
4
- */
5
- export {};