@farcaster/miniapp-core 0.0.0-canary-20250630212339

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 (144) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +13 -0
  3. package/dist/actions/AddMiniApp.d.ts +36 -0
  4. package/dist/actions/AddMiniApp.js +57 -0
  5. package/dist/actions/ComposeCast.d.ts +37 -0
  6. package/dist/actions/ComposeCast.js +2 -0
  7. package/dist/actions/Haptics.d.ts +5 -0
  8. package/dist/actions/Haptics.js +2 -0
  9. package/dist/actions/Ready.d.ts +13 -0
  10. package/dist/actions/Ready.js +6 -0
  11. package/dist/actions/SendToken.d.ts +48 -0
  12. package/dist/actions/SendToken.js +2 -0
  13. package/dist/actions/SignIn.d.ts +55 -0
  14. package/dist/actions/SignIn.js +47 -0
  15. package/dist/actions/SwapToken.d.ts +46 -0
  16. package/dist/actions/SwapToken.js +2 -0
  17. package/dist/actions/ViewCast.d.ts +25 -0
  18. package/dist/actions/ViewCast.js +2 -0
  19. package/dist/actions/ViewProfile.d.ts +4 -0
  20. package/dist/actions/ViewProfile.js +2 -0
  21. package/dist/actions/ViewToken.d.ts +4 -0
  22. package/dist/actions/ViewToken.js +2 -0
  23. package/dist/actions/index.d.ts +10 -0
  24. package/dist/actions/index.js +46 -0
  25. package/dist/back.d.ts +13 -0
  26. package/dist/back.js +6 -0
  27. package/dist/context.d.ts +94 -0
  28. package/dist/context.js +2 -0
  29. package/dist/errors.d.ts +13 -0
  30. package/dist/errors.js +12 -0
  31. package/dist/index.d.ts +10 -0
  32. package/dist/index.js +49 -0
  33. package/dist/internal/types.d.ts +8 -0
  34. package/dist/internal/types.js +2 -0
  35. package/dist/manifest.d.ts +113 -0
  36. package/dist/manifest.js +10 -0
  37. package/dist/schemas/embeds.d.ts +128 -0
  38. package/dist/schemas/embeds.js +43 -0
  39. package/dist/schemas/events.d.ts +63 -0
  40. package/dist/schemas/events.js +35 -0
  41. package/dist/schemas/index.d.ts +5 -0
  42. package/dist/schemas/index.js +21 -0
  43. package/dist/schemas/manifest.d.ts +236 -0
  44. package/dist/schemas/manifest.js +127 -0
  45. package/dist/schemas/notifications.d.ts +22 -0
  46. package/dist/schemas/notifications.js +23 -0
  47. package/dist/schemas/shared.d.ts +24 -0
  48. package/dist/schemas/shared.js +110 -0
  49. package/dist/solana.d.ts +72 -0
  50. package/dist/solana.js +15 -0
  51. package/dist/solanaWire.d.ts +3 -0
  52. package/dist/solanaWire.js +84 -0
  53. package/dist/types.d.ts +91 -0
  54. package/dist/types.js +41 -0
  55. package/dist/wallet/ethereum.d.ts +47 -0
  56. package/dist/wallet/ethereum.js +2 -0
  57. package/dist/wallet/index.d.ts +1 -0
  58. package/dist/wallet/index.js +37 -0
  59. package/esm/actions/AddMiniApp.d.ts +36 -0
  60. package/esm/actions/AddMiniApp.js +19 -0
  61. package/esm/actions/ComposeCast.d.ts +37 -0
  62. package/esm/actions/ComposeCast.js +1 -0
  63. package/esm/actions/Haptics.d.ts +5 -0
  64. package/esm/actions/Haptics.js +1 -0
  65. package/esm/actions/Ready.d.ts +13 -0
  66. package/esm/actions/Ready.js +3 -0
  67. package/esm/actions/SendToken.d.ts +48 -0
  68. package/esm/actions/SendToken.js +1 -0
  69. package/esm/actions/SignIn.d.ts +55 -0
  70. package/esm/actions/SignIn.js +10 -0
  71. package/esm/actions/SwapToken.d.ts +46 -0
  72. package/esm/actions/SwapToken.js +1 -0
  73. package/esm/actions/ViewCast.d.ts +25 -0
  74. package/esm/actions/ViewCast.js +1 -0
  75. package/esm/actions/ViewProfile.d.ts +4 -0
  76. package/esm/actions/ViewProfile.js +1 -0
  77. package/esm/actions/ViewToken.d.ts +4 -0
  78. package/esm/actions/ViewToken.js +1 -0
  79. package/esm/actions/index.d.ts +10 -0
  80. package/esm/actions/index.js +10 -0
  81. package/esm/back.d.ts +13 -0
  82. package/esm/back.js +3 -0
  83. package/esm/context.d.ts +94 -0
  84. package/esm/context.js +1 -0
  85. package/esm/errors.d.ts +13 -0
  86. package/esm/errors.js +8 -0
  87. package/esm/index.d.ts +10 -0
  88. package/esm/index.js +10 -0
  89. package/esm/internal/types.d.ts +8 -0
  90. package/esm/internal/types.js +1 -0
  91. package/esm/manifest.d.ts +113 -0
  92. package/esm/manifest.js +7 -0
  93. package/esm/schemas/embeds.d.ts +128 -0
  94. package/esm/schemas/embeds.js +39 -0
  95. package/esm/schemas/events.d.ts +63 -0
  96. package/esm/schemas/events.js +32 -0
  97. package/esm/schemas/index.d.ts +5 -0
  98. package/esm/schemas/index.js +5 -0
  99. package/esm/schemas/manifest.d.ts +236 -0
  100. package/esm/schemas/manifest.js +124 -0
  101. package/esm/schemas/notifications.d.ts +22 -0
  102. package/esm/schemas/notifications.js +20 -0
  103. package/esm/schemas/shared.d.ts +24 -0
  104. package/esm/schemas/shared.js +106 -0
  105. package/esm/solana.d.ts +72 -0
  106. package/esm/solana.js +11 -0
  107. package/esm/solanaWire.d.ts +3 -0
  108. package/esm/solanaWire.js +80 -0
  109. package/esm/tsconfig.tsbuildinfo +1 -0
  110. package/esm/types.d.ts +91 -0
  111. package/esm/types.js +23 -0
  112. package/esm/wallet/ethereum.d.ts +47 -0
  113. package/esm/wallet/ethereum.js +1 -0
  114. package/esm/wallet/index.d.ts +1 -0
  115. package/esm/wallet/index.js +1 -0
  116. package/package.json +42 -0
  117. package/src/actions/AddMiniApp.ts +51 -0
  118. package/src/actions/ComposeCast.ts +44 -0
  119. package/src/actions/Haptics.ts +9 -0
  120. package/src/actions/Ready.ts +15 -0
  121. package/src/actions/SendToken.ts +57 -0
  122. package/src/actions/SignIn.ts +67 -0
  123. package/src/actions/SwapToken.ts +54 -0
  124. package/src/actions/ViewCast.ts +27 -0
  125. package/src/actions/ViewProfile.ts +5 -0
  126. package/src/actions/ViewToken.ts +5 -0
  127. package/src/actions/index.ts +10 -0
  128. package/src/back.ts +15 -0
  129. package/src/context.ts +117 -0
  130. package/src/errors.ts +21 -0
  131. package/src/index.ts +10 -0
  132. package/src/internal/types.ts +20 -0
  133. package/src/manifest.ts +131 -0
  134. package/src/schemas/embeds.ts +58 -0
  135. package/src/schemas/events.ts +57 -0
  136. package/src/schemas/index.ts +5 -0
  137. package/src/schemas/manifest.ts +142 -0
  138. package/src/schemas/notifications.ts +35 -0
  139. package/src/schemas/shared.ts +138 -0
  140. package/src/solana.ts +108 -0
  141. package/src/solanaWire.ts +120 -0
  142. package/src/types.ts +165 -0
  143. package/src/wallet/ethereum.ts +65 -0
  144. package/src/wallet/index.ts +1 -0
@@ -0,0 +1,51 @@
1
+ import * as Errors from '../errors.ts'
2
+ import type { OneOf } from '../internal/types.ts'
3
+ import type { MiniAppNotificationDetails } from '../schemas/index.ts'
4
+
5
+ export type AddMiniAppResult = {
6
+ notificationDetails?: MiniAppNotificationDetails
7
+ }
8
+
9
+ export type AddMiniApp = () => Promise<AddMiniAppResult>
10
+
11
+ type InvalidDomainManifestJsonError = {
12
+ type: 'invalid_domain_manifest'
13
+ }
14
+
15
+ type RejectedByUserJsonError = {
16
+ type: 'rejected_by_user'
17
+ }
18
+
19
+ export type AddMiniAppJsonError =
20
+ | InvalidDomainManifestJsonError
21
+ | RejectedByUserJsonError
22
+
23
+ export type AddMiniAppRejectedReason = AddMiniAppJsonError['type']
24
+
25
+ export type AddMiniAppJsonResult = OneOf<
26
+ { result: AddMiniAppResult } | { error: AddMiniAppJsonError }
27
+ >
28
+
29
+ export type WireAddMiniApp = () => Promise<AddMiniAppJsonResult>
30
+
31
+ /**
32
+ * Thrown when the miniapp does not have a valid domain manifest.
33
+ */
34
+ export class InvalidDomainManifest extends Errors.BaseError {
35
+ override readonly name = 'AddMiniApp.InvalidDomainManifest'
36
+
37
+ constructor() {
38
+ super('Invalid domain manifest')
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Thrown when add miniapp action was rejected by the user.
44
+ */
45
+ export class RejectedByUser extends Errors.BaseError {
46
+ override readonly name = 'AddMiniApp.RejectedByUser'
47
+
48
+ constructor() {
49
+ super('Add miniapp rejected by user')
50
+ }
51
+ }
@@ -0,0 +1,44 @@
1
+ export type Options<close extends boolean | undefined = undefined> = {
2
+ /**
3
+ * Suggested text for the body of the cast.
4
+ *
5
+ * Mentions can be included using the human-writable form (e.g. @farcaster).
6
+ **/
7
+ text?: string
8
+
9
+ /** Suggested embeds. Max two. */
10
+ embeds?: [] | [string] | [string, string]
11
+
12
+ /** Suggested parent. */
13
+ parent?: { type: 'cast'; hash: string }
14
+
15
+ /** Whether the app should be closed when this action is called. */
16
+ close?: close
17
+
18
+ /** Whether the cast should be posted to a channel. */
19
+ channelKey?: string
20
+ }
21
+
22
+ export type ComposeCastInnerResult = {
23
+ /** Cast of the created cast */
24
+ hash: string
25
+
26
+ /** Text of the created cast */
27
+ text?: string
28
+
29
+ /** Embeds of the created cast */
30
+ embeds?: [] | [string] | [string, string]
31
+
32
+ /** Parent of the created cast */
33
+ parent?: { type: 'cast'; hash: string }
34
+
35
+ /** Channel key of the created cast */
36
+ channelKey?: string
37
+ }
38
+
39
+ export type Result<close extends boolean | undefined = undefined> =
40
+ close extends true
41
+ ? undefined
42
+ : {
43
+ cast: ComposeCastInnerResult | null
44
+ }
@@ -0,0 +1,9 @@
1
+ // Haptics types
2
+ export type ImpactOccurredType = 'light' | 'medium' | 'heavy' | 'soft' | 'rigid'
3
+ export type NotificationOccurredType = 'success' | 'warning' | 'error'
4
+
5
+ export type ImpactOccurred = (type: ImpactOccurredType) => Promise<void>
6
+ export type NotificationOccurred = (
7
+ type: NotificationOccurredType,
8
+ ) => Promise<void>
9
+ export type SelectionChanged = () => Promise<void>
@@ -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,57 @@
1
+ export type SendTokenOptions = {
2
+ /**
3
+ * CAIP-19 asset ID
4
+ * For example, Base USDC:
5
+ * eip155:8453/erc20:0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
6
+ */
7
+ token?: string
8
+
9
+ /**
10
+ * Token amount, as numeric string.
11
+ * For example, 10 USDC: 1000000
12
+ */
13
+ amount?: string
14
+
15
+ /**
16
+ * Recipient address.
17
+ */
18
+ recipientAddress?: string
19
+
20
+ /**
21
+ * Recipient fid.
22
+ */
23
+ recipientFid?: number
24
+ }
25
+
26
+ type SendTokenDetails = {
27
+ /**
28
+ * Tx identifier.
29
+ */
30
+ transaction: `0x${string}`
31
+ }
32
+
33
+ type SendTokenErrorDetails = {
34
+ /**
35
+ * Error code.
36
+ */
37
+ error: string
38
+ /**
39
+ * Error message.
40
+ */
41
+ message?: string
42
+ }
43
+
44
+ export type SendTokenErrorReason = 'rejected_by_user' | 'send_failed'
45
+
46
+ export type SendTokenResult =
47
+ | {
48
+ success: true
49
+ send: SendTokenDetails
50
+ }
51
+ | {
52
+ success: false
53
+ reason: SendTokenErrorReason
54
+ error?: SendTokenErrorDetails
55
+ }
56
+
57
+ export type SendToken = (options: SendTokenOptions) => Promise<SendTokenResult>
@@ -0,0 +1,67 @@
1
+ import * as Errors from '../errors.ts'
2
+ import type { OneOf } from '../internal/types.ts'
3
+
4
+ export type SignInOptions = {
5
+ /**
6
+ * A random string used to prevent replay attacks.
7
+ */
8
+ nonce: string
9
+
10
+ /**
11
+ * Start time at which the signature becomes valid.
12
+ * ISO 8601 datetime.
13
+ */
14
+ notBefore?: string
15
+
16
+ /**
17
+ * Expiration time at which the signature is no longer valid.
18
+ * ISO 8601 datetime.
19
+ */
20
+ expirationTime?: string
21
+
22
+ /**
23
+ * Whether an [Auth
24
+ * Address](https://github.com/farcasterxyz/protocol/discussions/225) signed
25
+ * message is acceptable. Defaults to `false` to maintain backwards
26
+ * compatibility, though applications should set this to `true` for the best
27
+ * user experience assuming their verification method supports it.
28
+ *
29
+ * @default false
30
+ */
31
+ acceptAuthAddress?: boolean
32
+ }
33
+
34
+ export type SignInResult = {
35
+ signature: string
36
+ message: string
37
+
38
+ /**
39
+ * Indicates if the signature was produced by a custody or auth address.
40
+ */
41
+ authMethod: 'custody' | 'authAddress'
42
+ }
43
+
44
+ export type SignIn = (options: SignInOptions) => Promise<SignInResult>
45
+
46
+ type RejectedByUserJsonError = {
47
+ type: 'rejected_by_user'
48
+ }
49
+
50
+ export type SignInJsonError = RejectedByUserJsonError
51
+
52
+ export type SignInJsonResult = OneOf<
53
+ { result: SignInResult } | { error: SignInJsonError }
54
+ >
55
+
56
+ export type WireSignIn = (options: SignInOptions) => Promise<SignInJsonResult>
57
+
58
+ /**
59
+ * Thrown when a sign in action was rejected.
60
+ */
61
+ export class RejectedByUser extends Errors.BaseError {
62
+ override readonly name = 'SignIn.RejectedByUser'
63
+
64
+ constructor() {
65
+ super('Sign in rejected by user')
66
+ }
67
+ }
@@ -0,0 +1,54 @@
1
+ export type SwapTokenOptions = {
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, 1 USDC: 1000000
18
+ */
19
+ sellAmount?: string
20
+ }
21
+
22
+ type SwapTokenDetails = {
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 SwapTokenErrorDetails = {
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 SwapTokenResult =
44
+ | {
45
+ success: true
46
+ swap: SwapTokenDetails
47
+ }
48
+ | {
49
+ success: false
50
+ reason: SwapErrorReason
51
+ error?: SwapTokenErrorDetails
52
+ }
53
+
54
+ export type SwapToken = (options: SwapTokenOptions) => Promise<SwapTokenResult>
@@ -0,0 +1,27 @@
1
+ export type ViewCastOptions = {
2
+ /**
3
+ * The hash of the cast to view.
4
+ * @example "0x6a112e2d35e2d2008e25dd29811e8769d1edd9ca"
5
+ */
6
+ hash: string
7
+
8
+ /**
9
+ * Whether the app should be closed when this action is called.
10
+ * If true, the app will be closed after opening the cast view.
11
+ */
12
+ close?: boolean
13
+ }
14
+
15
+ /**
16
+ * Opens a cast view in the Farcaster client.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * await sdk.actions.viewCast({
21
+ * hash: "0x6a112e2d35e2d2008e25dd29811e8769d1edd9ca"
22
+ * })
23
+ * ```
24
+ *
25
+ * @see {@link https://miniapps.farcaster.xyz/docs/sdk/actions/view-cast | View Cast Documentation}
26
+ */
27
+ export type ViewCast = (options: ViewCastOptions) => Promise<void>
@@ -0,0 +1,5 @@
1
+ export type ViewProfileOptions = {
2
+ fid: number
3
+ }
4
+
5
+ export type ViewProfile = (options: ViewProfileOptions) => Promise<void>
@@ -0,0 +1,5 @@
1
+ export type ViewTokenOptions = {
2
+ token: string
3
+ }
4
+
5
+ export type ViewToken = (options: ViewTokenOptions) => Promise<void>
@@ -0,0 +1,10 @@
1
+ export * as AddMiniApp from './AddMiniApp.ts'
2
+ export * as ComposeCast from './ComposeCast.ts'
3
+ export * as Haptics from './Haptics.ts'
4
+ export * as Ready from './Ready.ts'
5
+ export * as SignIn from './SignIn.ts'
6
+ export * as SendToken from './SendToken.ts'
7
+ export * as SwapToken from './SwapToken.ts'
8
+ export * as ViewCast from './ViewCast.ts'
9
+ export * as ViewProfile from './ViewProfile.ts'
10
+ export * as ViewToken from './ViewToken.ts'
package/src/back.ts ADDED
@@ -0,0 +1,15 @@
1
+ export type BackState = {
2
+ /**
3
+ * Is the back control visible. Note that on mobile devices Farcaster clients
4
+ * may support a gesture based control rather than button control.
5
+ *
6
+ * @default false
7
+ */
8
+ visible: boolean
9
+ }
10
+
11
+ export const DEFAULT_BACK_STATE = {
12
+ visible: false,
13
+ } satisfies BackState
14
+
15
+ export type UpdateBackState = (state: BackState) => Promise<void>
package/src/context.ts ADDED
@@ -0,0 +1,117 @@
1
+ import type { MiniAppNotificationDetails } from './schemas/index.ts'
2
+
3
+ export type MiniAppUser = {
4
+ fid: number
5
+ username?: string
6
+ displayName?: string
7
+ pfpUrl?: string
8
+ }
9
+
10
+ export interface MiniAppCast {
11
+ author: MiniAppUser
12
+ hash: string
13
+ parentHash?: string
14
+ parentFid?: number
15
+ timestamp?: number
16
+ mentions?: MiniAppUser[]
17
+ text: string
18
+ embeds?: string[]
19
+ channelKey?: string
20
+ }
21
+
22
+ export type CastEmbedLocationContext = {
23
+ type: 'cast_embed'
24
+ embed: string
25
+ cast: MiniAppCast
26
+ }
27
+
28
+ export type CastShareLocationContext = {
29
+ type: 'cast_share'
30
+ cast: MiniAppCast
31
+ }
32
+
33
+ export type NotificationLocationContext = {
34
+ type: 'notification'
35
+ notification: {
36
+ notificationId: string
37
+ title: string
38
+ body: string
39
+ }
40
+ }
41
+
42
+ export type LauncherLocationContext = {
43
+ type: 'launcher'
44
+ }
45
+
46
+ export type ChannelLocationContext = {
47
+ type: 'channel'
48
+ channel: {
49
+ /**
50
+ * Channel key identifier
51
+ */
52
+ key: string
53
+
54
+ /**
55
+ * Channel name
56
+ */
57
+ name: string
58
+
59
+ /**
60
+ * Channel profile image URL
61
+ */
62
+ imageUrl?: string
63
+ }
64
+ }
65
+
66
+ export type LocationContext =
67
+ | CastEmbedLocationContext
68
+ | CastShareLocationContext
69
+ | NotificationLocationContext
70
+ | LauncherLocationContext
71
+ | ChannelLocationContext
72
+
73
+ export type AccountLocation = {
74
+ placeId: string
75
+
76
+ /**
77
+ * Human-readable string describing the location
78
+ */
79
+ description: string
80
+ }
81
+
82
+ export type UserContext = {
83
+ fid: number
84
+ username?: string
85
+ displayName?: string
86
+
87
+ /**
88
+ * Profile image URL
89
+ */
90
+ pfpUrl?: string
91
+ location?: AccountLocation
92
+ }
93
+
94
+ export type SafeAreaInsets = {
95
+ top: number
96
+ bottom: number
97
+ left: number
98
+ right: number
99
+ }
100
+
101
+ export type ClientContext = {
102
+ clientFid: number
103
+ added: boolean
104
+ notificationDetails?: MiniAppNotificationDetails
105
+ safeAreaInsets?: SafeAreaInsets
106
+ }
107
+
108
+ export type ClientFeatures = {
109
+ haptics: boolean
110
+ }
111
+
112
+ export type MiniAppContext = {
113
+ client: ClientContext
114
+ user: UserContext
115
+ location?: LocationContext
116
+ features?: ClientFeatures
117
+ }
package/src/errors.ts ADDED
@@ -0,0 +1,21 @@
1
+ export type GlobalErrorType<name extends string = 'Error'> = Error & {
2
+ name: name
3
+ }
4
+
5
+ export class BaseError<
6
+ cause extends Error | undefined = undefined,
7
+ > extends Error {
8
+ override name = 'BaseError'
9
+ cause: cause
10
+
11
+ constructor(message: string, options: BaseError.Options<cause> = {}) {
12
+ super(message, options.cause ? { cause: options.cause } : undefined)
13
+ this.cause = options.cause as any
14
+ }
15
+ }
16
+
17
+ export declare namespace BaseError {
18
+ type Options<cause extends Error | undefined = Error | undefined> = {
19
+ cause?: cause | undefined
20
+ }
21
+ }
package/src/index.ts ADDED
@@ -0,0 +1,10 @@
1
+ export * from './actions/index.ts'
2
+ export * from './wallet/index.ts'
3
+ export * as Back from './back.ts'
4
+ export * as Errors from './errors.ts'
5
+ export * as Context from './context.ts'
6
+ export * as Manifest from './manifest.ts'
7
+ export * from './types.ts'
8
+ export * from './schemas/index.ts'
9
+ export * from './solana.ts'
10
+ export * from './solanaWire.ts'
@@ -0,0 +1,20 @@
1
+ type Compute<type> = { [key in keyof type]: type[key] } & unknown
2
+
3
+ type KeyofUnion<type> = type extends type ? keyof type : never
4
+
5
+ export type OneOf<
6
+ union extends object,
7
+ fallback extends object | undefined = undefined,
8
+ ///
9
+ keys extends KeyofUnion<union> = KeyofUnion<union>,
10
+ > = union extends infer item
11
+ ? Compute<
12
+ item & {
13
+ [key in Exclude<keys, keyof item>]?: fallback extends object
14
+ ? key extends keyof fallback
15
+ ? fallback[key]
16
+ : undefined
17
+ : undefined
18
+ }
19
+ >
20
+ : never
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Farcaster manifest for a domain hosted at `/.well-known/farcaster.json`
3
+ */
4
+ export type Manifest = {
5
+ accountAssociation: AccountAssociation
6
+ miniapp?: MiniAppConfig
7
+ frame?: MiniAppConfig
8
+ }
9
+
10
+ /**
11
+ * Signed domain association linking this miniapp to a Farcaster account
12
+ *
13
+ * A DomainAssociation can be generated using the {@link https://farcaster.xyz/~/developers/domains | Warpcast
14
+ * Domains Developer} tool.
15
+ */
16
+ export type AccountAssociation = {
17
+ /**
18
+ * Base64URL encoded JFS signature
19
+ */
20
+ header: string
21
+
22
+ /**
23
+ * Base64URL encoded payload signature
24
+ */
25
+ payload: string
26
+
27
+ /**
28
+ * Base64URL encoded signature
29
+ */
30
+ signature: string
31
+ }
32
+
33
+ /**
34
+ * MiniApp configuration
35
+ *
36
+ * @example
37
+ * ``ts
38
+ * const miniapp: MiniAppConfig = {
39
+ * version: '1',
40
+ * name: 'Yoink!',
41
+ * homeUrl: 'https://yoink.party',
42
+ * iconUrl: 'https://yoink.party/img/icon.png',
43
+ * imageUrl: 'https://yoink.party/framesV2/opengraph-image',
44
+ * buttonTitle: '🚩 Start',
45
+ * splashImageUrl: 'https://yoink.party/img/splash.png',
46
+ * splashImageBackgroundColor: '#eeeee4',
47
+ * webhookUrl: 'https://yoink.party/webhook'
48
+ * };
49
+ * ``
50
+ */
51
+ export type MiniAppConfig = {
52
+ /**
53
+ * Manifest version
54
+ *
55
+ * Must be the literal '1'.
56
+ */
57
+ version: '1'
58
+
59
+ /**
60
+ * App name that will be displayed to users
61
+ *
62
+ * Max length of 32 characters.
63
+ */
64
+ name: string
65
+
66
+ /**
67
+ * Default launch URL
68
+ *
69
+ * Max length of 1024 characters.
70
+ */
71
+ homeUrl: string
72
+
73
+ /**
74
+ * Icon URL
75
+ *
76
+ * Max length of 1024 characters. Image must be 200x200px and less than 1MB.
77
+ */
78
+ iconUrl: string
79
+
80
+ /**
81
+ * Image URL
82
+ *
83
+ * Max length of 1024 characters. Image must have a 3:2 ratio.
84
+ */
85
+ imageUrl: string
86
+
87
+ /**
88
+ * Default button title to use when miniapp is rendered.
89
+ *
90
+ * Max length of 32 characters.
91
+ */
92
+ buttonTitle: string
93
+
94
+ /**
95
+ * Splash image URL
96
+ *
97
+ * Max length of 1024 characters. Image must be 200x200px and less than 1MB.
98
+ */
99
+ splashImageUrl?: string
100
+
101
+ /**
102
+ * Splash background color
103
+ *
104
+ * Must be a hex color code.
105
+ */
106
+ splashBackgroundColor?: string
107
+
108
+ /**
109
+ * URL to which clients will POST server events.
110
+ * Max length of 1024 characters.
111
+ * Required if the miniapp application uses notifications.
112
+ */
113
+ webhookUrl?: string
114
+
115
+ /**
116
+ * Canonical domain for the miniapp application.
117
+ * If specified, this domain will be treated as the primary domain for the miniapp.
118
+ * Max length of 1024 characters.
119
+ */
120
+ canonicalDomain?: string
121
+ }
122
+
123
+ /**
124
+ * Helper function to get the MiniApp config from a manifest,
125
+ * supporting both 'miniapp' and 'frame' properties during the transition period
126
+ */
127
+ export function getMiniAppConfig(
128
+ manifest: Manifest,
129
+ ): MiniAppConfig | undefined {
130
+ return manifest.miniapp || manifest.frame
131
+ }