@jack-kernel/sdk 1.0.0 → 1.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/dist/cjs/index.js +43 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/yellow/channel-state-manager.js +167 -0
- package/dist/cjs/yellow/channel-state-manager.js.map +1 -0
- package/dist/cjs/yellow/clear-node-connection.js +390 -0
- package/dist/cjs/yellow/clear-node-connection.js.map +1 -0
- package/dist/cjs/yellow/event-mapper.js +254 -0
- package/dist/cjs/yellow/event-mapper.js.map +1 -0
- package/dist/cjs/yellow/serialization.js +130 -0
- package/dist/cjs/yellow/serialization.js.map +1 -0
- package/dist/cjs/yellow/session-key-manager.js +308 -0
- package/dist/cjs/yellow/session-key-manager.js.map +1 -0
- package/dist/cjs/yellow/types.js +12 -0
- package/dist/cjs/yellow/types.js.map +1 -0
- package/dist/cjs/yellow/yellow-provider.js +1545 -0
- package/dist/cjs/yellow/yellow-provider.js.map +1 -0
- package/dist/esm/index.js +34 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/yellow/channel-state-manager.js +163 -0
- package/dist/esm/yellow/channel-state-manager.js.map +1 -0
- package/dist/esm/yellow/clear-node-connection.js +385 -0
- package/dist/esm/yellow/clear-node-connection.js.map +1 -0
- package/dist/esm/yellow/event-mapper.js +248 -0
- package/dist/esm/yellow/event-mapper.js.map +1 -0
- package/dist/esm/yellow/serialization.js +125 -0
- package/dist/esm/yellow/serialization.js.map +1 -0
- package/dist/esm/yellow/session-key-manager.js +302 -0
- package/dist/esm/yellow/session-key-manager.js.map +1 -0
- package/dist/esm/yellow/types.js +11 -0
- package/dist/esm/yellow/types.js.map +1 -0
- package/dist/esm/yellow/yellow-provider.js +1538 -0
- package/dist/esm/yellow/yellow-provider.js.map +1 -0
- package/dist/types/index.d.ts +47 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/yellow/channel-state-manager.d.ts +106 -0
- package/dist/types/yellow/channel-state-manager.d.ts.map +1 -0
- package/dist/types/yellow/clear-node-connection.d.ts +202 -0
- package/dist/types/yellow/clear-node-connection.d.ts.map +1 -0
- package/dist/types/yellow/event-mapper.d.ts +74 -0
- package/dist/types/yellow/event-mapper.d.ts.map +1 -0
- package/dist/types/yellow/serialization.d.ts +52 -0
- package/dist/types/yellow/serialization.d.ts.map +1 -0
- package/dist/types/yellow/session-key-manager.d.ts +179 -0
- package/dist/types/yellow/session-key-manager.d.ts.map +1 -0
- package/dist/types/yellow/types.d.ts +177 -0
- package/dist/types/yellow/types.d.ts.map +1 -0
- package/dist/types/yellow/yellow-provider.d.ts +303 -0
- package/dist/types/yellow/yellow-provider.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session Key Manager for Yellow Network ClearNode Authentication
|
|
3
|
+
*
|
|
4
|
+
* Handles session key generation, EIP-712 authentication flow, and session lifecycle.
|
|
5
|
+
*
|
|
6
|
+
* Authentication flow:
|
|
7
|
+
* 1. Generate session keypair via viem's generatePrivateKey + privateKeyToAccount
|
|
8
|
+
* 2. Send auth_request message with session key address, allowances, expiry, scope
|
|
9
|
+
* 3. Receive auth_challenge from ClearNode
|
|
10
|
+
* 4. Sign challenge with main wallet via EIP-712 typed data
|
|
11
|
+
* 5. Send auth_verify with signed challenge
|
|
12
|
+
* 6. Receive confirmation and store session state
|
|
13
|
+
*
|
|
14
|
+
* Requirements: 2.1, 2.2, 2.3, 2.4, 2.5, 2.6
|
|
15
|
+
*/
|
|
16
|
+
import type { WalletClient, Hex } from 'viem';
|
|
17
|
+
import type { ClearNodeConnection } from './clear-node-connection.js';
|
|
18
|
+
/**
|
|
19
|
+
* Signer function type used for signing messages.
|
|
20
|
+
* Compatible with @erc7824/nitrolite's MessageSigner type.
|
|
21
|
+
*/
|
|
22
|
+
export type MessageSigner = (payload: Uint8Array) => Promise<Hex>;
|
|
23
|
+
/**
|
|
24
|
+
* Parameters for creating an auth request message.
|
|
25
|
+
*/
|
|
26
|
+
interface AuthRequestParams {
|
|
27
|
+
wallet: string;
|
|
28
|
+
participant: string;
|
|
29
|
+
allowances: Array<{
|
|
30
|
+
asset: string;
|
|
31
|
+
amount: string;
|
|
32
|
+
}>;
|
|
33
|
+
expire: number;
|
|
34
|
+
scope: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Parameters for authenticating with ClearNode.
|
|
38
|
+
*/
|
|
39
|
+
export interface AuthParams {
|
|
40
|
+
/** Token allowances for the session */
|
|
41
|
+
allowances: Array<{
|
|
42
|
+
asset: string;
|
|
43
|
+
amount: string;
|
|
44
|
+
}>;
|
|
45
|
+
/** Unix timestamp when the session expires. Default: now + 3600 seconds */
|
|
46
|
+
expiresAt?: number;
|
|
47
|
+
/** Application scope identifier. Default: "jack-kernel" */
|
|
48
|
+
scope?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Information about the current authenticated session.
|
|
52
|
+
*/
|
|
53
|
+
export interface SessionInfo {
|
|
54
|
+
/** The session key's Ethereum address */
|
|
55
|
+
sessionAddress: string;
|
|
56
|
+
/** Unix timestamp when the session expires */
|
|
57
|
+
expiresAt: number;
|
|
58
|
+
/** Whether the session is currently authenticated */
|
|
59
|
+
authenticated: boolean;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Create an auth_request message for ClearNode.
|
|
63
|
+
*
|
|
64
|
+
* This is a local implementation matching the @erc7824/nitrolite
|
|
65
|
+
* createAuthRequestMessage API. It constructs a JSON-RPC style message
|
|
66
|
+
* with the session key details and allowances.
|
|
67
|
+
*
|
|
68
|
+
* @param params - Auth request parameters
|
|
69
|
+
* @returns JSON string of the auth_request message
|
|
70
|
+
*/
|
|
71
|
+
export declare function createAuthRequestMessage(params: AuthRequestParams): string;
|
|
72
|
+
/**
|
|
73
|
+
* Create an EIP-712 auth message signer using the provided wallet client.
|
|
74
|
+
*
|
|
75
|
+
* This is a local implementation matching the @erc7824/nitrolite
|
|
76
|
+
* createEIP712AuthMessageSigner API. It returns a function that signs
|
|
77
|
+
* a challenge string using EIP-712 typed data via the wallet client.
|
|
78
|
+
*
|
|
79
|
+
* The EIP-712 domain and types follow the Yellow Network auth protocol:
|
|
80
|
+
* - Domain: { name: "Yellow ClearNode", version: "1" }
|
|
81
|
+
* - Types: { Auth: [{ name: "challenge", type: "string" }] }
|
|
82
|
+
*
|
|
83
|
+
* @param walletClient - The viem WalletClient to sign with
|
|
84
|
+
* @returns A function that takes a challenge string and returns the EIP-712 signature
|
|
85
|
+
*/
|
|
86
|
+
export declare function createEIP712AuthMessageSigner(walletClient: WalletClient): (challenge: string) => Promise<Hex>;
|
|
87
|
+
/**
|
|
88
|
+
* Manages session key generation, ClearNode authentication, and session lifecycle.
|
|
89
|
+
*
|
|
90
|
+
* The SessionKeyManager generates ephemeral session keypairs for signing offchain
|
|
91
|
+
* messages, authenticates them with ClearNode via EIP-712, and tracks session expiry
|
|
92
|
+
* to support automatic re-authentication when the session expires.
|
|
93
|
+
*
|
|
94
|
+
* Requirements: 2.1, 2.2, 2.3, 2.4, 2.5, 2.6
|
|
95
|
+
*/
|
|
96
|
+
export declare class SessionKeyManager {
|
|
97
|
+
private readonly walletClient;
|
|
98
|
+
private readonly connection;
|
|
99
|
+
private sessionAccount;
|
|
100
|
+
private sessionPrivateKey;
|
|
101
|
+
private _sessionInfo;
|
|
102
|
+
private lastAuthParams;
|
|
103
|
+
/**
|
|
104
|
+
* @param walletClient - The main wallet's viem WalletClient for EIP-712 signing
|
|
105
|
+
* @param connection - The ClearNodeConnection for sending/receiving auth messages
|
|
106
|
+
*/
|
|
107
|
+
constructor(walletClient: WalletClient, connection: ClearNodeConnection);
|
|
108
|
+
/**
|
|
109
|
+
* Generate a session keypair and authenticate with ClearNode.
|
|
110
|
+
*
|
|
111
|
+
* Flow:
|
|
112
|
+
* 1. Generate session keypair (Requirement 2.1)
|
|
113
|
+
* 2. Send auth_request with session address, allowances, expiry, scope (Requirement 2.2)
|
|
114
|
+
* 3. Receive auth_challenge from ClearNode
|
|
115
|
+
* 4. Sign challenge with main wallet via EIP-712 (Requirement 2.3)
|
|
116
|
+
* 5. Send auth_verify with signed challenge
|
|
117
|
+
* 6. Receive confirmation and store session state (Requirement 2.4)
|
|
118
|
+
*
|
|
119
|
+
* @param params - Authentication parameters including allowances and optional expiry/scope
|
|
120
|
+
* @returns Session information including address, expiry, and authentication status
|
|
121
|
+
* @throws Error if authentication fails or times out (Requirement 2.5)
|
|
122
|
+
*/
|
|
123
|
+
authenticate(params: AuthParams): Promise<SessionInfo>;
|
|
124
|
+
/**
|
|
125
|
+
* Check if the current session is valid and not expired.
|
|
126
|
+
*
|
|
127
|
+
* Returns false if:
|
|
128
|
+
* - No session has been established
|
|
129
|
+
* - The session has been invalidated
|
|
130
|
+
* - The session has expired (Requirement 2.6)
|
|
131
|
+
*/
|
|
132
|
+
get isAuthenticated(): boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Get the session signer function for signing offchain messages.
|
|
135
|
+
*
|
|
136
|
+
* The returned function signs arbitrary payloads using the session private key.
|
|
137
|
+
* This is used for signing state channel messages without exposing the main wallet.
|
|
138
|
+
*
|
|
139
|
+
* @throws Error if no authenticated session exists
|
|
140
|
+
*/
|
|
141
|
+
get sessionSigner(): MessageSigner;
|
|
142
|
+
/**
|
|
143
|
+
* Get the session key's Ethereum address.
|
|
144
|
+
*
|
|
145
|
+
* @throws Error if no session key has been generated
|
|
146
|
+
*/
|
|
147
|
+
get sessionAddress(): string;
|
|
148
|
+
/**
|
|
149
|
+
* Invalidate the current session.
|
|
150
|
+
*
|
|
151
|
+
* Clears all session state including the keypair and authentication status.
|
|
152
|
+
* After invalidation, a new authenticate() call is required.
|
|
153
|
+
*/
|
|
154
|
+
invalidate(): void;
|
|
155
|
+
/**
|
|
156
|
+
* Re-authenticate using the last authentication parameters.
|
|
157
|
+
*
|
|
158
|
+
* This is called internally when a session has expired and a new operation
|
|
159
|
+
* requires an active session (Requirement 2.6).
|
|
160
|
+
*
|
|
161
|
+
* @returns Session information from the new authentication
|
|
162
|
+
* @throws Error if no previous auth params exist or re-authentication fails
|
|
163
|
+
*/
|
|
164
|
+
reauthenticate(): Promise<SessionInfo>;
|
|
165
|
+
/**
|
|
166
|
+
* Ensure the session is authenticated, re-authenticating if expired.
|
|
167
|
+
*
|
|
168
|
+
* This is a convenience method for use by other components that need
|
|
169
|
+
* to ensure an active session before performing operations.
|
|
170
|
+
*
|
|
171
|
+
* Requirement 2.6: Auto-reauthentication on next operation when expired.
|
|
172
|
+
*
|
|
173
|
+
* @returns The current or newly created session info
|
|
174
|
+
* @throws Error if authentication fails
|
|
175
|
+
*/
|
|
176
|
+
ensureAuthenticated(): Promise<SessionInfo>;
|
|
177
|
+
}
|
|
178
|
+
export {};
|
|
179
|
+
//# sourceMappingURL=session-key-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-key-manager.d.ts","sourceRoot":"","sources":["../../../src/yellow/session-key-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,GAAG,EAAgB,MAAM,MAAM,CAAC;AAC5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAQtE;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,UAAU,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAElE;;GAEG;AACH,UAAU,iBAAiB;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACrD,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AA+BD;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,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ACH,UAAU,IAAI,IAAI;IAMlB;;;;;;;;OAQG;IACG,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC;IAW5C;;;;;;;;;;OAUG;IACG,mBAAmB,IAAI,OAAO,CAAC,WAAW,CAAC;CAQlD"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Yellow Network Integration - Shared Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* This module defines all shared types for the Yellow Network integration layer.
|
|
5
|
+
* All BigInt-representable fields (allocations, challenge duration) use string type
|
|
6
|
+
* for JSON compatibility (Requirements 11.1, 11.2, 11.5).
|
|
7
|
+
*
|
|
8
|
+
* Requirements: 7.3, 11.1, 11.2, 11.5
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Connection status of the YellowProvider to ClearNode.
|
|
12
|
+
*/
|
|
13
|
+
export type YellowProviderStatus = 'connected' | 'disconnected' | 'connecting' | 'error';
|
|
14
|
+
/**
|
|
15
|
+
* Reason codes for Yellow Network operation failures.
|
|
16
|
+
* Used in YellowFallback to indicate why an operation failed.
|
|
17
|
+
*/
|
|
18
|
+
export type YellowReasonCode = 'MISSING_PARAMS' | 'UNSUPPORTED_CHAIN' | 'INSUFFICIENT_BALANCE' | 'INSUFFICIENT_CHANNEL_BALANCE' | 'NO_SOLVER_QUOTES' | 'YELLOW_UNAVAILABLE' | 'YELLOW_TX_FAILED' | 'YELLOW_AUTH_FAILED' | 'YELLOW_TIMEOUT' | 'YELLOW_CHANNEL_DISPUTE' | 'YELLOW_WS_ERROR';
|
|
19
|
+
/**
|
|
20
|
+
* Fallback information returned when a Yellow Network operation cannot be completed.
|
|
21
|
+
* The `enabled: true` flag indicates that fallback to an alternative provider is recommended.
|
|
22
|
+
*/
|
|
23
|
+
export interface YellowFallback {
|
|
24
|
+
enabled: true;
|
|
25
|
+
reasonCode: YellowReasonCode;
|
|
26
|
+
message: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Normalized representation of a state channel's current status, allocations, and metadata.
|
|
30
|
+
* Requirement 7.3: includes channelId, status, allocations per participant, token address, and chainId.
|
|
31
|
+
*/
|
|
32
|
+
export interface ChannelState {
|
|
33
|
+
channelId: string;
|
|
34
|
+
status: 'VOID' | 'INITIAL' | 'ACTIVE' | 'DISPUTE' | 'FINAL';
|
|
35
|
+
chainId: number;
|
|
36
|
+
token: string;
|
|
37
|
+
allocations: ChannelAllocation[];
|
|
38
|
+
stateVersion: number;
|
|
39
|
+
stateIntent: string;
|
|
40
|
+
stateHash?: string;
|
|
41
|
+
adjudicator: string;
|
|
42
|
+
challengePeriod: number;
|
|
43
|
+
challengeExpiration?: number;
|
|
44
|
+
createdAt: number;
|
|
45
|
+
updatedAt: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A single allocation within a state channel, mapping a participant to a token amount.
|
|
49
|
+
* The `amount` field is a string representation of a BigInt for JSON compatibility (Requirement 11.5).
|
|
50
|
+
*/
|
|
51
|
+
export interface ChannelAllocation {
|
|
52
|
+
destination: string;
|
|
53
|
+
token: string;
|
|
54
|
+
amount: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A normalized solver quote received via ClearNode.
|
|
58
|
+
* All amount fields use string type for JSON compatibility.
|
|
59
|
+
*/
|
|
60
|
+
export interface YellowQuote {
|
|
61
|
+
solverId: string;
|
|
62
|
+
channelId: string;
|
|
63
|
+
amountIn: string;
|
|
64
|
+
amountOut: string;
|
|
65
|
+
estimatedTime: number;
|
|
66
|
+
timestamp: number;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The outcome of an offchain clearing operation.
|
|
70
|
+
* Contains matched orders and net settlement amounts.
|
|
71
|
+
*/
|
|
72
|
+
export interface ClearingResult {
|
|
73
|
+
channelId: string;
|
|
74
|
+
matchedAmountIn: string;
|
|
75
|
+
matchedAmountOut: string;
|
|
76
|
+
netSettlement: string;
|
|
77
|
+
settlementProof?: SettlementProof;
|
|
78
|
+
timestamp: number;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* On-chain evidence of a completed settlement.
|
|
82
|
+
* Includes the final state hash, participant signatures, and optional transaction hash.
|
|
83
|
+
*/
|
|
84
|
+
export interface SettlementProof {
|
|
85
|
+
stateHash: string;
|
|
86
|
+
signatures: string[];
|
|
87
|
+
txHash?: string;
|
|
88
|
+
finalAllocations: ChannelAllocation[];
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Result of a ClearNode connection and authentication attempt.
|
|
92
|
+
*/
|
|
93
|
+
export interface YellowConnectionResult {
|
|
94
|
+
connected: boolean;
|
|
95
|
+
sessionAddress?: string;
|
|
96
|
+
fallback?: YellowFallback;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Result of a channel lifecycle operation (create, resize, close, or query).
|
|
100
|
+
*/
|
|
101
|
+
export interface YellowChannelResult {
|
|
102
|
+
channelId?: string;
|
|
103
|
+
state?: ChannelState;
|
|
104
|
+
txHash?: string;
|
|
105
|
+
fallback?: YellowFallback;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Result of an offchain transfer operation.
|
|
109
|
+
*/
|
|
110
|
+
export interface YellowTransferResult {
|
|
111
|
+
success: boolean;
|
|
112
|
+
updatedAllocations?: ChannelAllocation[];
|
|
113
|
+
fallback?: YellowFallback;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Result of executing an intent via Yellow Network clearing.
|
|
117
|
+
* The `provider` field indicates whether Yellow or a fallback provider handled the intent.
|
|
118
|
+
*/
|
|
119
|
+
export interface YellowExecutionResult {
|
|
120
|
+
provider: 'yellow' | 'fallback';
|
|
121
|
+
intentId?: string;
|
|
122
|
+
quote?: YellowQuote;
|
|
123
|
+
clearing?: ClearingResult;
|
|
124
|
+
channelId?: string;
|
|
125
|
+
timestamp: number;
|
|
126
|
+
fallback?: YellowFallback;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Result of querying the list of channels and their balances.
|
|
130
|
+
*/
|
|
131
|
+
export interface YellowChannelsResult {
|
|
132
|
+
channels: ChannelState[];
|
|
133
|
+
fallback?: YellowFallback;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Events emitted by the YellowProvider during its lifecycle.
|
|
137
|
+
*/
|
|
138
|
+
export type YellowEvent = 'connected' | 'disconnected' | 'channel_created' | 'channel_resized' | 'channel_closed' | 'transfer_completed' | 'quote_received' | 'clearing_completed' | 'error';
|
|
139
|
+
/**
|
|
140
|
+
* Handler function for YellowProvider events.
|
|
141
|
+
*/
|
|
142
|
+
export type YellowEventHandler = (data: unknown) => void;
|
|
143
|
+
/**
|
|
144
|
+
* Parameters for creating a new state channel.
|
|
145
|
+
*/
|
|
146
|
+
export interface CreateChannelParams {
|
|
147
|
+
chainId: number;
|
|
148
|
+
token: string;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Parameters for resizing a channel's allocations.
|
|
152
|
+
* The `allocateAmount` field is a string representation of a BigInt for JSON compatibility.
|
|
153
|
+
*/
|
|
154
|
+
export interface ResizeChannelParams {
|
|
155
|
+
channelId: string;
|
|
156
|
+
allocateAmount: string;
|
|
157
|
+
fundsDestination?: string;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Parameters for closing a state channel.
|
|
161
|
+
*/
|
|
162
|
+
export interface CloseChannelParams {
|
|
163
|
+
channelId: string;
|
|
164
|
+
withdraw?: boolean;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Parameters for sending an offchain transfer through a state channel.
|
|
168
|
+
* Allocation amounts are string representations of BigInt for JSON compatibility.
|
|
169
|
+
*/
|
|
170
|
+
export interface TransferParams {
|
|
171
|
+
destination: string;
|
|
172
|
+
allocations: Array<{
|
|
173
|
+
asset: string;
|
|
174
|
+
amount: string;
|
|
175
|
+
}>;
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @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AC,EAAE,WAAW,CAAC;IACpB,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,YAAY,EAAE,CAAC;IACzB,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B;AAMD;;GAEG;AACH,MAAM,MAAM,WAAW,GACnB,WAAW,GACX,cAAc,GACd,iBAAiB,GACjB,iBAAiB,GACjB,gBAAgB,GAChB,oBAAoB,GACpB,gBAAgB,GAChB,oBAAoB,GACpB,OAAO,CAAC;AAEZ;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;AAMzD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACvD"}
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* YellowProvider - Main entry point for Yellow Network operations
|
|
3
|
+
*
|
|
4
|
+
* Orchestrates session management, channel lifecycle, clearing, and event mapping.
|
|
5
|
+
* Follows the same standalone-class pattern as LifiProvider.
|
|
6
|
+
*
|
|
7
|
+
* Key design decisions:
|
|
8
|
+
* - Constructor MAY throw if NitroliteClient initialization fails
|
|
9
|
+
* - All other public methods return result objects (never throw)
|
|
10
|
+
* - WebSocket connection management is encapsulated in ClearNodeConnection
|
|
11
|
+
* - Session key management is handled internally via SessionKeyManager
|
|
12
|
+
*
|
|
13
|
+
* Requirements: 1.1, 1.2, 1.3, 1.4, 1.5, 1.8, 10.1
|
|
14
|
+
*/
|
|
15
|
+
import type { WalletClient, PublicClient } from 'viem';
|
|
16
|
+
import type { IntentParams } from '../types.js';
|
|
17
|
+
import type { YellowConnectionResult, YellowChannelResult, YellowTransferResult, YellowExecutionResult, YellowChannelsResult, YellowEvent, YellowEventHandler, YellowProviderStatus, YellowReasonCode, CreateChannelParams, ResizeChannelParams, CloseChannelParams, TransferParams } from './types.js';
|
|
18
|
+
/**
|
|
19
|
+
* Centralized error-to-reason-code mapping for all YellowProvider methods.
|
|
20
|
+
*
|
|
21
|
+
* Classifies an unknown error into the appropriate YellowReasonCode based on
|
|
22
|
+
* the error message content. This ensures consistent error classification
|
|
23
|
+
* across all provider methods.
|
|
24
|
+
*
|
|
25
|
+
* Mapping rules (Requirements 13.1, 13.2, 13.3, 13.4, 13.5):
|
|
26
|
+
* - WebSocket errors → YELLOW_UNAVAILABLE
|
|
27
|
+
* - On-chain transaction reverts → YELLOW_TX_FAILED
|
|
28
|
+
* - Authentication failures → YELLOW_AUTH_FAILED
|
|
29
|
+
* - Message timeouts → YELLOW_TIMEOUT
|
|
30
|
+
* - ClearNode unavailable / all reconnection attempts exhausted → YELLOW_UNAVAILABLE
|
|
31
|
+
*
|
|
32
|
+
* @param error - The error to classify (may be Error, string, or unknown)
|
|
33
|
+
* @returns The appropriate YellowReasonCode for the error
|
|
34
|
+
*/
|
|
35
|
+
export declare function mapErrorToReasonCode(error: unknown): YellowReasonCode;
|
|
36
|
+
/**
|
|
37
|
+
* Extract a revert reason from an on-chain transaction error, if available.
|
|
38
|
+
*
|
|
39
|
+
* Attempts to parse the revert reason from common error formats produced by
|
|
40
|
+
* viem and other Ethereum libraries.
|
|
41
|
+
*
|
|
42
|
+
* @param error - The error to extract the revert reason from
|
|
43
|
+
* @returns The revert reason string, or undefined if not found
|
|
44
|
+
*/
|
|
45
|
+
export declare function extractRevertReason(error: unknown): string | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Local stub interface for @erc7824/nitrolite NitroliteClient.
|
|
48
|
+
*
|
|
49
|
+
* This captures the expected API surface of the NitroliteClient from the
|
|
50
|
+
* @erc7824/nitrolite package. The real package is NOT installed; this stub
|
|
51
|
+
* allows the code to be structurally correct and ready to swap in the real
|
|
52
|
+
* package later.
|
|
53
|
+
*/
|
|
54
|
+
export interface NitroliteClientConfig {
|
|
55
|
+
publicClient: PublicClient;
|
|
56
|
+
walletClient: WalletClient;
|
|
57
|
+
custodyAddress: `0x${string}`;
|
|
58
|
+
adjudicatorAddress: `0x${string}`;
|
|
59
|
+
challengeDuration: bigint;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Stub NitroliteClient class.
|
|
63
|
+
*
|
|
64
|
+
* Provides the constructor interface expected by the real @erc7824/nitrolite package.
|
|
65
|
+
* Channel lifecycle methods (createChannel, resizeChannel, closeChannel) are stubs
|
|
66
|
+
* that will be replaced when the real package is installed.
|
|
67
|
+
*/
|
|
68
|
+
export declare class NitroliteClient {
|
|
69
|
+
readonly config: NitroliteClientConfig;
|
|
70
|
+
constructor(config: NitroliteClientConfig);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Configuration object for initializing the YellowProvider.
|
|
74
|
+
*
|
|
75
|
+
* Requirement 1.8: Accepts fields for ClearNode WebSocket URL, custody contract address,
|
|
76
|
+
* adjudicator contract address, chain ID, challenge duration, RPC URL, and session expiry.
|
|
77
|
+
*/
|
|
78
|
+
export interface YellowConfig {
|
|
79
|
+
/** ClearNode WebSocket URL. Default: "wss://clearnet-sandbox.yellow.com/ws" */
|
|
80
|
+
clearNodeUrl?: string;
|
|
81
|
+
/** Custody contract address (required) */
|
|
82
|
+
custodyAddress: `0x${string}`;
|
|
83
|
+
/** Adjudicator contract address (required) */
|
|
84
|
+
adjudicatorAddress: `0x${string}`;
|
|
85
|
+
/** Chain ID for on-chain operations (required) */
|
|
86
|
+
chainId: number;
|
|
87
|
+
/** RPC URL for the chain (optional, used to create a PublicClient if needed) */
|
|
88
|
+
rpcUrl?: string;
|
|
89
|
+
/** Challenge period in seconds. Default: 3600 */
|
|
90
|
+
challengeDuration?: number;
|
|
91
|
+
/** Session key expiry in seconds. Default: 3600 */
|
|
92
|
+
sessionExpiry?: number;
|
|
93
|
+
/** WebSocket message timeout in ms. Default: 30000 */
|
|
94
|
+
messageTimeout?: number;
|
|
95
|
+
/** Max WebSocket reconnection attempts. Default: 5 */
|
|
96
|
+
maxReconnectAttempts?: number;
|
|
97
|
+
/** Initial reconnection delay in ms. Default: 1000 */
|
|
98
|
+
reconnectDelay?: number;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Main provider class for Yellow Network operations.
|
|
102
|
+
*
|
|
103
|
+
* Orchestrates session management, channel lifecycle, clearing, and event mapping.
|
|
104
|
+
* The constructor initializes the NitroliteClient with viem clients and contract addresses.
|
|
105
|
+
* The connect() method establishes the WebSocket and completes the auth handshake.
|
|
106
|
+
*
|
|
107
|
+
* Requirements: 1.1, 1.2, 1.3, 1.4, 1.5, 1.8, 10.1
|
|
108
|
+
*/
|
|
109
|
+
export declare class YellowProvider {
|
|
110
|
+
private readonly nitroliteClient;
|
|
111
|
+
private readonly walletClient;
|
|
112
|
+
private readonly publicClient;
|
|
113
|
+
private readonly config;
|
|
114
|
+
private connection;
|
|
115
|
+
private sessionManager;
|
|
116
|
+
private channelStateManager;
|
|
117
|
+
private readonly eventHandlers;
|
|
118
|
+
private _status;
|
|
119
|
+
/**
|
|
120
|
+
* Creates a new YellowProvider instance.
|
|
121
|
+
*
|
|
122
|
+
* Requirement 1.1: Initialize NitroliteClient with custody/adjudicator addresses and viem clients.
|
|
123
|
+
* Requirement 1.2: Default clearNodeUrl to "wss://clearnet-sandbox.yellow.com/ws".
|
|
124
|
+
* Requirement 1.3: Convert challengeDuration to BigInt when passing to NitroliteClient.
|
|
125
|
+
* Requirement 1.4: Default challengeDuration to 3600 seconds.
|
|
126
|
+
* Requirement 1.5: Throw descriptive error if NitroliteClient initialization fails.
|
|
127
|
+
* Requirement 1.8: Accept all YellowConfig fields.
|
|
128
|
+
*
|
|
129
|
+
* @param config - Yellow Network configuration
|
|
130
|
+
* @param walletClient - viem WalletClient for signing transactions and EIP-712 messages
|
|
131
|
+
* @throws Error if NitroliteClient initialization fails
|
|
132
|
+
*/
|
|
133
|
+
constructor(config: YellowConfig, walletClient: WalletClient);
|
|
134
|
+
/**
|
|
135
|
+
* Connect to ClearNode and authenticate.
|
|
136
|
+
*
|
|
137
|
+
* Establishes a WebSocket connection via ClearNodeConnection, then authenticates
|
|
138
|
+
* using SessionKeyManager with the configured session expiry.
|
|
139
|
+
*
|
|
140
|
+
* Requirement 10.1: Establish WebSocket connection and emit connected event.
|
|
141
|
+
*
|
|
142
|
+
* @returns Connection result with session address on success, or fallback on failure
|
|
143
|
+
*/
|
|
144
|
+
connect(): Promise<YellowConnectionResult>;
|
|
145
|
+
/**
|
|
146
|
+
* Disconnect from ClearNode and clean up all resources.
|
|
147
|
+
*
|
|
148
|
+
* Closes the WebSocket connection, invalidates the session, clears channel state,
|
|
149
|
+
* and removes all event handlers from internal components.
|
|
150
|
+
*
|
|
151
|
+
* Requirement 10.4: Close WebSocket and clean up all pending message handlers.
|
|
152
|
+
*/
|
|
153
|
+
disconnect(): Promise<void>;
|
|
154
|
+
/**
|
|
155
|
+
* Check if the provider is connected and authenticated.
|
|
156
|
+
*/
|
|
157
|
+
get isConnected(): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Get the current provider status.
|
|
160
|
+
*/
|
|
161
|
+
get status(): YellowProviderStatus;
|
|
162
|
+
/**
|
|
163
|
+
* Register an event listener for YellowProvider events.
|
|
164
|
+
*
|
|
165
|
+
* @param event - The event type to listen for
|
|
166
|
+
* @param handler - The handler function to call when the event fires
|
|
167
|
+
*/
|
|
168
|
+
on(event: YellowEvent, handler: YellowEventHandler): void;
|
|
169
|
+
/**
|
|
170
|
+
* Remove an event listener.
|
|
171
|
+
*
|
|
172
|
+
* @param event - The event type to stop listening for
|
|
173
|
+
* @param handler - The handler function to remove
|
|
174
|
+
*/
|
|
175
|
+
off(event: YellowEvent, handler: YellowEventHandler): void;
|
|
176
|
+
/**
|
|
177
|
+
* Create a new state channel.
|
|
178
|
+
*
|
|
179
|
+
* Two-phase operation:
|
|
180
|
+
* 1. Send create_channel message to ClearNode via sendAndWait
|
|
181
|
+
* 2. Submit channel creation on-chain via NitroliteClient (simulated)
|
|
182
|
+
*
|
|
183
|
+
* After success, updates the ChannelStateManager cache and emits channel_created.
|
|
184
|
+
*
|
|
185
|
+
* Requirements: 3.1, 3.2, 3.3, 3.4, 3.5
|
|
186
|
+
*
|
|
187
|
+
* @param params - Channel creation parameters (chainId, token)
|
|
188
|
+
* @returns YellowChannelResult with channelId, state, and txHash on success; fallback on failure
|
|
189
|
+
*/
|
|
190
|
+
createChannel(params: CreateChannelParams): Promise<YellowChannelResult>;
|
|
191
|
+
/**
|
|
192
|
+
* Resize a channel's allocations.
|
|
193
|
+
*
|
|
194
|
+
* Two-phase operation:
|
|
195
|
+
* 1. Send resize_channel message to ClearNode via sendAndWait
|
|
196
|
+
* 2. Submit resize on-chain via NitroliteClient (simulated)
|
|
197
|
+
*
|
|
198
|
+
* After success, updates the ChannelStateManager cache and emits channel_resized.
|
|
199
|
+
*
|
|
200
|
+
* Requirements: 4.1, 4.2, 4.3, 4.4, 4.5
|
|
201
|
+
*
|
|
202
|
+
* @param params - Resize parameters (channelId, allocateAmount, optional fundsDestination)
|
|
203
|
+
* @returns YellowChannelResult with updated state on success; fallback on failure
|
|
204
|
+
*/
|
|
205
|
+
resizeChannel(params: ResizeChannelParams): Promise<YellowChannelResult>;
|
|
206
|
+
/**
|
|
207
|
+
* Close a channel and optionally withdraw funds.
|
|
208
|
+
*
|
|
209
|
+
* Two-phase operation:
|
|
210
|
+
* 1. Send close_channel message to ClearNode via sendAndWait
|
|
211
|
+
* 2. Submit close on-chain via NitroliteClient (simulated)
|
|
212
|
+
* 3. Optionally call custody withdrawal for the channel's tokens
|
|
213
|
+
*
|
|
214
|
+
* After success, updates the ChannelStateManager cache and emits channel_closed.
|
|
215
|
+
*
|
|
216
|
+
* Requirements: 5.1, 5.2, 5.3, 5.4, 5.5
|
|
217
|
+
*
|
|
218
|
+
* @param params - Close parameters (channelId, optional withdraw flag defaulting to true)
|
|
219
|
+
* @returns YellowChannelResult with FINAL status on success; fallback on failure
|
|
220
|
+
*/
|
|
221
|
+
closeChannel(params: CloseChannelParams): Promise<YellowChannelResult>;
|
|
222
|
+
/**
|
|
223
|
+
* Send an offchain transfer through an open state channel.
|
|
224
|
+
*
|
|
225
|
+
* Validates the transfer amount against the sender's channel allocation,
|
|
226
|
+
* sends a signed transfer message to ClearNode, and returns the updated allocations.
|
|
227
|
+
*
|
|
228
|
+
* Requirements: 6.1, 6.2, 6.3, 6.4
|
|
229
|
+
*
|
|
230
|
+
* @param params - Transfer parameters (destination, allocations with asset/amount)
|
|
231
|
+
* @returns YellowTransferResult with success and updated allocations, or fallback on failure
|
|
232
|
+
*/
|
|
233
|
+
transfer(params: TransferParams): Promise<YellowTransferResult>;
|
|
234
|
+
/**
|
|
235
|
+
* Execute an intent via Yellow Network clearing.
|
|
236
|
+
*
|
|
237
|
+
* Validates the intent parameters, finds or creates a state channel for the
|
|
238
|
+
* intent's token/chain, submits the intent for solver matching via ClearNode,
|
|
239
|
+
* normalizes the solver quote into a YellowQuote, and returns a YellowExecutionResult
|
|
240
|
+
* with the clearing result on success.
|
|
241
|
+
*
|
|
242
|
+
* Requirements: 8.1, 8.2, 8.3, 8.4, 8.5
|
|
243
|
+
*
|
|
244
|
+
* @param params - Intent parameters (sourceChain, destinationChain, tokenIn, tokenOut, amountIn required)
|
|
245
|
+
* @returns YellowExecutionResult with clearing result on success; fallback on failure
|
|
246
|
+
*/
|
|
247
|
+
executeIntent(params: IntentParams): Promise<YellowExecutionResult>;
|
|
248
|
+
/**
|
|
249
|
+
* Query channel list and balances.
|
|
250
|
+
*
|
|
251
|
+
* When connected to ClearNode, sends a get_ledger_balances message and parses
|
|
252
|
+
* the response into ChannelState objects, updating the local cache.
|
|
253
|
+
* When disconnected, falls back to the ChannelStateManager's cached data.
|
|
254
|
+
*
|
|
255
|
+
* Requirements: 7.1, 7.4
|
|
256
|
+
*
|
|
257
|
+
* @returns YellowChannelsResult with the list of channels
|
|
258
|
+
*/
|
|
259
|
+
getChannels(): Promise<YellowChannelsResult>;
|
|
260
|
+
/**
|
|
261
|
+
* Query a specific channel's on-chain state.
|
|
262
|
+
*
|
|
263
|
+
* Queries the on-chain custody contract via ChannelStateManager.queryOnChainBalances
|
|
264
|
+
* for authoritative balance data, and also checks the local cache for additional
|
|
265
|
+
* channel metadata.
|
|
266
|
+
*
|
|
267
|
+
* Requirements: 7.2, 7.3
|
|
268
|
+
*
|
|
269
|
+
* @param channelId - The channel identifier to query
|
|
270
|
+
* @returns YellowChannelResult with the channel state
|
|
271
|
+
*/
|
|
272
|
+
getChannelState(channelId: string): Promise<YellowChannelResult>;
|
|
273
|
+
/**
|
|
274
|
+
* Emit an event to all registered handlers.
|
|
275
|
+
*
|
|
276
|
+
* @param event - The event type to emit
|
|
277
|
+
* @param data - The data to pass to handlers
|
|
278
|
+
*/
|
|
279
|
+
private emit;
|
|
280
|
+
/**
|
|
281
|
+
* Simulate an on-chain transaction via NitroliteClient.
|
|
282
|
+
*
|
|
283
|
+
* Since NitroliteClient is a stub, this generates a deterministic transaction hash
|
|
284
|
+
* based on the operation and channel ID. In production, this would call the actual
|
|
285
|
+
* NitroliteClient methods (createChannel, resizeChannel, closeChannel, withdraw).
|
|
286
|
+
*
|
|
287
|
+
* @param operation - The on-chain operation name
|
|
288
|
+
* @param channelId - The channel identifier
|
|
289
|
+
* @returns A simulated transaction hash
|
|
290
|
+
*/
|
|
291
|
+
private simulateOnChainTransaction;
|
|
292
|
+
/**
|
|
293
|
+
* Get the internal NitroliteClient instance.
|
|
294
|
+
* Exposed for testing and advanced use cases.
|
|
295
|
+
*/
|
|
296
|
+
getNitroliteClient(): NitroliteClient;
|
|
297
|
+
/**
|
|
298
|
+
* Get the resolved configuration with defaults applied.
|
|
299
|
+
* Exposed for testing.
|
|
300
|
+
*/
|
|
301
|
+
getResolvedConfig(): Readonly<typeof this.config>;
|
|
302
|
+
}
|
|
303
|
+
//# sourceMappingURL=yellow-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yellow-provider.d.ts","sourceRoot":"","sources":["../../../src/yellow/yellow-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAMvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EACV,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,WAAW,EACX,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAKhB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACf,MAAM,YAAY,CAAC;AAUpB;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CA2ErE;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAiBtE;AAyDD;;;;;;;GAOG;AACH,MAAM,WAAW,qBAAqB;IACpC,YAAY,EAAE,YAA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