@farcaster/snap 1.17.2 → 1.18.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/schemas.d.ts CHANGED
@@ -68,17 +68,12 @@ export type SnapHandlerResult = {
68
68
  effects?: z.input<typeof snapResponseSchema>["effects"];
69
69
  ui: SnapSpecInput;
70
70
  };
71
- /**
72
- * @deprecated `nonce` and `audience` are currently optional for backward
73
- * compatibility but will become **required** in a future major version.
74
- * Clients should always include both fields.
75
- */
76
71
  export declare const payloadSchema: z.ZodObject<{
77
72
  fid: z.ZodNumber;
78
73
  inputs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>>;
79
74
  timestamp: z.ZodNumber;
80
- nonce: z.ZodOptional<z.ZodString>;
81
- audience: z.ZodOptional<z.ZodString>;
75
+ nonce: z.ZodString;
76
+ audience: z.ZodString;
82
77
  }, z.core.$strip>;
83
78
  export type SnapPayload = z.infer<typeof payloadSchema>;
84
79
  export declare const ACTION_TYPE_GET: "get";
@@ -91,8 +86,8 @@ declare const snapPostActionSchema: z.ZodObject<{
91
86
  fid: z.ZodNumber;
92
87
  inputs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>>;
93
88
  timestamp: z.ZodNumber;
94
- nonce: z.ZodOptional<z.ZodString>;
95
- audience: z.ZodOptional<z.ZodString>;
89
+ nonce: z.ZodString;
90
+ audience: z.ZodString;
96
91
  type: z.ZodLiteral<"post">;
97
92
  }, z.core.$strip>;
98
93
  export type SnapPostAction = z.infer<typeof snapPostActionSchema>;
@@ -102,8 +97,8 @@ export declare const snapActionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
102
97
  fid: z.ZodNumber;
103
98
  inputs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>>;
104
99
  timestamp: z.ZodNumber;
105
- nonce: z.ZodOptional<z.ZodString>;
106
- audience: z.ZodOptional<z.ZodString>;
100
+ nonce: z.ZodString;
101
+ audience: z.ZodString;
107
102
  type: z.ZodLiteral<"post">;
108
103
  }, z.core.$strip>], "type">;
109
104
  export type SnapAction = z.infer<typeof snapActionSchema>;
package/dist/schemas.js CHANGED
@@ -31,20 +31,13 @@ const postInputValueSchema = z.union([
31
31
  z.boolean(),
32
32
  z.array(z.string()),
33
33
  ]);
34
- /**
35
- * @deprecated `nonce` and `audience` are currently optional for backward
36
- * compatibility but will become **required** in a future major version.
37
- * Clients should always include both fields.
38
- */
39
34
  export const payloadSchema = z
40
35
  .object({
41
36
  fid: z.number().int().nonnegative(),
42
37
  inputs: z.record(z.string(), postInputValueSchema).default({}),
43
38
  timestamp: z.number().int(),
44
- /** @deprecated Will become required. Clients should always send a unique nonce. */
45
- nonce: z.string().optional(),
46
- /** @deprecated Will become required. Clients should always send the target server origin. */
47
- audience: z.string().optional(),
39
+ nonce: z.string(),
40
+ audience: z.string(),
48
41
  })
49
42
  .strip();
50
43
  export const ACTION_TYPE_GET = "get";
@@ -77,36 +77,29 @@ export async function parseRequest(request, options = {}) {
77
77
  },
78
78
  };
79
79
  }
80
- // Deprecation: nonce and audience will become required in a future major version.
81
- if (body.nonce === undefined || body.audience === undefined) {
82
- console.warn("[snap] POST payload is missing nonce and/or audience. " +
83
- "These fields will be required in a future major version. " +
84
- "Please update your client to include both fields.");
85
- }
86
- if (body.audience !== undefined) {
87
- let expectedOrigin = options.requestOrigin;
88
- if (expectedOrigin === undefined) {
89
- try {
90
- const url = new URL(request.url);
91
- const proto = request.headers.get("x-forwarded-proto") ??
92
- url.protocol.replace(":", "");
93
- const host = request.headers.get("x-forwarded-host") ?? url.host;
94
- expectedOrigin = `${proto}://${host}`;
95
- }
96
- catch {
97
- // do nothing
98
- }
80
+ // Audience validation: ensure the payload audience matches the server origin.
81
+ let expectedOrigin = options.requestOrigin;
82
+ if (expectedOrigin === undefined) {
83
+ try {
84
+ const url = new URL(request.url);
85
+ const proto = request.headers.get("x-forwarded-proto") ??
86
+ url.protocol.replace(":", "");
87
+ const host = request.headers.get("x-forwarded-host") ?? url.host;
88
+ expectedOrigin = `${proto}://${host}`;
99
89
  }
100
- if (expectedOrigin !== undefined && body.audience !== expectedOrigin) {
101
- return {
102
- success: false,
103
- error: {
104
- type: "origin_mismatch",
105
- message: `payload audience "${body.audience}" does not match expected origin "${expectedOrigin}"`,
106
- },
107
- };
90
+ catch {
91
+ // do nothing
108
92
  }
109
93
  }
94
+ if (expectedOrigin !== undefined && body.audience !== expectedOrigin) {
95
+ return {
96
+ success: false,
97
+ error: {
98
+ type: "origin_mismatch",
99
+ message: `payload audience "${body.audience}" does not match expected origin "${expectedOrigin}"`,
100
+ },
101
+ };
102
+ }
110
103
  return {
111
104
  success: true,
112
105
  action: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farcaster/snap",
3
- "version": "1.17.2",
3
+ "version": "1.18.0",
4
4
  "description": "Farcaster Snaps 🫰",
5
5
  "repository": {
6
6
  "type": "git",
package/src/schemas.ts CHANGED
@@ -81,20 +81,13 @@ const postInputValueSchema = z.union([
81
81
  z.array(z.string()),
82
82
  ]);
83
83
 
84
- /**
85
- * @deprecated `nonce` and `audience` are currently optional for backward
86
- * compatibility but will become **required** in a future major version.
87
- * Clients should always include both fields.
88
- */
89
84
  export const payloadSchema = z
90
85
  .object({
91
86
  fid: z.number().int().nonnegative(),
92
87
  inputs: z.record(z.string(), postInputValueSchema).default({}),
93
88
  timestamp: z.number().int(),
94
- /** @deprecated Will become required. Clients should always send a unique nonce. */
95
- nonce: z.string().optional(),
96
- /** @deprecated Will become required. Clients should always send the target server origin. */
97
- audience: z.string().optional(),
89
+ nonce: z.string(),
90
+ audience: z.string(),
98
91
  })
99
92
  .strip();
100
93
 
@@ -148,39 +148,29 @@ export async function parseRequest(
148
148
  };
149
149
  }
150
150
 
151
- // Deprecation: nonce and audience will become required in a future major version.
152
- if (body.nonce === undefined || body.audience === undefined) {
153
- console.warn(
154
- "[snap] POST payload is missing nonce and/or audience. " +
155
- "These fields will be required in a future major version. " +
156
- "Please update your client to include both fields.",
157
- );
158
- }
159
-
160
- if (body.audience !== undefined) {
161
- let expectedOrigin = options.requestOrigin;
162
- if (expectedOrigin === undefined) {
163
- try {
164
- const url = new URL(request.url);
165
- const proto =
166
- request.headers.get("x-forwarded-proto") ??
167
- url.protocol.replace(":", "");
168
- const host = request.headers.get("x-forwarded-host") ?? url.host;
169
- expectedOrigin = `${proto}://${host}`;
170
- } catch {
171
- // do nothing
172
- }
151
+ // Audience validation: ensure the payload audience matches the server origin.
152
+ let expectedOrigin = options.requestOrigin;
153
+ if (expectedOrigin === undefined) {
154
+ try {
155
+ const url = new URL(request.url);
156
+ const proto =
157
+ request.headers.get("x-forwarded-proto") ??
158
+ url.protocol.replace(":", "");
159
+ const host = request.headers.get("x-forwarded-host") ?? url.host;
160
+ expectedOrigin = `${proto}://${host}`;
161
+ } catch {
162
+ // do nothing
173
163
  }
164
+ }
174
165
 
175
- if (expectedOrigin !== undefined && body.audience !== expectedOrigin) {
176
- return {
177
- success: false,
178
- error: {
179
- type: "origin_mismatch",
180
- message: `payload audience "${body.audience}" does not match expected origin "${expectedOrigin}"`,
181
- },
182
- };
183
- }
166
+ if (expectedOrigin !== undefined && body.audience !== expectedOrigin) {
167
+ return {
168
+ success: false,
169
+ error: {
170
+ type: "origin_mismatch",
171
+ message: `payload audience "${body.audience}" does not match expected origin "${expectedOrigin}"`,
172
+ },
173
+ };
184
174
  }
185
175
 
186
176
  return {