@farcaster/frame-core 0.0.26 → 0.0.28

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 (42) hide show
  1. package/dist/actions/Ready.d.ts +13 -0
  2. package/dist/actions/Ready.js +6 -0
  3. package/dist/actions/Swap.d.ts +46 -0
  4. package/dist/actions/Swap.js +2 -0
  5. package/dist/actions/ViewToken.d.ts +4 -0
  6. package/dist/actions/ViewToken.js +2 -0
  7. package/dist/actions/index.d.ts +4 -1
  8. package/dist/actions/index.js +5 -2
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.js +1 -0
  11. package/dist/types.d.ts +16 -77
  12. package/dist/types.js +18 -3
  13. package/dist/wallet/ethereum.d.ts +43 -0
  14. package/dist/wallet/ethereum.js +2 -0
  15. package/dist/wallet/index.d.ts +1 -0
  16. package/dist/wallet/index.js +37 -0
  17. package/esm/actions/Ready.d.ts +13 -0
  18. package/esm/actions/Ready.js +3 -0
  19. package/esm/actions/Swap.d.ts +46 -0
  20. package/esm/actions/Swap.js +1 -0
  21. package/esm/actions/ViewToken.d.ts +4 -0
  22. package/esm/actions/ViewToken.js +1 -0
  23. package/esm/actions/index.d.ts +4 -1
  24. package/esm/actions/index.js +4 -1
  25. package/esm/index.d.ts +1 -0
  26. package/esm/index.js +1 -0
  27. package/esm/tsconfig.tsbuildinfo +1 -1
  28. package/esm/types.d.ts +16 -77
  29. package/esm/types.js +3 -3
  30. package/esm/wallet/ethereum.d.ts +43 -0
  31. package/esm/wallet/ethereum.js +1 -0
  32. package/esm/wallet/index.d.ts +1 -0
  33. package/esm/wallet/index.js +1 -0
  34. package/package.json +2 -2
  35. package/src/actions/Ready.ts +15 -0
  36. package/src/actions/Swap.ts +54 -0
  37. package/src/actions/ViewToken.ts +5 -0
  38. package/src/actions/index.ts +4 -1
  39. package/src/index.ts +1 -0
  40. package/src/types.ts +26 -100
  41. package/src/wallet/ethereum.ts +61 -0
  42. package/src/wallet/index.ts +1 -0
package/esm/types.d.ts CHANGED
@@ -1,63 +1,41 @@
1
- import type { Address, Provider, RpcRequest, RpcResponse, RpcSchema } from 'ox';
2
- import type { AddFrame, SignIn, ViewProfile } from './actions';
1
+ import type { AddFrame, Ready, SignIn, Swap, ViewProfile, ViewToken } from './actions';
3
2
  import type { FrameContext } from './context';
4
3
  import type { EventFrameAdded, EventFrameRemoved, EventNotificationsDisabled, EventNotificationsEnabled } from './schemas';
4
+ import type { Ethereum } from './wallet';
5
5
  export type SetPrimaryButtonOptions = {
6
6
  text: string;
7
7
  loading?: boolean;
8
8
  disabled?: boolean;
9
9
  hidden?: boolean;
10
10
  };
11
+ export * from './wallet/ethereum';
12
+ export { DEFAULT_READY_OPTIONS, ReadyOptions } from './actions/Ready';
13
+ export type SignInOptions = SignIn.SignInOptions;
11
14
  export type SetPrimaryButton = (options: SetPrimaryButtonOptions) => void;
12
- export type EthProviderRequest = Provider.RequestFn<RpcSchema.Default>;
13
- export type ReadyOptions = {
14
- /**
15
- * Disable native gestures. Use this option if your frame uses gestures
16
- * that conflict with native gestures.
17
- *
18
- * @defaultValue false
19
- */
20
- disableNativeGestures: boolean;
21
- };
22
- export declare const DEFAULT_READY_OPTIONS: ReadyOptions;
23
- export type SignInOptions = {
24
- /**
25
- * A random string used to prevent replay attacks.
26
- */
27
- nonce: string;
28
- /**
29
- * Start time at which the signature becomes valid.
30
- * ISO 8601 datetime.
31
- */
32
- notBefore?: string;
33
- /**
34
- * Expiration time at which the signature is no longer valid.
35
- * ISO 8601 datetime.
36
- */
37
- expirationTime?: string;
38
- };
39
15
  export type WireFrameHost = {
40
16
  context: FrameContext;
41
17
  close: () => void;
42
- ready: (options?: Partial<ReadyOptions>) => void;
18
+ ready: Ready.Ready;
43
19
  openUrl: (url: string) => void;
44
20
  signIn: SignIn.WireSignIn;
45
21
  setPrimaryButton: SetPrimaryButton;
46
- ethProviderRequest: EthProviderRequest;
47
- ethProviderRequestV2: RpcTransport;
22
+ ethProviderRequest: Ethereum.EthProvideRequest;
23
+ ethProviderRequestV2: Ethereum.RpcTransport;
48
24
  eip6963RequestProvider: () => void;
49
25
  addFrame: AddFrame.WireAddFrame;
50
26
  viewProfile: ViewProfile.ViewProfile;
27
+ viewToken: ViewToken.ViewToken;
28
+ swap: Swap.Swap;
51
29
  };
52
30
  export type FrameHost = {
53
31
  context: FrameContext;
54
32
  close: () => void;
55
- ready: (options?: Partial<ReadyOptions>) => void;
33
+ ready: Ready.Ready;
56
34
  openUrl: (url: string) => void;
57
35
  signIn: SignIn.SignIn;
58
36
  setPrimaryButton: SetPrimaryButton;
59
- ethProviderRequest: EthProviderRequest;
60
- ethProviderRequestV2: RpcTransport;
37
+ ethProviderRequest: Ethereum.EthProvideRequest;
38
+ ethProviderRequestV2: Ethereum.RpcTransport;
61
39
  /**
62
40
  * Receive forwarded eip6963:requestProvider events from the frame document.
63
41
  * Hosts must emit an EventEip6963AnnounceProvider in response.
@@ -65,35 +43,9 @@ export type FrameHost = {
65
43
  eip6963RequestProvider: () => void;
66
44
  addFrame: AddFrame.AddFrame;
67
45
  viewProfile: ViewProfile.ViewProfile;
46
+ viewToken: ViewToken.ViewToken;
47
+ swap: Swap.Swap;
68
48
  };
69
- export type FrameEthProviderEventData = {
70
- type: 'frame_eth_provider_event';
71
- } & EthProviderWireEvent;
72
- export type RpcTransport = (request: RpcRequest.RpcRequest) => Promise<RpcResponse.RpcResponse>;
73
- export type ProviderRpcError = {
74
- code: number;
75
- details?: string;
76
- message?: string;
77
- };
78
- export type EthProviderWireEvent = {
79
- event: 'accountsChanged';
80
- params: [readonly Address.Address[]];
81
- } | {
82
- event: 'chainChanged';
83
- params: [string];
84
- } | {
85
- event: 'connect';
86
- params: [Provider.ConnectInfo];
87
- } | {
88
- event: 'disconnect';
89
- params: [ProviderRpcError];
90
- } | {
91
- event: 'message';
92
- params: [Provider.Message];
93
- };
94
- export type EmitEthProvider = <event extends EthProviderWireEvent['event']>(event: event, params: Extract<EthProviderWireEvent, {
95
- event: event;
96
- }>['params']) => void;
97
49
  export type EventFrameAddRejected = {
98
50
  event: 'frame_add_rejected';
99
51
  reason: AddFrame.AddFrameRejectedReason;
@@ -101,17 +53,4 @@ export type EventFrameAddRejected = {
101
53
  export type EventPrimaryButtonClicked = {
102
54
  event: 'primary_button_clicked';
103
55
  };
104
- /**
105
- * Metadata of the EIP-1193 Provider.
106
- */
107
- export interface EIP6963ProviderInfo {
108
- icon: `data:image/${string}`;
109
- name: string;
110
- rdns: string;
111
- uuid: string;
112
- }
113
- export type EventEip6963AnnounceProvider = {
114
- event: 'eip6963:announceProvider';
115
- info: EIP6963ProviderInfo;
116
- };
117
- export type FrameClientEvent = EventFrameAdded | EventFrameAddRejected | EventFrameRemoved | EventNotificationsEnabled | EventNotificationsDisabled | EventPrimaryButtonClicked | EventEip6963AnnounceProvider;
56
+ export type FrameClientEvent = EventFrameAdded | EventFrameAddRejected | EventFrameRemoved | EventNotificationsEnabled | EventNotificationsDisabled | EventPrimaryButtonClicked | Ethereum.EventEip6963AnnounceProvider;
package/esm/types.js CHANGED
@@ -1,3 +1,3 @@
1
- export const DEFAULT_READY_OPTIONS = {
2
- disableNativeGestures: false,
3
- };
1
+ // start backwards compat, remove in 1.0
2
+ export * from './wallet/ethereum';
3
+ export { DEFAULT_READY_OPTIONS } from './actions/Ready';
@@ -0,0 +1,43 @@
1
+ import type { Address, Provider, RpcRequest, RpcResponse, RpcSchema } from 'ox';
2
+ export type EthProvideRequest<schema extends RpcSchema.Generic = RpcSchema.Default> = Provider.RequestFn<schema>;
3
+ export type FrameEthProviderEventData = {
4
+ type: 'frame_eth_provider_event';
5
+ } & EthProviderWireEvent;
6
+ export type RpcTransport = (request: RpcRequest.RpcRequest) => Promise<RpcResponse.RpcResponse>;
7
+ export type ProviderRpcError = {
8
+ code: number;
9
+ details?: string;
10
+ message?: string;
11
+ };
12
+ export type EthProviderWireEvent = {
13
+ event: 'accountsChanged';
14
+ params: [readonly Address.Address[]];
15
+ } | {
16
+ event: 'chainChanged';
17
+ params: [string];
18
+ } | {
19
+ event: 'connect';
20
+ params: [Provider.ConnectInfo];
21
+ } | {
22
+ event: 'disconnect';
23
+ params: [ProviderRpcError];
24
+ } | {
25
+ event: 'message';
26
+ params: [Provider.Message];
27
+ };
28
+ export type EmitEthProvider = <event extends EthProviderWireEvent['event']>(event: event, params: Extract<EthProviderWireEvent, {
29
+ event: event;
30
+ }>['params']) => void;
31
+ /**
32
+ * Metadata of the EIP-1193 Provider.
33
+ */
34
+ export interface EIP6963ProviderInfo {
35
+ icon: `data:image/${string}`;
36
+ name: string;
37
+ rdns: string;
38
+ uuid: string;
39
+ }
40
+ export type EventEip6963AnnounceProvider = {
41
+ event: 'eip6963:announceProvider';
42
+ info: EIP6963ProviderInfo;
43
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export * as Ethereum from './ethereum';
@@ -0,0 +1 @@
1
+ export * as Ethereum from './ethereum';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farcaster/frame-core",
3
- "version": "0.0.26",
3
+ "version": "0.0.28",
4
4
  "main": "dist/index.js",
5
5
  "module": "esm/index.js",
6
6
  "files": [
@@ -11,7 +11,7 @@
11
11
  "devDependencies": {
12
12
  "@vitest/coverage-v8": "^2.1.8",
13
13
  "typescript": "^5.7.2",
14
- "vitest": "^2.1.8",
14
+ "vitest": "^2.1.9",
15
15
  "@farcaster/tsconfig": "0.0.2"
16
16
  },
17
17
  "dependencies": {
@@ -0,0 +1,15 @@
1
+ export type ReadyOptions = {
2
+ /**
3
+ * Disable native gestures. Use this option if your frame uses gestures
4
+ * that conflict with native gestures.
5
+ *
6
+ * @defaultValue false
7
+ */
8
+ disableNativeGestures: boolean
9
+ }
10
+
11
+ export const DEFAULT_READY_OPTIONS = {
12
+ disableNativeGestures: false,
13
+ } satisfies ReadyOptions
14
+
15
+ export type Ready = (options?: Partial<ReadyOptions>) => void
@@ -0,0 +1,54 @@
1
+ export type SwapOptions = {
2
+ /**
3
+ * CAIP-19 asset ID
4
+ * For example, Base USDC:
5
+ * eip155:8453/erc20:0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
6
+ */
7
+ sellToken?: string
8
+
9
+ /**
10
+ * CAIP-19 token ID. For example, OP ETH:
11
+ * eip155:10/native
12
+ */
13
+ buyToken?: string
14
+
15
+ /**
16
+ * Sell token amount, as numeric string.
17
+ * For example, 10 USDC: 1000000
18
+ */
19
+ sellAmount?: string
20
+ }
21
+
22
+ type SwapDetails = {
23
+ /**
24
+ * Array of tx identifiers in order of execution.
25
+ * Some swaps will have both an approval and swap tx.
26
+ */
27
+ transactions: `0x${string}`[]
28
+ }
29
+
30
+ type SwapErrorDetails = {
31
+ /**
32
+ * Error code.
33
+ */
34
+ error: string
35
+ /**
36
+ * Error message.
37
+ */
38
+ message?: string
39
+ }
40
+
41
+ export type SwapErrorReason = 'rejected_by_user' | 'swap_failed'
42
+
43
+ export type SwapResult =
44
+ | {
45
+ success: true
46
+ swap: SwapDetails
47
+ }
48
+ | {
49
+ success: false
50
+ reason: SwapErrorReason
51
+ error?: SwapErrorDetails
52
+ }
53
+
54
+ export type Swap = (options: SwapOptions) => Promise<SwapResult>
@@ -0,0 +1,5 @@
1
+ export type ViewTokenOptions = {
2
+ token: string
3
+ }
4
+
5
+ export type ViewToken = (options: ViewTokenOptions) => Promise<void>
@@ -1,3 +1,6 @@
1
1
  export * as AddFrame from './AddFrame'
2
- export * as ViewProfile from './ViewProfile'
2
+ export * as Ready from './Ready'
3
3
  export * as SignIn from './SignIn'
4
+ export * as Swap from './Swap'
5
+ export * as ViewProfile from './ViewProfile'
6
+ export * as ViewToken from './ViewToken'
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './actions'
2
+ export * from './wallet'
2
3
  export * as Context from './context'
3
4
  export * from './types'
4
5
  export * from './schemas'
package/src/types.ts CHANGED
@@ -1,5 +1,11 @@
1
- import type { Address, Provider, RpcRequest, RpcResponse, RpcSchema } from 'ox'
2
- import type { AddFrame, SignIn, ViewProfile } from './actions'
1
+ import type {
2
+ AddFrame,
3
+ Ready,
4
+ SignIn,
5
+ Swap,
6
+ ViewProfile,
7
+ ViewToken,
8
+ } from './actions'
3
9
  import type { FrameContext } from './context'
4
10
  import type {
5
11
  EventFrameAdded,
@@ -7,6 +13,7 @@ import type {
7
13
  EventNotificationsDisabled,
8
14
  EventNotificationsEnabled,
9
15
  } from './schemas'
16
+ import type { Ethereum } from './wallet'
10
17
 
11
18
  export type SetPrimaryButtonOptions = {
12
19
  text: string
@@ -15,66 +22,39 @@ export type SetPrimaryButtonOptions = {
15
22
  hidden?: boolean
16
23
  }
17
24
 
18
- export type SetPrimaryButton = (options: SetPrimaryButtonOptions) => void
19
-
20
- export type EthProviderRequest = Provider.RequestFn<RpcSchema.Default>
21
-
22
- export type ReadyOptions = {
23
- /**
24
- * Disable native gestures. Use this option if your frame uses gestures
25
- * that conflict with native gestures.
26
- *
27
- * @defaultValue false
28
- */
29
- disableNativeGestures: boolean
30
- }
31
-
32
- export const DEFAULT_READY_OPTIONS: ReadyOptions = {
33
- disableNativeGestures: false,
34
- }
35
-
36
- export type SignInOptions = {
37
- /**
38
- * A random string used to prevent replay attacks.
39
- */
40
- nonce: string
41
-
42
- /**
43
- * Start time at which the signature becomes valid.
44
- * ISO 8601 datetime.
45
- */
46
- notBefore?: string
25
+ // start backwards compat, remove in 1.0
26
+ export * from './wallet/ethereum'
27
+ export { DEFAULT_READY_OPTIONS, ReadyOptions } from './actions/Ready'
28
+ export type SignInOptions = SignIn.SignInOptions
29
+ // end backwards compat
47
30
 
48
- /**
49
- * Expiration time at which the signature is no longer valid.
50
- * ISO 8601 datetime.
51
- */
52
- expirationTime?: string
53
- }
31
+ export type SetPrimaryButton = (options: SetPrimaryButtonOptions) => void
54
32
 
55
33
  export type WireFrameHost = {
56
34
  context: FrameContext
57
35
  close: () => void
58
- ready: (options?: Partial<ReadyOptions>) => void
36
+ ready: Ready.Ready
59
37
  openUrl: (url: string) => void
60
38
  signIn: SignIn.WireSignIn
61
39
  setPrimaryButton: SetPrimaryButton
62
- ethProviderRequest: EthProviderRequest
63
- ethProviderRequestV2: RpcTransport
40
+ ethProviderRequest: Ethereum.EthProvideRequest
41
+ ethProviderRequestV2: Ethereum.RpcTransport
64
42
  eip6963RequestProvider: () => void
65
43
  addFrame: AddFrame.WireAddFrame
66
44
  viewProfile: ViewProfile.ViewProfile
45
+ viewToken: ViewToken.ViewToken
46
+ swap: Swap.Swap
67
47
  }
68
48
 
69
49
  export type FrameHost = {
70
50
  context: FrameContext
71
51
  close: () => void
72
- ready: (options?: Partial<ReadyOptions>) => void
52
+ ready: Ready.Ready
73
53
  openUrl: (url: string) => void
74
54
  signIn: SignIn.SignIn
75
55
  setPrimaryButton: SetPrimaryButton
76
- ethProviderRequest: EthProviderRequest
77
- ethProviderRequestV2: RpcTransport
56
+ ethProviderRequest: Ethereum.EthProvideRequest
57
+ ethProviderRequestV2: Ethereum.RpcTransport
78
58
  /**
79
59
  * Receive forwarded eip6963:requestProvider events from the frame document.
80
60
  * Hosts must emit an EventEip6963AnnounceProvider in response.
@@ -82,49 +62,10 @@ export type FrameHost = {
82
62
  eip6963RequestProvider: () => void
83
63
  addFrame: AddFrame.AddFrame
84
64
  viewProfile: ViewProfile.ViewProfile
65
+ viewToken: ViewToken.ViewToken
66
+ swap: Swap.Swap
85
67
  }
86
68
 
87
- export type FrameEthProviderEventData = {
88
- type: 'frame_eth_provider_event'
89
- } & EthProviderWireEvent
90
-
91
- export type RpcTransport = (
92
- request: RpcRequest.RpcRequest,
93
- ) => Promise<RpcResponse.RpcResponse>
94
-
95
- export type ProviderRpcError = {
96
- code: number
97
- details?: string
98
- message?: string
99
- }
100
-
101
- export type EthProviderWireEvent =
102
- | {
103
- event: 'accountsChanged'
104
- params: [readonly Address.Address[]]
105
- }
106
- | {
107
- event: 'chainChanged'
108
- params: [string]
109
- }
110
- | {
111
- event: 'connect'
112
- params: [Provider.ConnectInfo]
113
- }
114
- | {
115
- event: 'disconnect'
116
- params: [ProviderRpcError]
117
- }
118
- | {
119
- event: 'message'
120
- params: [Provider.Message]
121
- }
122
-
123
- export type EmitEthProvider = <event extends EthProviderWireEvent['event']>(
124
- event: event,
125
- params: Extract<EthProviderWireEvent, { event: event }>['params'],
126
- ) => void
127
-
128
69
  export type EventFrameAddRejected = {
129
70
  event: 'frame_add_rejected'
130
71
  reason: AddFrame.AddFrameRejectedReason
@@ -134,21 +75,6 @@ export type EventPrimaryButtonClicked = {
134
75
  event: 'primary_button_clicked'
135
76
  }
136
77
 
137
- /**
138
- * Metadata of the EIP-1193 Provider.
139
- */
140
- export interface EIP6963ProviderInfo {
141
- icon: `data:image/${string}` // RFC-2397
142
- name: string
143
- rdns: string
144
- uuid: string
145
- }
146
-
147
- export type EventEip6963AnnounceProvider = {
148
- event: 'eip6963:announceProvider'
149
- info: EIP6963ProviderInfo
150
- }
151
-
152
78
  export type FrameClientEvent =
153
79
  | EventFrameAdded
154
80
  | EventFrameAddRejected
@@ -156,4 +82,4 @@ export type FrameClientEvent =
156
82
  | EventNotificationsEnabled
157
83
  | EventNotificationsDisabled
158
84
  | EventPrimaryButtonClicked
159
- | EventEip6963AnnounceProvider
85
+ | Ethereum.EventEip6963AnnounceProvider
@@ -0,0 +1,61 @@
1
+ import type { Address, Provider, RpcRequest, RpcResponse, RpcSchema } from 'ox'
2
+
3
+ export type EthProvideRequest<
4
+ schema extends RpcSchema.Generic = RpcSchema.Default,
5
+ > = Provider.RequestFn<schema>
6
+
7
+ export type FrameEthProviderEventData = {
8
+ type: 'frame_eth_provider_event'
9
+ } & EthProviderWireEvent
10
+
11
+ export type RpcTransport = (
12
+ request: RpcRequest.RpcRequest,
13
+ ) => Promise<RpcResponse.RpcResponse>
14
+
15
+ export type ProviderRpcError = {
16
+ code: number
17
+ details?: string
18
+ message?: string
19
+ }
20
+
21
+ export type EthProviderWireEvent =
22
+ | {
23
+ event: 'accountsChanged'
24
+ params: [readonly Address.Address[]]
25
+ }
26
+ | {
27
+ event: 'chainChanged'
28
+ params: [string]
29
+ }
30
+ | {
31
+ event: 'connect'
32
+ params: [Provider.ConnectInfo]
33
+ }
34
+ | {
35
+ event: 'disconnect'
36
+ params: [ProviderRpcError]
37
+ }
38
+ | {
39
+ event: 'message'
40
+ params: [Provider.Message]
41
+ }
42
+
43
+ export type EmitEthProvider = <event extends EthProviderWireEvent['event']>(
44
+ event: event,
45
+ params: Extract<EthProviderWireEvent, { event: event }>['params'],
46
+ ) => void
47
+
48
+ /**
49
+ * Metadata of the EIP-1193 Provider.
50
+ */
51
+ export interface EIP6963ProviderInfo {
52
+ icon: `data:image/${string}` // RFC-2397
53
+ name: string
54
+ rdns: string
55
+ uuid: string
56
+ }
57
+
58
+ export type EventEip6963AnnounceProvider = {
59
+ event: 'eip6963:announceProvider'
60
+ info: EIP6963ProviderInfo
61
+ }
@@ -0,0 +1 @@
1
+ export * as Ethereum from './ethereum'