@selat-ai/router-client 0.1.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 +126 -0
- package/dist/index.cjs +589 -0
- package/dist/index.d.cts +94 -0
- package/dist/index.d.ts +94 -0
- package/dist/index.js +555 -0
- package/package.json +58 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { SupportedChainName } from '@circle-fin/x402-batching/client';
|
|
2
|
+
import { privateKeyToAccount } from 'viem/accounts';
|
|
3
|
+
|
|
4
|
+
interface PaymentRequiredAccept {
|
|
5
|
+
scheme: string;
|
|
6
|
+
network: string;
|
|
7
|
+
asset: string;
|
|
8
|
+
amount: string;
|
|
9
|
+
payTo: string;
|
|
10
|
+
maxTimeoutSeconds: number;
|
|
11
|
+
extra?: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
interface QuoteChallenge {
|
|
14
|
+
quoteId: string;
|
|
15
|
+
expiresAt: number;
|
|
16
|
+
x402Version: number;
|
|
17
|
+
resource?: Record<string, unknown>;
|
|
18
|
+
accepts: PaymentRequiredAccept[];
|
|
19
|
+
}
|
|
20
|
+
interface PaymentPayload {
|
|
21
|
+
paymentSignature: string;
|
|
22
|
+
}
|
|
23
|
+
interface PaymentSigner {
|
|
24
|
+
address: `0x${string}`;
|
|
25
|
+
circleAgentWalletProcessor?: (input: {
|
|
26
|
+
chainId: number;
|
|
27
|
+
verifyingContract?: `0x${string}`;
|
|
28
|
+
version?: string;
|
|
29
|
+
}) => Promise<void>;
|
|
30
|
+
signTypedData: (params: Parameters<ReturnType<typeof privateKeyToAccount>["signTypedData"]>[0]) => Promise<`0x${string}`>;
|
|
31
|
+
}
|
|
32
|
+
interface RouterClientOptions {
|
|
33
|
+
routerUrl?: string;
|
|
34
|
+
chain: SupportedChainName;
|
|
35
|
+
privateKey?: `0x${string}`;
|
|
36
|
+
signer?: PaymentSigner;
|
|
37
|
+
requestTimeoutMs?: number;
|
|
38
|
+
defaultHeaders?: Record<string, string>;
|
|
39
|
+
}
|
|
40
|
+
interface RouterFetchOptions extends RequestInit {
|
|
41
|
+
preferProtocol?: "x402" | "mpp";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
declare class RouterClient {
|
|
45
|
+
private readonly options;
|
|
46
|
+
private readonly quoteParser;
|
|
47
|
+
private readonly routerUrl;
|
|
48
|
+
private readonly requestTimeoutMs;
|
|
49
|
+
private readonly paymentPayloadBuilder;
|
|
50
|
+
constructor(options: RouterClientOptions);
|
|
51
|
+
createFetch(config: {
|
|
52
|
+
baseUrl: string;
|
|
53
|
+
}): (path: string, init?: RouterFetchOptions) => Promise<Response>;
|
|
54
|
+
fetch(input: string, init?: RouterFetchOptions): Promise<Response>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
type CircleNanopaymentPayloadBuilderOptions = {
|
|
58
|
+
chain: SupportedChainName;
|
|
59
|
+
signer: PaymentSigner;
|
|
60
|
+
};
|
|
61
|
+
declare class CircleNanopaymentPayloadBuilder {
|
|
62
|
+
private readonly options;
|
|
63
|
+
constructor(options: CircleNanopaymentPayloadBuilderOptions);
|
|
64
|
+
build(challenge: QuoteChallenge): Promise<PaymentPayload>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
declare function createViemSigner(privateKey: `0x${string}`): PaymentSigner;
|
|
68
|
+
|
|
69
|
+
type SignTypedDataRequest = Parameters<PaymentSigner["signTypedData"]>[0];
|
|
70
|
+
type RemoteSignTypedDataRequester = (payload: {
|
|
71
|
+
address: `0x${string}`;
|
|
72
|
+
typedData: SignTypedDataRequest;
|
|
73
|
+
}) => Promise<`0x${string}`>;
|
|
74
|
+
declare function createRemoteSigner(address: `0x${string}`, requester: RemoteSignTypedDataRequester): PaymentSigner;
|
|
75
|
+
|
|
76
|
+
type CircleAgentWalletSignerOptions = {
|
|
77
|
+
address: `0x${string}`;
|
|
78
|
+
chain: SupportedChainName;
|
|
79
|
+
cliCommand?: string;
|
|
80
|
+
timeoutMs?: number;
|
|
81
|
+
};
|
|
82
|
+
declare function createCircleAgentWalletSigner(options: CircleAgentWalletSignerOptions): PaymentSigner;
|
|
83
|
+
|
|
84
|
+
declare class RouterSdkError extends Error {
|
|
85
|
+
constructor(message: string);
|
|
86
|
+
}
|
|
87
|
+
declare class QuoteParseError extends RouterSdkError {
|
|
88
|
+
constructor(message: string);
|
|
89
|
+
}
|
|
90
|
+
declare class RouterClientConfigError extends RouterSdkError {
|
|
91
|
+
constructor(message: string);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export { CircleNanopaymentPayloadBuilder, type PaymentPayload, type PaymentRequiredAccept, type PaymentSigner, type QuoteChallenge, QuoteParseError, RouterClient, RouterClientConfigError, type RouterClientOptions, type RouterFetchOptions, RouterSdkError, createCircleAgentWalletSigner, createRemoteSigner, createViemSigner };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { SupportedChainName } from '@circle-fin/x402-batching/client';
|
|
2
|
+
import { privateKeyToAccount } from 'viem/accounts';
|
|
3
|
+
|
|
4
|
+
interface PaymentRequiredAccept {
|
|
5
|
+
scheme: string;
|
|
6
|
+
network: string;
|
|
7
|
+
asset: string;
|
|
8
|
+
amount: string;
|
|
9
|
+
payTo: string;
|
|
10
|
+
maxTimeoutSeconds: number;
|
|
11
|
+
extra?: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
interface QuoteChallenge {
|
|
14
|
+
quoteId: string;
|
|
15
|
+
expiresAt: number;
|
|
16
|
+
x402Version: number;
|
|
17
|
+
resource?: Record<string, unknown>;
|
|
18
|
+
accepts: PaymentRequiredAccept[];
|
|
19
|
+
}
|
|
20
|
+
interface PaymentPayload {
|
|
21
|
+
paymentSignature: string;
|
|
22
|
+
}
|
|
23
|
+
interface PaymentSigner {
|
|
24
|
+
address: `0x${string}`;
|
|
25
|
+
circleAgentWalletProcessor?: (input: {
|
|
26
|
+
chainId: number;
|
|
27
|
+
verifyingContract?: `0x${string}`;
|
|
28
|
+
version?: string;
|
|
29
|
+
}) => Promise<void>;
|
|
30
|
+
signTypedData: (params: Parameters<ReturnType<typeof privateKeyToAccount>["signTypedData"]>[0]) => Promise<`0x${string}`>;
|
|
31
|
+
}
|
|
32
|
+
interface RouterClientOptions {
|
|
33
|
+
routerUrl?: string;
|
|
34
|
+
chain: SupportedChainName;
|
|
35
|
+
privateKey?: `0x${string}`;
|
|
36
|
+
signer?: PaymentSigner;
|
|
37
|
+
requestTimeoutMs?: number;
|
|
38
|
+
defaultHeaders?: Record<string, string>;
|
|
39
|
+
}
|
|
40
|
+
interface RouterFetchOptions extends RequestInit {
|
|
41
|
+
preferProtocol?: "x402" | "mpp";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
declare class RouterClient {
|
|
45
|
+
private readonly options;
|
|
46
|
+
private readonly quoteParser;
|
|
47
|
+
private readonly routerUrl;
|
|
48
|
+
private readonly requestTimeoutMs;
|
|
49
|
+
private readonly paymentPayloadBuilder;
|
|
50
|
+
constructor(options: RouterClientOptions);
|
|
51
|
+
createFetch(config: {
|
|
52
|
+
baseUrl: string;
|
|
53
|
+
}): (path: string, init?: RouterFetchOptions) => Promise<Response>;
|
|
54
|
+
fetch(input: string, init?: RouterFetchOptions): Promise<Response>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
type CircleNanopaymentPayloadBuilderOptions = {
|
|
58
|
+
chain: SupportedChainName;
|
|
59
|
+
signer: PaymentSigner;
|
|
60
|
+
};
|
|
61
|
+
declare class CircleNanopaymentPayloadBuilder {
|
|
62
|
+
private readonly options;
|
|
63
|
+
constructor(options: CircleNanopaymentPayloadBuilderOptions);
|
|
64
|
+
build(challenge: QuoteChallenge): Promise<PaymentPayload>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
declare function createViemSigner(privateKey: `0x${string}`): PaymentSigner;
|
|
68
|
+
|
|
69
|
+
type SignTypedDataRequest = Parameters<PaymentSigner["signTypedData"]>[0];
|
|
70
|
+
type RemoteSignTypedDataRequester = (payload: {
|
|
71
|
+
address: `0x${string}`;
|
|
72
|
+
typedData: SignTypedDataRequest;
|
|
73
|
+
}) => Promise<`0x${string}`>;
|
|
74
|
+
declare function createRemoteSigner(address: `0x${string}`, requester: RemoteSignTypedDataRequester): PaymentSigner;
|
|
75
|
+
|
|
76
|
+
type CircleAgentWalletSignerOptions = {
|
|
77
|
+
address: `0x${string}`;
|
|
78
|
+
chain: SupportedChainName;
|
|
79
|
+
cliCommand?: string;
|
|
80
|
+
timeoutMs?: number;
|
|
81
|
+
};
|
|
82
|
+
declare function createCircleAgentWalletSigner(options: CircleAgentWalletSignerOptions): PaymentSigner;
|
|
83
|
+
|
|
84
|
+
declare class RouterSdkError extends Error {
|
|
85
|
+
constructor(message: string);
|
|
86
|
+
}
|
|
87
|
+
declare class QuoteParseError extends RouterSdkError {
|
|
88
|
+
constructor(message: string);
|
|
89
|
+
}
|
|
90
|
+
declare class RouterClientConfigError extends RouterSdkError {
|
|
91
|
+
constructor(message: string);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export { CircleNanopaymentPayloadBuilder, type PaymentPayload, type PaymentRequiredAccept, type PaymentSigner, type QuoteChallenge, QuoteParseError, RouterClient, RouterClientConfigError, type RouterClientOptions, type RouterFetchOptions, RouterSdkError, createCircleAgentWalletSigner, createRemoteSigner, createViemSigner };
|