@farcaster/frame-sdk 0.0.6 → 0.0.8

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.
@@ -1,443 +1,8 @@
1
1
  import { Provider } from "ox";
2
- export declare const provider: {
3
- request: Provider.RequestFn<{
4
- Request: {
5
- method: "eth_accounts";
6
- params?: undefined;
7
- };
8
- ReturnType: readonly import("ox/_types/core/Address").Address[];
9
- } | {
10
- Request: {
11
- method: "eth_blobBaseFee";
12
- params?: undefined;
13
- };
14
- ReturnType: import("ox/_types/core/Hex").Hex;
15
- } | {
16
- Request: {
17
- method: "eth_blockNumber";
18
- params?: undefined;
19
- };
20
- ReturnType: import("ox/_types/core/Hex").Hex;
21
- } | {
22
- Request: {
23
- method: "eth_call";
24
- params: [transaction: import("ox/_types/core/TransactionRequest").Rpc] | [transaction: import("ox/_types/core/TransactionRequest").Rpc, block: import("ox/_types/core/Block").Number<import("ox/_types/core/Hex").Hex> | import("ox/_types/core/Block").Tag | import("ox/_types/core/Block").Hash] | [transaction: import("ox/_types/core/TransactionRequest").Rpc, block: import("ox/_types/core/Block").Number<import("ox/_types/core/Hex").Hex> | import("ox/_types/core/Block").Tag | import("ox/_types/core/Block").Hash, stateOverride: unknown];
25
- };
26
- ReturnType: import("ox/_types/core/Hex").Hex;
27
- } | {
28
- Request: {
29
- method: "eth_chainId";
30
- params?: undefined;
31
- };
32
- ReturnType: import("ox/_types/core/Hex").Hex;
33
- } | {
34
- Request: {
35
- method: "eth_coinbase";
36
- params?: undefined;
37
- };
38
- ReturnType: import("ox/_types/core/Address").Address;
39
- } | {
40
- Request: {
41
- method: "eth_estimateGas";
42
- params: [transaction: import("ox/_types/core/TransactionRequest").Rpc] | [transaction: import("ox/_types/core/TransactionRequest").Rpc, block: import("ox/_types/core/Block").Number<import("ox/_types/core/Hex").Hex> | import("ox/_types/core/Block").Tag | import("ox/_types/core/Block").Hash] | [transaction: import("ox/_types/core/TransactionRequest").Rpc, block: import("ox/_types/core/Block").Number<import("ox/_types/core/Hex").Hex> | import("ox/_types/core/Block").Tag | import("ox/_types/core/Block").Hash, stateOverride: unknown];
43
- };
44
- ReturnType: import("ox/_types/core/Hex").Hex;
45
- } | {
46
- Request: {
47
- method: "eth_feeHistory";
48
- params: [blockCount: import("ox/_types/core/Hex").Hex, newestBlock: import("ox/_types/core/Block").Number<import("ox/_types/core/Hex").Hex> | import("ox/_types/core/Block").Tag, rewardPercentiles: number[] | undefined];
49
- };
50
- ReturnType: import("ox/_types/core/Fee").FeeHistoryRpc;
51
- } | {
52
- Request: {
53
- method: "eth_gasPrice";
54
- params?: undefined;
55
- };
56
- ReturnType: import("ox/_types/core/Hex").Hex;
57
- } | {
58
- Request: {
59
- method: "eth_getBalance";
60
- params: [address: import("ox/_types/core/Address").Address, block: import("ox/_types/core/Block").Number<import("ox/_types/core/Hex").Hex> | import("ox/_types/core/Block").Tag | import("ox/_types/core/Block").Hash];
61
- };
62
- ReturnType: import("ox/_types/core/Hex").Hex;
63
- } | {
64
- Request: {
65
- method: "eth_getBlockByHash";
66
- params: [hash: import("ox/_types/core/Hex").Hex, includeTransactionObjects: boolean];
67
- };
68
- ReturnType: import("ox/_types/core/Block").Rpc | null;
69
- } | {
70
- Request: {
71
- method: "eth_getBlockByNumber";
72
- params: [block: import("ox/_types/core/Block").Number<import("ox/_types/core/Hex").Hex> | import("ox/_types/core/Block").Tag, includeTransactionObjects: boolean];
73
- };
74
- ReturnType: import("ox/_types/core/Block").Rpc | null;
75
- } | {
76
- Request: {
77
- method: "eth_getBlockTransactionCountByHash";
78
- params: [hash: import("ox/_types/core/Hex").Hex];
79
- };
80
- ReturnType: import("ox/_types/core/Hex").Hex;
81
- } | {
82
- Request: {
83
- method: "eth_getBlockTransactionCountByNumber";
84
- params: [block: import("ox/_types/core/Block").Number<import("ox/_types/core/Hex").Hex> | import("ox/_types/core/Block").Tag];
85
- };
86
- ReturnType: import("ox/_types/core/Hex").Hex;
87
- } | {
88
- Request: {
89
- method: "eth_getCode";
90
- params: [address: import("ox/_types/core/Address").Address, block: import("ox/_types/core/Block").Number<import("ox/_types/core/Hex").Hex> | import("ox/_types/core/Block").Tag | import("ox/_types/core/Block").Hash];
91
- };
92
- ReturnType: import("ox/_types/core/Hex").Hex;
93
- } | {
94
- Request: {
95
- method: "eth_getFilterChanges";
96
- params: [filterId: import("ox/_types/core/Hex").Hex];
97
- };
98
- ReturnType: readonly import("ox/_types/core/Log").Rpc[] | readonly import("ox/_types/core/Hex").Hex[];
99
- } | {
100
- Request: {
101
- method: "eth_getFilterLogs";
102
- params: [filterId: import("ox/_types/core/Hex").Hex];
103
- };
104
- ReturnType: readonly import("ox/_types/core/Log").Rpc[];
105
- } | {
106
- Request: {
107
- method: "eth_getLogs";
108
- params: [filter: import("ox/_types/core/Filter").Rpc];
109
- };
110
- ReturnType: readonly import("ox/_types/core/Log").Rpc[];
111
- } | {
112
- Request: {
113
- method: "eth_getProof";
114
- params: [address: import("ox/_types/core/Address").Address, storageKeys: import("ox/_types/core/Hex").Hex[], block: import("ox/_types/core/Block").Number<import("ox/_types/core/Hex").Hex> | import("ox/_types/core/Block").Tag | import("ox/_types/core/Block").Hash];
115
- };
116
- ReturnType: import("ox/_types/core/AccountProof").Rpc;
117
- } | {
118
- Request: {
119
- method: "eth_getStorageAt";
120
- params: [address: import("ox/_types/core/Address").Address, index: import("ox/_types/core/Hex").Hex, block: import("ox/_types/core/Block").Number<import("ox/_types/core/Hex").Hex> | import("ox/_types/core/Block").Tag | import("ox/_types/core/Block").Hash];
121
- };
122
- ReturnType: import("ox/_types/core/Hex").Hex;
123
- } | {
124
- Request: {
125
- method: "eth_getTransactionByBlockHashAndIndex";
126
- params: [hash: import("ox/_types/core/Hex").Hex, index: import("ox/_types/core/Hex").Hex];
127
- };
128
- ReturnType: import("ox/_types/core/Transaction").Rpc | null;
129
- } | {
130
- Request: {
131
- method: "eth_getTransactionByBlockNumberAndIndex";
132
- params: [block: import("ox/_types/core/Block").Number<import("ox/_types/core/Hex").Hex> | import("ox/_types/core/Block").Tag, index: import("ox/_types/core/Hex").Hex];
133
- };
134
- ReturnType: import("ox/_types/core/Transaction").Rpc | null;
135
- } | {
136
- Request: {
137
- method: "eth_getTransactionByHash";
138
- params: [hash: import("ox/_types/core/Hex").Hex];
139
- };
140
- ReturnType: import("ox/_types/core/Transaction").Rpc | null;
141
- } | {
142
- Request: {
143
- method: "eth_getTransactionCount";
144
- params: [address: import("ox/_types/core/Address").Address, block: import("ox/_types/core/Block").Number<import("ox/_types/core/Hex").Hex> | import("ox/_types/core/Block").Tag | import("ox/_types/core/Block").Hash];
145
- };
146
- ReturnType: import("ox/_types/core/Hex").Hex;
147
- } | {
148
- Request: {
149
- method: "eth_getTransactionReceipt";
150
- params: [hash: import("ox/_types/core/Hex").Hex];
151
- };
152
- ReturnType: import("ox/_types/core/TransactionReceipt").Rpc | null;
153
- } | {
154
- Request: {
155
- method: "eth_getUncleCountByBlockHash";
156
- params: [hash: import("ox/_types/core/Hex").Hex];
157
- };
158
- ReturnType: import("ox/_types/core/Hex").Hex;
159
- } | {
160
- Request: {
161
- method: "eth_getUncleCountByBlockNumber";
162
- params: [block: import("ox/_types/core/Block").Number<import("ox/_types/core/Hex").Hex> | import("ox/_types/core/Block").Tag];
163
- };
164
- ReturnType: import("ox/_types/core/Hex").Hex;
165
- } | {
166
- Request: {
167
- method: "eth_maxPriorityFeePerGas";
168
- params?: undefined;
169
- };
170
- ReturnType: import("ox/_types/core/Hex").Hex;
171
- } | {
172
- Request: {
173
- method: "eth_newBlockFilter";
174
- params?: undefined;
175
- };
176
- ReturnType: import("ox/_types/core/Hex").Hex;
177
- } | {
178
- Request: {
179
- method: "eth_newFilter";
180
- params: [filter: import("ox/_types/core/Filter").Rpc];
181
- };
182
- ReturnType: import("ox/_types/core/Hex").Hex;
183
- } | {
184
- Request: {
185
- method: "eth_newPendingTransactionFilter";
186
- params?: undefined;
187
- };
188
- ReturnType: import("ox/_types/core/Hex").Hex;
189
- } | {
190
- Request: {
191
- method: "eth_protocolVersion";
192
- params?: undefined;
193
- };
194
- ReturnType: string;
195
- } | {
196
- Request: {
197
- method: "eth_requestAccounts";
198
- params?: undefined;
199
- };
200
- ReturnType: readonly import("ox/_types/core/Address").Address[];
201
- } | {
202
- Request: {
203
- method: "eth_sendRawTransaction";
204
- params: [serializedTransaction: import("ox/_types/core/Hex").Hex];
205
- };
206
- ReturnType: import("ox/_types/core/Hex").Hex;
207
- } | {
208
- Request: {
209
- method: "eth_sendTransaction";
210
- params: [transaction: import("ox/_types/core/TransactionRequest").Rpc];
211
- };
212
- ReturnType: import("ox/_types/core/Hex").Hex;
213
- } | {
214
- Request: {
215
- method: "eth_signTransaction";
216
- params: [request: import("ox/_types/core/TransactionRequest").Rpc];
217
- };
218
- ReturnType: import("ox/_types/core/Hex").Hex;
219
- } | {
220
- Request: {
221
- method: "eth_signTypedData_v4";
222
- params: [address: import("ox/_types/core/Address").Address, message: string];
223
- };
224
- ReturnType: import("ox/_types/core/Hex").Hex;
225
- } | {
226
- Request: {
227
- method: "eth_uninstallFilter";
228
- params: [filterId: import("ox/_types/core/Hex").Hex];
229
- };
230
- ReturnType: boolean;
231
- } | {
232
- Request: {
233
- method: "eth_requestAccounts";
234
- params?: undefined;
235
- };
236
- ReturnType: readonly import("ox/_types/core/Address").Address[];
237
- } | {
238
- Request: {
239
- method: "eth_sendRawTransaction";
240
- params: [serializedTransaction: import("ox/_types/core/Hex").Hex];
241
- };
242
- ReturnType: import("ox/_types/core/Hex").Hex;
243
- } | {
244
- Request: {
245
- method: "eth_sendTransaction";
246
- params: [transaction: import("ox/_types/core/TransactionRequest").Rpc];
247
- };
248
- ReturnType: import("ox/_types/core/Hex").Hex;
249
- } | {
250
- Request: {
251
- method: "eth_signTransaction";
252
- params: [request: import("ox/_types/core/TransactionRequest").Rpc];
253
- };
254
- ReturnType: import("ox/_types/core/Hex").Hex;
255
- } | {
256
- Request: {
257
- method: "eth_signTypedData_v4";
258
- params: [address: import("ox/_types/core/Address").Address, message: string];
259
- };
260
- ReturnType: import("ox/_types/core/Hex").Hex;
261
- } | {
262
- Request: {
263
- method: "personal_sign";
264
- params: [data: import("ox/_types/core/Hex").Hex, address: import("ox/_types/core/Address").Address];
265
- };
266
- ReturnType: import("ox/_types/core/Hex").Hex;
267
- } | {
268
- Request: {
269
- method: "wallet_addEthereumChain";
270
- params: [chain: import("ox/_types/core/internal/types").Compute<{
271
- chainId: string;
272
- chainName: string;
273
- nativeCurrency?: {
274
- name: string;
275
- symbol: string;
276
- decimals: number;
277
- } | undefined;
278
- rpcUrls: readonly string[];
279
- blockExplorerUrls?: readonly string[] | undefined;
280
- iconUrls?: readonly string[] | undefined;
281
- }>];
282
- };
283
- ReturnType: null;
284
- } | {
285
- Request: {
286
- method: "wallet_getCallsStatus";
287
- params?: [string];
288
- };
289
- ReturnType: import("ox/_types/core/internal/types").Compute<{
290
- status: "PENDING" | "CONFIRMED";
291
- receipts?: readonly {
292
- logs: {
293
- address: import("ox/_types/core/Hex").Hex;
294
- data: import("ox/_types/core/Hex").Hex;
295
- topics: readonly import("ox/_types/core/Hex").Hex[];
296
- }[];
297
- status: import("ox/_types/core/Hex").Hex;
298
- blockHash: import("ox/_types/core/Hex").Hex;
299
- blockNumber: import("ox/_types/core/Hex").Hex;
300
- gasUsed: import("ox/_types/core/Hex").Hex;
301
- transactionHash: import("ox/_types/core/Hex").Hex;
302
- }[] | undefined;
303
- }>;
304
- } | {
305
- Request: {
306
- method: "wallet_getCapabilities";
307
- params?: [import("ox/_types/core/Address").Address];
308
- };
309
- ReturnType: import("ox/_types/core/internal/types").Compute<{
310
- [chainId: `0x${string}`]: {
311
- [capability: string]: any;
312
- };
313
- }>;
314
- } | {
315
- Request: {
316
- method: "wallet_getPermissions";
317
- params?: undefined;
318
- };
319
- ReturnType: readonly import("ox/_types/core/internal/types").Compute<{
320
- caveats: readonly {
321
- type: string;
322
- value: any;
323
- }[];
324
- date: number;
325
- id: string;
326
- invoker: `http://${string}` | `https://${string}`;
327
- parentCapability: "eth_accounts" | string;
328
- }>[];
329
- } | {
330
- Request: {
331
- method: "wallet_grantPermissions";
332
- params?: [{
333
- signer?: {
334
- type: string;
335
- data?: unknown | undefined;
336
- } | undefined;
337
- permissions: readonly {
338
- data: unknown;
339
- policies: readonly {
340
- data: unknown;
341
- type: string;
342
- }[];
343
- required?: boolean | undefined;
344
- type: string;
345
- }[];
346
- expiry: number;
347
- }];
348
- };
349
- ReturnType: import("ox/_types/core/internal/types").Compute<{
350
- expiry: number;
351
- factory?: `0x${string}` | undefined;
352
- factoryData?: string | undefined;
353
- grantedPermissions: readonly {
354
- data: unknown;
355
- policies: readonly {
356
- data: unknown;
357
- type: string;
358
- }[];
359
- required?: boolean | undefined;
360
- type: string;
361
- }[];
362
- permissionsContext: string;
363
- signerData?: {
364
- userOpBuilder?: `0x${string}` | undefined;
365
- submitToAddress?: `0x${string}` | undefined;
366
- } | undefined;
367
- }>;
368
- } | {
369
- Request: {
370
- method: "wallet_requestPermissions";
371
- params: [permissions: {
372
- eth_accounts: Record<string, any>;
373
- }];
374
- };
375
- ReturnType: readonly import("ox/_types/core/internal/types").Compute<{
376
- caveats: readonly {
377
- type: string;
378
- value: any;
379
- }[];
380
- date: number;
381
- id: string;
382
- invoker: `http://${string}` | `https://${string}`;
383
- parentCapability: "eth_accounts" | string;
384
- }>[];
385
- } | {
386
- Request: {
387
- method: "wallet_revokePermissions";
388
- params: [permissions: {
389
- eth_accounts: Record<string, any>;
390
- }];
391
- };
392
- ReturnType: null;
393
- } | {
394
- Request: {
395
- method: "wallet_sendCalls";
396
- params: import("ox/_types/core/internal/types").Compute<[{
397
- calls: readonly {
398
- to?: import("ox/_types/core/Address").Address | undefined;
399
- data?: import("ox/_types/core/Hex").Hex | undefined;
400
- value?: import("ox/_types/core/Hex").Hex | undefined;
401
- }[];
402
- capabilities?: {
403
- [capability: string]: any;
404
- } | undefined;
405
- chainId?: import("ox/_types/core/Hex").Hex | undefined;
406
- from: import("ox/_types/core/Address").Address;
407
- version: string;
408
- }]>;
409
- };
410
- ReturnType: string;
411
- } | {
412
- Request: {
413
- method: "wallet_showCallsStatus";
414
- params: [string];
415
- };
416
- ReturnType: undefined;
417
- } | {
418
- Request: {
419
- method: "wallet_switchEthereumChain";
420
- params: [chain: {
421
- chainId: string;
422
- }];
423
- };
424
- ReturnType: null;
425
- } | {
426
- Request: {
427
- method: "wallet_watchAsset";
428
- params: [import("ox/_types/core/internal/types").Compute<{
429
- type: "ERC20";
430
- options: {
431
- address: string;
432
- symbol: string;
433
- decimals: number;
434
- image?: string | undefined;
435
- };
436
- }>];
437
- };
438
- ReturnType: boolean;
439
- }>;
440
- on: Provider.EventListenerFn;
441
- removeListener: Provider.EventListenerFn;
2
+ type GenericProviderRpcError = {
3
+ code: number;
4
+ details?: string;
442
5
  };
443
- export type ProviderType = typeof provider;
6
+ export declare function toProviderRpcError({ code, details }: GenericProviderRpcError): Provider.ProviderRpcError;
7
+ export declare const provider: Provider.Provider;
8
+ export {};
package/dist/provider.js CHANGED
@@ -1,20 +1,55 @@
1
- import { Provider, RpcRequest } from "ox";
1
+ import { Provider, RpcRequest, RpcResponse } from "ox";
2
2
  import { frameHost } from "./frameHost";
3
3
  const emitter = Provider.createEmitter();
4
4
  const store = RpcRequest.createStore();
5
+ export function toProviderRpcError({ code, details }) {
6
+ switch (code) {
7
+ case 4001:
8
+ return new Provider.UserRejectedRequestError();
9
+ case 4100:
10
+ return new Provider.UnauthorizedError();
11
+ case 4200:
12
+ return new Provider.UnsupportedMethodError();
13
+ case 4900:
14
+ return new Provider.DisconnectedError();
15
+ case 4901:
16
+ return new Provider.ChainDisconnectedError();
17
+ default:
18
+ return new Provider.ProviderRpcError(code, details !== null && details !== void 0 ? details : 'Unknown provider RPC error');
19
+ }
20
+ }
5
21
  export const provider = Provider.from({
6
22
  ...emitter,
7
23
  async request(args) {
8
- return await frameHost.ethProviderRequest(
9
- // @ts-expect-error - from ox examples but our FetchFn needs better typing
10
- store.prepare(args));
11
- },
24
+ // @ts-expect-error
25
+ const request = store.prepare(args);
26
+ try {
27
+ const response = await frameHost.ethProviderRequestV2(request).then((res) => RpcResponse.parse(res, { request, raw: true }));
28
+ if (response.error) {
29
+ throw toProviderRpcError(response.error);
30
+ }
31
+ return response.result;
32
+ }
33
+ catch (e) {
34
+ // ethProviderRequestV2 not supported, fall back to v1
35
+ if (e instanceof Error && e.message.match(/cannot read property 'apply'/i)) {
36
+ return await frameHost.ethProviderRequest(request);
37
+ }
38
+ if (e instanceof Provider.ProviderRpcError ||
39
+ e instanceof RpcResponse.BaseError) {
40
+ throw e;
41
+ }
42
+ throw new RpcResponse.InternalError({ message: e instanceof Error ? e.message : undefined });
43
+ }
44
+ }
12
45
  });
13
46
  // Required to pass SSR
14
- if (typeof document !== 'undefined')
15
- document.addEventListener("FarcasterFrameEvent", (event) => {
47
+ if (typeof document !== 'undefined') {
48
+ document.addEventListener("FarcasterFrameEthProviderEvent", (event) => {
16
49
  if (event instanceof MessageEvent) {
17
- // TODO narrow to EventMap types and emit
18
- // emitter.emit(event.type as (keyof Provider.EventMap), event.data);
50
+ const ethProviderEvent = event.data;
51
+ // @ts-expect-error
52
+ emitter.emit(ethProviderEvent.event, ...ethProviderEvent.params);
19
53
  }
20
54
  });
55
+ }