@bananalink-sdk/protocol 1.2.7

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.
Files changed (158) hide show
  1. package/README.md +604 -0
  2. package/dist/chunk-32OWUOZ3.js +308 -0
  3. package/dist/chunk-32OWUOZ3.js.map +1 -0
  4. package/dist/chunk-65HNHRJK.cjs +123 -0
  5. package/dist/chunk-65HNHRJK.cjs.map +1 -0
  6. package/dist/chunk-7KYDLL3B.js +480 -0
  7. package/dist/chunk-7KYDLL3B.js.map +1 -0
  8. package/dist/chunk-A6FLEJ7R.cjs +62 -0
  9. package/dist/chunk-A6FLEJ7R.cjs.map +1 -0
  10. package/dist/chunk-CUJK7ZTS.js +217 -0
  11. package/dist/chunk-CUJK7ZTS.js.map +1 -0
  12. package/dist/chunk-GI3BUPIH.cjs +236 -0
  13. package/dist/chunk-GI3BUPIH.cjs.map +1 -0
  14. package/dist/chunk-JXHV66Q4.js +106 -0
  15. package/dist/chunk-JXHV66Q4.js.map +1 -0
  16. package/dist/chunk-KNGZKGRS.cjs +552 -0
  17. package/dist/chunk-KNGZKGRS.cjs.map +1 -0
  18. package/dist/chunk-LELPCIE7.js +840 -0
  19. package/dist/chunk-LELPCIE7.js.map +1 -0
  20. package/dist/chunk-MCZG7QEM.cjs +310 -0
  21. package/dist/chunk-MCZG7QEM.cjs.map +1 -0
  22. package/dist/chunk-TCVKC227.js +56 -0
  23. package/dist/chunk-TCVKC227.js.map +1 -0
  24. package/dist/chunk-VXLUSU5B.cjs +856 -0
  25. package/dist/chunk-VXLUSU5B.cjs.map +1 -0
  26. package/dist/chunk-WCQVDF3K.js +12 -0
  27. package/dist/chunk-WCQVDF3K.js.map +1 -0
  28. package/dist/chunk-WGEGR3DF.cjs +15 -0
  29. package/dist/chunk-WGEGR3DF.cjs.map +1 -0
  30. package/dist/client-session-claim-3QF3noOr.d.ts +197 -0
  31. package/dist/client-session-claim-C4lUik3b.d.cts +197 -0
  32. package/dist/core-DMhuNfoz.d.cts +62 -0
  33. package/dist/core-DMhuNfoz.d.ts +62 -0
  34. package/dist/crypto/providers/noble-provider.cjs +14 -0
  35. package/dist/crypto/providers/noble-provider.cjs.map +1 -0
  36. package/dist/crypto/providers/noble-provider.d.cts +30 -0
  37. package/dist/crypto/providers/noble-provider.d.ts +30 -0
  38. package/dist/crypto/providers/noble-provider.js +5 -0
  39. package/dist/crypto/providers/noble-provider.js.map +1 -0
  40. package/dist/crypto/providers/node-provider.cjs +308 -0
  41. package/dist/crypto/providers/node-provider.cjs.map +1 -0
  42. package/dist/crypto/providers/node-provider.d.cts +32 -0
  43. package/dist/crypto/providers/node-provider.d.ts +32 -0
  44. package/dist/crypto/providers/node-provider.js +306 -0
  45. package/dist/crypto/providers/node-provider.js.map +1 -0
  46. package/dist/crypto/providers/quickcrypto-provider.cjs +339 -0
  47. package/dist/crypto/providers/quickcrypto-provider.cjs.map +1 -0
  48. package/dist/crypto/providers/quickcrypto-provider.d.cts +34 -0
  49. package/dist/crypto/providers/quickcrypto-provider.d.ts +34 -0
  50. package/dist/crypto/providers/quickcrypto-provider.js +337 -0
  51. package/dist/crypto/providers/quickcrypto-provider.js.map +1 -0
  52. package/dist/crypto/providers/webcrypto-provider.cjs +310 -0
  53. package/dist/crypto/providers/webcrypto-provider.cjs.map +1 -0
  54. package/dist/crypto/providers/webcrypto-provider.d.cts +30 -0
  55. package/dist/crypto/providers/webcrypto-provider.d.ts +30 -0
  56. package/dist/crypto/providers/webcrypto-provider.js +308 -0
  57. package/dist/crypto/providers/webcrypto-provider.js.map +1 -0
  58. package/dist/crypto-BUS06Qz-.d.cts +40 -0
  59. package/dist/crypto-BUS06Qz-.d.ts +40 -0
  60. package/dist/crypto-export.cjs +790 -0
  61. package/dist/crypto-export.cjs.map +1 -0
  62. package/dist/crypto-export.d.cts +257 -0
  63. package/dist/crypto-export.d.ts +257 -0
  64. package/dist/crypto-export.js +709 -0
  65. package/dist/crypto-export.js.map +1 -0
  66. package/dist/crypto-provider-deYoVIxi.d.cts +36 -0
  67. package/dist/crypto-provider-deYoVIxi.d.ts +36 -0
  68. package/dist/index.cjs +615 -0
  69. package/dist/index.cjs.map +1 -0
  70. package/dist/index.d.cts +379 -0
  71. package/dist/index.d.ts +379 -0
  72. package/dist/index.js +504 -0
  73. package/dist/index.js.map +1 -0
  74. package/dist/schemas-export.cjs +294 -0
  75. package/dist/schemas-export.cjs.map +1 -0
  76. package/dist/schemas-export.d.cts +1598 -0
  77. package/dist/schemas-export.d.ts +1598 -0
  78. package/dist/schemas-export.js +5 -0
  79. package/dist/schemas-export.js.map +1 -0
  80. package/dist/siwe-export.cjs +237 -0
  81. package/dist/siwe-export.cjs.map +1 -0
  82. package/dist/siwe-export.d.cts +27 -0
  83. package/dist/siwe-export.d.ts +27 -0
  84. package/dist/siwe-export.js +228 -0
  85. package/dist/siwe-export.js.map +1 -0
  86. package/dist/testing.cjs +54 -0
  87. package/dist/testing.cjs.map +1 -0
  88. package/dist/testing.d.cts +20 -0
  89. package/dist/testing.d.ts +20 -0
  90. package/dist/testing.js +51 -0
  91. package/dist/testing.js.map +1 -0
  92. package/dist/validation-export.cjs +359 -0
  93. package/dist/validation-export.cjs.map +1 -0
  94. package/dist/validation-export.d.cts +3 -0
  95. package/dist/validation-export.d.ts +3 -0
  96. package/dist/validation-export.js +6 -0
  97. package/dist/validation-export.js.map +1 -0
  98. package/dist/validators-export.cjs +73 -0
  99. package/dist/validators-export.cjs.map +1 -0
  100. package/dist/validators-export.d.cts +37 -0
  101. package/dist/validators-export.d.ts +37 -0
  102. package/dist/validators-export.js +4 -0
  103. package/dist/validators-export.js.map +1 -0
  104. package/package.json +140 -0
  105. package/src/constants/index.ts +205 -0
  106. package/src/crypto/context.ts +228 -0
  107. package/src/crypto/diagnostics.ts +772 -0
  108. package/src/crypto/errors.ts +114 -0
  109. package/src/crypto/index.ts +89 -0
  110. package/src/crypto/payload-handler.ts +102 -0
  111. package/src/crypto/providers/compliance-provider.ts +579 -0
  112. package/src/crypto/providers/factory.ts +204 -0
  113. package/src/crypto/providers/index.ts +44 -0
  114. package/src/crypto/providers/noble-provider.ts +392 -0
  115. package/src/crypto/providers/node-provider.ts +433 -0
  116. package/src/crypto/providers/quickcrypto-provider.ts +483 -0
  117. package/src/crypto/providers/registry.ts +129 -0
  118. package/src/crypto/providers/webcrypto-provider.ts +364 -0
  119. package/src/crypto/session-security.ts +185 -0
  120. package/src/crypto/types.ts +93 -0
  121. package/src/crypto/utils.ts +190 -0
  122. package/src/crypto-export.ts +21 -0
  123. package/src/index.ts +38 -0
  124. package/src/schemas/auth.ts +60 -0
  125. package/src/schemas/client-messages.ts +57 -0
  126. package/src/schemas/core.ts +144 -0
  127. package/src/schemas/crypto.ts +65 -0
  128. package/src/schemas/discovery.ts +79 -0
  129. package/src/schemas/index.ts +239 -0
  130. package/src/schemas/relay-messages.ts +45 -0
  131. package/src/schemas/wallet-messages.ts +177 -0
  132. package/src/schemas-export.ts +23 -0
  133. package/src/siwe-export.ts +27 -0
  134. package/src/testing.ts +71 -0
  135. package/src/types/auth.ts +60 -0
  136. package/src/types/client-messages.ts +84 -0
  137. package/src/types/core.ts +131 -0
  138. package/src/types/crypto-provider.ts +264 -0
  139. package/src/types/crypto.ts +90 -0
  140. package/src/types/discovery.ts +50 -0
  141. package/src/types/errors.ts +87 -0
  142. package/src/types/index.ts +197 -0
  143. package/src/types/post-auth-operations.ts +363 -0
  144. package/src/types/providers.ts +72 -0
  145. package/src/types/relay-messages.ts +60 -0
  146. package/src/types/request-lifecycle.ts +161 -0
  147. package/src/types/signing-operations.ts +99 -0
  148. package/src/types/wallet-messages.ts +251 -0
  149. package/src/utils/client-session-claim.ts +188 -0
  150. package/src/utils/index.ts +54 -0
  151. package/src/utils/public-keys.ts +49 -0
  152. package/src/utils/siwe.ts +362 -0
  153. package/src/utils/url-decoding.ts +126 -0
  154. package/src/utils/url-encoding.ts +144 -0
  155. package/src/utils/wallet-session-claim.ts +188 -0
  156. package/src/validation-export.ts +32 -0
  157. package/src/validators/index.ts +222 -0
  158. package/src/validators-export.ts +8 -0
@@ -0,0 +1,197 @@
1
+ /**
2
+ * Core types for the BananaLink protocol
3
+ * Based on ERC-4361 SIWE format with BananaLink extensions
4
+ */
5
+
6
+ // Re-export QR Code payload from discovery types
7
+ export type { QRPayload } from './discovery';
8
+ // Re-export provider configuration types
9
+ export type {
10
+ ProviderType,
11
+ ProviderConfig,
12
+ ProviderConfigResponse,
13
+ UWebSocketConfig,
14
+ PusherConfig,
15
+ AblyConfig
16
+ } from './providers';
17
+
18
+ // Re-export v2.0 wallet message types
19
+ export type {
20
+ WalletSessionClaim,
21
+ WalletMessageEnvelope,
22
+ ClaimSessionPayload,
23
+ PrefetchMetadataPayload,
24
+ ConnectionRejectedPayload,
25
+ AuthenticateConnectionPayload,
26
+ WalletReconnectPayload,
27
+ WalletMessagePayload,
28
+ RejectionData,
29
+ AuthenticationData,
30
+ WalletMetadata,
31
+ WalletHandshakeMessage,
32
+ ConnectionRejectedMessage,
33
+ ConnectionAuthenticatedMessage,
34
+ RelayToDAppMessage,
35
+ PrefetchMetadataResponse,
36
+ } from './wallet-messages';
37
+
38
+ // Re-export v2.1+ request lifecycle types
39
+ export type {
40
+ BaseRequestMetadata,
41
+ BaseResponseMetadata,
42
+ BaseRejectionMetadata,
43
+ RequestRejectionReason,
44
+ RequestState,
45
+ } from './request-lifecycle';
46
+
47
+ export {
48
+ isValidRejectionReason,
49
+ } from './request-lifecycle';
50
+
51
+ // Re-export v2.1+ signing operation types
52
+ export type {
53
+ BaseSigningRequest,
54
+ BaseSigningResponse,
55
+ SigningRejection,
56
+ } from './signing-operations';
57
+
58
+ export {
59
+ isValidSignature,
60
+ isValidAddress,
61
+ } from './signing-operations';
62
+
63
+ // Re-export v2.1+ post-authentication operation types
64
+ export type {
65
+ SignMessageRequest,
66
+ SignMessageResponse,
67
+ SignTypedDataRequest,
68
+ SignTypedDataResponse,
69
+ EIP712Domain,
70
+ EIP712TypeDefinition,
71
+ SignTransactionRequest,
72
+ SignTransactionResponse,
73
+ LegacyTransaction,
74
+ EIP1559Transaction,
75
+ TransactionRequest,
76
+ AccessListEntry,
77
+ SignMessageRequestPayload,
78
+ SignTypedDataRequestPayload,
79
+ SignTransactionRequestPayload,
80
+ RequestFulfilledPayload,
81
+ RequestRejectedPayload,
82
+ RequestFulfilledData,
83
+ RequestRejectedData,
84
+ } from './post-auth-operations';
85
+
86
+ export {
87
+ isSignMessageRequest,
88
+ isSignTypedDataRequest,
89
+ isSignTransactionRequest,
90
+ isLegacyTransaction,
91
+ isEIP1559Transaction,
92
+ isSignMessageRequestPayload,
93
+ isSignTypedDataRequestPayload,
94
+ isSignTransactionRequestPayload,
95
+ isRequestFulfilledPayload,
96
+ isRequestRejectedPayload,
97
+ } from './post-auth-operations';
98
+
99
+ // Re-export wallet message type guards
100
+ export {
101
+ isClaimSessionPayload,
102
+ isPrefetchMetadataPayload,
103
+ isConnectionRejectedPayload,
104
+ isAuthenticateConnectionPayload,
105
+ isWalletReconnectPayload,
106
+ isWalletHandshakeMessage,
107
+ isConnectionRejectedMessage,
108
+ isConnectionAuthenticatedMessage,
109
+ } from './wallet-messages';
110
+
111
+ // Re-export v2.0 client message types
112
+ export type {
113
+ ClientSessionClaim,
114
+ ClientMessageEnvelope,
115
+ ClientReconnectPayload,
116
+ CloseSessionPayload,
117
+ ClientMessagePayload,
118
+ } from './client-messages';
119
+
120
+ // Re-export client message type guards
121
+ export {
122
+ isClientReconnectPayload,
123
+ isCloseSessionPayload,
124
+ } from './client-messages';
125
+
126
+ // Re-export v2.0 relay notification message types
127
+ export type {
128
+ SessionClosedAck,
129
+ SessionClosedNotification,
130
+ ReconnectedMessage,
131
+ RelayNotificationMessage,
132
+ } from './relay-messages';
133
+
134
+ // Re-export relay notification message type guards
135
+ export {
136
+ isSessionClosedAck,
137
+ isSessionClosedNotification,
138
+ isReconnectedMessage,
139
+ } from './relay-messages';
140
+
141
+ // Re-export core types from core.ts (Protocol v2.0 only)
142
+ export type {
143
+ SIWEFields,
144
+ DAppMetadata,
145
+ SessionConfig,
146
+ SessionOptions,
147
+ SecurityPolicy,
148
+ SessionMetadata,
149
+ CreateSessionRequest,
150
+ CreateSessionResponse,
151
+ } from './core';
152
+
153
+ // Re-export discovery and relay types
154
+ export type { RelayMessageType, EncryptedPayload, RelayMessage, DisplayInfo } from './discovery';
155
+
156
+ // Re-export auth types
157
+ export type { SessionState, SessionInfo, SessionSecurity, OriginProof } from './auth';
158
+
159
+ // Re-export error types
160
+ export type {
161
+ BananaLinkErrorCode,
162
+ WalletRejectionReason,
163
+ RelayRejectionReason,
164
+ RejectionReason,
165
+ } from './errors';
166
+
167
+ // Re-export crypto provider types
168
+ export type {
169
+ CryptoKeyLike,
170
+ KeyPairLike,
171
+ ProviderKeyPair,
172
+ CryptoProvider,
173
+ CryptoProviderFactory,
174
+ CryptoProviderType,
175
+ PlatformDetectionResult,
176
+ ProviderDetectionResult,
177
+ } from './crypto-provider';
178
+
179
+ // Re-export crypto runtime types
180
+ export type {
181
+ EncryptionAlgorithm,
182
+ EncryptedMessage,
183
+ KeyPair,
184
+ SessionKeys,
185
+ CryptoConfig,
186
+ CreatePayloadOptions,
187
+ } from '../crypto/types';
188
+
189
+ // Re-export crypto payload types (from crypto.ts)
190
+ export type {
191
+ KeyExchange,
192
+ Encryption,
193
+ PublicKeyJWK,
194
+ CryptoParameters,
195
+ KeyDerivation,
196
+ CryptoPayload,
197
+ } from './crypto';
@@ -0,0 +1,363 @@
1
+ /**
2
+ * Post-Authentication Operations Types for BananaLink Protocol v2.0
3
+ *
4
+ * This module defines concrete operation types for post-authentication requests:
5
+ * - Message signing (personal_sign)
6
+ * - Typed data signing (eth_signTypedData_v4)
7
+ * - Transaction signing (legacy + EIP-1559)
8
+ *
9
+ * All operations follow the request lifecycle defined in request-lifecycle.ts
10
+ */
11
+
12
+ import type { EncryptedPayload } from './discovery';
13
+ import type {
14
+ BaseSigningRequest,
15
+ BaseSigningResponse,
16
+ SigningRejection
17
+ } from './signing-operations';
18
+
19
+ /**
20
+ * ========================================
21
+ * MESSAGE SIGNING OPERATIONS
22
+ * ========================================
23
+ */
24
+
25
+ /**
26
+ * Personal sign request (personal_sign / eth_sign)
27
+ * Used for signing arbitrary messages
28
+ *
29
+ * Security Note: personal_sign is recommended over eth_sign
30
+ * eth_sign is dangerous and should only be used with explicit user consent
31
+ */
32
+ export interface SignMessageRequest extends BaseSigningRequest {
33
+ /**
34
+ * Message to sign (UTF-8 string or hex-encoded bytes)
35
+ * Wallet MUST display raw message to user
36
+ * @example "Sign this message to authenticate"
37
+ * @example "0x48656c6c6f20576f726c64" (hex-encoded "Hello World")
38
+ */
39
+ data: string;
40
+
41
+ /**
42
+ * Signing method
43
+ * - personal_sign: Prefixes message with "\x19Ethereum Signed Message:\n{length}"
44
+ * - eth_sign: Direct signing without prefix (DANGEROUS - wallet should warn user)
45
+ */
46
+ method: 'personal_sign';
47
+ }
48
+
49
+ /**
50
+ * Sign message response
51
+ */
52
+ export interface SignMessageResponse extends BaseSigningResponse {
53
+ /** Discriminator for union type matching */
54
+ requestType: 'sign_message';
55
+ }
56
+
57
+ /**
58
+ * ========================================
59
+ * TYPED DATA SIGNING OPERATIONS (EIP-712)
60
+ * ========================================
61
+ */
62
+
63
+ /**
64
+ * EIP-712 Domain Separator
65
+ * Defines the context for typed data signing
66
+ */
67
+ export interface EIP712Domain {
68
+ /** Human-readable name of signing domain */
69
+ name?: string;
70
+
71
+ /** Current version of signing domain */
72
+ version?: string;
73
+
74
+ /** Chain ID where signature is valid (EIP-155) */
75
+ chainId?: number;
76
+
77
+ /** Address of contract that will verify signature */
78
+ verifyingContract?: string;
79
+
80
+ /** Salt for domain separation (optional) */
81
+ salt?: string;
82
+ }
83
+
84
+ /**
85
+ * EIP-712 Type Definition
86
+ * Defines structure of a custom type
87
+ */
88
+ export interface EIP712TypeDefinition {
89
+ name: string;
90
+ type: string;
91
+ }
92
+
93
+ /**
94
+ * Typed data sign request (EIP-712)
95
+ * Used for structured data signing (permits, orders, etc.)
96
+ */
97
+ export interface SignTypedDataRequest extends BaseSigningRequest {
98
+ /**
99
+ * EIP-712 typed data object
100
+ * Wallet MUST validate structure and display human-readable form
101
+ */
102
+ data: {
103
+ /** Domain separator for signature context */
104
+ domain: EIP712Domain;
105
+
106
+ /** Type definitions (excluding EIP712Domain) */
107
+ types: Record<string, EIP712TypeDefinition[]>;
108
+
109
+ /** Primary type name (must be defined in types) */
110
+ primaryType: string;
111
+
112
+ /** Message data matching primaryType structure */
113
+ message: Record<string, unknown>;
114
+ };
115
+
116
+ /**
117
+ * Signing method version
118
+ * Only v4 supported (v1-v3 deprecated)
119
+ */
120
+ method: 'eth_signTypedData_v4';
121
+ }
122
+
123
+ /**
124
+ * Sign typed data response
125
+ */
126
+ export interface SignTypedDataResponse extends BaseSigningResponse {
127
+ /** Discriminator for union type matching */
128
+ requestType: 'sign_typed_data';
129
+ }
130
+
131
+ /**
132
+ * ========================================
133
+ * TRANSACTION SIGNING OPERATIONS
134
+ * ========================================
135
+ */
136
+
137
+ /**
138
+ * Transaction access list entry (EIP-2930)
139
+ * Specifies accounts and storage slots accessed by transaction
140
+ */
141
+ export interface AccessListEntry {
142
+ /** Account address */
143
+ address: string;
144
+
145
+ /** Storage keys accessed in this account */
146
+ storageKeys: string[];
147
+ }
148
+
149
+ /**
150
+ * Legacy transaction (pre-EIP-1559)
151
+ * Uses fixed gas price model
152
+ */
153
+ export interface LegacyTransaction {
154
+ /** Transaction type discriminator */
155
+ type: 'legacy';
156
+
157
+ /** Recipient address (0x-prefixed, 42 chars) */
158
+ to: string;
159
+
160
+ /** Value in wei (hex-encoded, 0x-prefixed) */
161
+ value: string;
162
+
163
+ /** Transaction data (hex-encoded, 0x-prefixed, optional) */
164
+ data?: string;
165
+
166
+ /** Transaction nonce (hex-encoded, 0x-prefixed) */
167
+ nonce: string;
168
+
169
+ /** Gas limit (hex-encoded, 0x-prefixed) */
170
+ gasLimit: string;
171
+
172
+ /** Gas price in wei (hex-encoded, 0x-prefixed) */
173
+ gasPrice: string;
174
+
175
+ /** Chain ID (EIP-155) */
176
+ chainId: number;
177
+ }
178
+
179
+ /**
180
+ * EIP-1559 transaction
181
+ * Uses base fee + priority fee model
182
+ */
183
+ export interface EIP1559Transaction {
184
+ /** Transaction type discriminator */
185
+ type: 'eip1559';
186
+
187
+ /** Recipient address */
188
+ to: string;
189
+
190
+ /** Value in wei (hex-encoded) */
191
+ value: string;
192
+
193
+ /** Transaction data (hex-encoded, optional) */
194
+ data?: string;
195
+
196
+ /** Transaction nonce (hex-encoded) */
197
+ nonce: string;
198
+
199
+ /** Gas limit (hex-encoded) */
200
+ gasLimit: string;
201
+
202
+ /** Max priority fee per gas in wei (hex-encoded) */
203
+ maxPriorityFeePerGas: string;
204
+
205
+ /** Max fee per gas in wei (hex-encoded) */
206
+ maxFeePerGas: string;
207
+
208
+ /** Chain ID (EIP-155) */
209
+ chainId: number;
210
+
211
+ /** Access list (EIP-2930, optional) */
212
+ accessList?: AccessListEntry[];
213
+ }
214
+
215
+ /**
216
+ * Transaction request union type
217
+ */
218
+ export type TransactionRequest = LegacyTransaction | EIP1559Transaction;
219
+
220
+ /**
221
+ * Sign transaction request
222
+ * Used for signing transactions (NOT broadcasting)
223
+ */
224
+ export interface SignTransactionRequest extends Omit<BaseSigningRequest, 'data'> {
225
+ /**
226
+ * Transaction parameters
227
+ * Wallet MUST validate all fields before signing
228
+ */
229
+ data: TransactionRequest;
230
+
231
+ /**
232
+ * Signing method (always eth_signTransaction)
233
+ */
234
+ method: 'eth_signTransaction';
235
+ }
236
+
237
+ /**
238
+ * Sign transaction response
239
+ */
240
+ export interface SignTransactionResponse extends BaseSigningResponse {
241
+ /** Discriminator for union type matching */
242
+ requestType: 'sign_transaction';
243
+
244
+ /**
245
+ * RLP-encoded signed transaction
246
+ * Format: 0x-prefixed hex string
247
+ * Can be broadcast to network via eth_sendRawTransaction
248
+ */
249
+ signedTransaction: string;
250
+ }
251
+
252
+ /**
253
+ * ========================================
254
+ * PAYLOAD TYPES (ENCRYPTED WRAPPERS)
255
+ * ========================================
256
+ */
257
+
258
+ /**
259
+ * Sign message request payload (dApp → Wallet)
260
+ */
261
+ export interface SignMessageRequestPayload {
262
+ type: 'sign_message_request';
263
+ encrypted: EncryptedPayload;
264
+ }
265
+
266
+ /**
267
+ * Sign typed data request payload (dApp → Wallet)
268
+ */
269
+ export interface SignTypedDataRequestPayload {
270
+ type: 'sign_typed_data_request';
271
+ encrypted: EncryptedPayload;
272
+ }
273
+
274
+ /**
275
+ * Sign transaction request payload (dApp → Wallet)
276
+ */
277
+ export interface SignTransactionRequestPayload {
278
+ type: 'sign_transaction_request';
279
+ encrypted: EncryptedPayload;
280
+ }
281
+
282
+ /**
283
+ * Request fulfilled response payload (Wallet → dApp)
284
+ * Used for all successful request completions
285
+ */
286
+ export interface RequestFulfilledPayload {
287
+ type: 'request_fulfilled';
288
+ encrypted: EncryptedPayload;
289
+ }
290
+
291
+ /**
292
+ * Request rejected response payload (Wallet → dApp)
293
+ * Used when wallet rejects a request
294
+ */
295
+ export interface RequestRejectedPayload {
296
+ type: 'request_rejected';
297
+ encrypted: EncryptedPayload;
298
+ }
299
+
300
+ /**
301
+ * Union type for request fulfilled data (decrypted)
302
+ */
303
+ export type RequestFulfilledData =
304
+ | SignMessageResponse
305
+ | SignTypedDataResponse
306
+ | SignTransactionResponse;
307
+
308
+ /**
309
+ * Request rejected data (decrypted)
310
+ */
311
+ export interface RequestRejectedData extends SigningRejection {
312
+ /** Original request type being rejected */
313
+ requestType: 'sign_message' | 'sign_typed_data' | 'sign_transaction';
314
+ }
315
+
316
+ /**
317
+ * ========================================
318
+ * TYPE GUARDS
319
+ * ========================================
320
+ */
321
+
322
+ export function isSignMessageRequest(req: unknown): req is SignMessageRequest {
323
+ const r = req as SignMessageRequest;
324
+ return r?.method === 'personal_sign' && typeof r?.data === 'string';
325
+ }
326
+
327
+ export function isSignTypedDataRequest(req: unknown): req is SignTypedDataRequest {
328
+ const r = req as SignTypedDataRequest;
329
+ return r?.method === 'eth_signTypedData_v4' && typeof r?.data === 'object';
330
+ }
331
+
332
+ export function isSignTransactionRequest(req: unknown): req is SignTransactionRequest {
333
+ const r = req as SignTransactionRequest;
334
+ return r?.method === 'eth_signTransaction' && typeof r?.data === 'object';
335
+ }
336
+
337
+ export function isLegacyTransaction(tx: TransactionRequest): tx is LegacyTransaction {
338
+ return tx.type === 'legacy';
339
+ }
340
+
341
+ export function isEIP1559Transaction(tx: TransactionRequest): tx is EIP1559Transaction {
342
+ return tx.type === 'eip1559';
343
+ }
344
+
345
+ export function isSignMessageRequestPayload(payload: unknown): payload is SignMessageRequestPayload {
346
+ return (payload as SignMessageRequestPayload)?.type === 'sign_message_request';
347
+ }
348
+
349
+ export function isSignTypedDataRequestPayload(payload: unknown): payload is SignTypedDataRequestPayload {
350
+ return (payload as SignTypedDataRequestPayload)?.type === 'sign_typed_data_request';
351
+ }
352
+
353
+ export function isSignTransactionRequestPayload(payload: unknown): payload is SignTransactionRequestPayload {
354
+ return (payload as SignTransactionRequestPayload)?.type === 'sign_transaction_request';
355
+ }
356
+
357
+ export function isRequestFulfilledPayload(payload: unknown): payload is RequestFulfilledPayload {
358
+ return (payload as RequestFulfilledPayload)?.type === 'request_fulfilled';
359
+ }
360
+
361
+ export function isRequestRejectedPayload(payload: unknown): payload is RequestRejectedPayload {
362
+ return (payload as RequestRejectedPayload)?.type === 'request_rejected';
363
+ }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Provider Configuration Types
3
+ * Types for transport provider configuration and management
4
+ */
5
+
6
+ /**
7
+ * Supported transport provider types (API response format)
8
+ * Note: 'uwebsockets' is maintained for API compatibility but SDKs normalize to 'websocket'
9
+ */
10
+ export type ProviderType = 'uwebsockets' | 'websocket' | 'pusher' | 'ably';
11
+
12
+ /**
13
+ * Base provider configuration
14
+ */
15
+ export interface ProviderConfig {
16
+ providerId: string;
17
+ type: ProviderType;
18
+ enabled: boolean;
19
+ priority: number;
20
+ config: UWebSocketConfig | PusherConfig | AblyConfig;
21
+ features?: string[];
22
+ }
23
+
24
+ /**
25
+ * Provider configuration response from API Gateway
26
+ */
27
+ export interface ProviderConfigResponse {
28
+ providers: ProviderConfig[];
29
+ ttl: number;
30
+ lastUpdated: string;
31
+ }
32
+
33
+ /**
34
+ * UWebSocket provider configuration
35
+ */
36
+ export interface UWebSocketConfig {
37
+ relayUrl: string;
38
+ maxConnections?: number;
39
+ reconnectInterval?: number;
40
+ heartbeatInterval?: number;
41
+ maxPayloadLength?: number;
42
+ idleTimeout?: number;
43
+ fallbackUrl?: string;
44
+ }
45
+
46
+ /**
47
+ * Pusher provider configuration
48
+ */
49
+ export interface PusherConfig {
50
+ appKey: string;
51
+ key?: string;
52
+ cluster: string;
53
+ encrypted?: boolean;
54
+ authEndpoint?: string;
55
+ useTLS?: boolean;
56
+ host?: string;
57
+ timeout?: number;
58
+ }
59
+
60
+ /**
61
+ * Ably provider configuration
62
+ */
63
+ export interface AblyConfig {
64
+ apiKey: string;
65
+ key?: string;
66
+ clientId?: string;
67
+ authUrl?: string;
68
+ environment?: string;
69
+ tls?: boolean;
70
+ timeout?: number;
71
+ clientOptions?: Record<string, unknown>;
72
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Relay notification message types for BananaLink protocol v2.0
3
+ * These are messages sent from relay server to clients/wallets
4
+ */
5
+
6
+ /**
7
+ * Session closed acknowledgment
8
+ * Sent to acknowledge a close_session request
9
+ */
10
+ export interface SessionClosedAck {
11
+ type: 'session_closed_ack';
12
+ timestamp: number;
13
+ }
14
+
15
+ /**
16
+ * Session closed notification
17
+ * Sent to notify the other party that peer closed the session
18
+ */
19
+ export interface SessionClosedNotification {
20
+ type: 'session_closed_notification';
21
+ /** Which party closed the session */
22
+ closedBy: 'client' | 'wallet';
23
+ /** Optional reason for closure */
24
+ reason?: string;
25
+ timestamp: number;
26
+ }
27
+
28
+ /**
29
+ * Reconnected confirmation message
30
+ * Sent after successful reconnection
31
+ */
32
+ export interface ReconnectedMessage {
33
+ type: 'reconnected';
34
+ /** Number of messages that were queued during disconnection */
35
+ queuedMessages: number;
36
+ timestamp: number;
37
+ }
38
+
39
+ /**
40
+ * Union type for relay notification messages
41
+ */
42
+ export type RelayNotificationMessage =
43
+ | SessionClosedAck
44
+ | SessionClosedNotification
45
+ | ReconnectedMessage;
46
+
47
+ /**
48
+ * Type guards for relay notification messages
49
+ */
50
+ export function isSessionClosedAck(message: RelayNotificationMessage): message is SessionClosedAck {
51
+ return message?.type === 'session_closed_ack';
52
+ }
53
+
54
+ export function isSessionClosedNotification(message: RelayNotificationMessage): message is SessionClosedNotification {
55
+ return message?.type === 'session_closed_notification';
56
+ }
57
+
58
+ export function isReconnectedMessage(message: RelayNotificationMessage): message is ReconnectedMessage {
59
+ return message?.type === 'reconnected';
60
+ }