@farcaster/snap 1.16.0 → 1.16.1

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
@@ -72,8 +72,8 @@ export declare const payloadSchema: z.ZodObject<{
72
72
  fid: z.ZodNumber;
73
73
  inputs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>>;
74
74
  timestamp: z.ZodNumber;
75
- nonce: z.ZodString;
76
- audience: z.ZodString;
75
+ nonce: z.ZodOptional<z.ZodString>;
76
+ audience: z.ZodOptional<z.ZodString>;
77
77
  }, z.core.$strip>;
78
78
  export type SnapPayload = z.infer<typeof payloadSchema>;
79
79
  export declare const ACTION_TYPE_GET: "get";
@@ -86,8 +86,8 @@ declare const snapPostActionSchema: z.ZodObject<{
86
86
  fid: z.ZodNumber;
87
87
  inputs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>>;
88
88
  timestamp: z.ZodNumber;
89
- nonce: z.ZodString;
90
- audience: z.ZodString;
89
+ nonce: z.ZodOptional<z.ZodString>;
90
+ audience: z.ZodOptional<z.ZodString>;
91
91
  type: z.ZodLiteral<"post">;
92
92
  }, z.core.$strip>;
93
93
  export type SnapPostAction = z.infer<typeof snapPostActionSchema>;
@@ -97,8 +97,8 @@ export declare const snapActionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
97
97
  fid: z.ZodNumber;
98
98
  inputs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>>;
99
99
  timestamp: z.ZodNumber;
100
- nonce: z.ZodString;
101
- audience: z.ZodString;
100
+ nonce: z.ZodOptional<z.ZodString>;
101
+ audience: z.ZodOptional<z.ZodString>;
102
102
  type: z.ZodLiteral<"post">;
103
103
  }, z.core.$strip>], "type">;
104
104
  export type SnapAction = z.infer<typeof snapActionSchema>;
package/dist/schemas.js CHANGED
@@ -36,8 +36,8 @@ export const payloadSchema = z
36
36
  fid: z.number().int().nonnegative(),
37
37
  inputs: z.record(z.string(), postInputValueSchema).default({}),
38
38
  timestamp: z.number().int(),
39
- nonce: z.string(),
40
- audience: z.string(),
39
+ nonce: z.string().optional(),
40
+ audience: z.string().optional(),
41
41
  })
42
42
  .strip();
43
43
  export const ACTION_TYPE_GET = "get";
@@ -77,33 +77,28 @@ export async function parseRequest(request, options = {}) {
77
77
  },
78
78
  };
79
79
  }
80
- let expectedOrigin = options.requestOrigin;
81
- if (expectedOrigin === undefined) {
82
- try {
83
- expectedOrigin = new URL(request.url).origin;
80
+ // Audience validation: only enforce when the client sends an audience field.
81
+ // v1 clients may not include nonce/audience yet.
82
+ if (body.audience !== undefined) {
83
+ let expectedOrigin = options.requestOrigin;
84
+ if (expectedOrigin === undefined) {
85
+ try {
86
+ expectedOrigin = new URL(request.url).origin;
87
+ }
88
+ catch {
89
+ // do nothing
90
+ }
84
91
  }
85
- catch {
86
- // do nothing
92
+ if (expectedOrigin !== undefined && body.audience !== expectedOrigin) {
93
+ return {
94
+ success: false,
95
+ error: {
96
+ type: "origin_mismatch",
97
+ message: `payload audience "${body.audience}" does not match expected origin "${expectedOrigin}"`,
98
+ },
99
+ };
87
100
  }
88
101
  }
89
- if (expectedOrigin === undefined) {
90
- return {
91
- success: false,
92
- error: {
93
- type: "origin_mismatch",
94
- message: "request origin is required for validation",
95
- },
96
- };
97
- }
98
- if (body.audience !== expectedOrigin) {
99
- return {
100
- success: false,
101
- error: {
102
- type: "origin_mismatch",
103
- message: `payload audience "${body.audience}" does not match expected origin "${expectedOrigin}"`,
104
- },
105
- };
106
- }
107
102
  return {
108
103
  success: true,
109
104
  action: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farcaster/snap",
3
- "version": "1.16.0",
3
+ "version": "1.16.1",
4
4
  "description": "Farcaster Snaps 🫰",
5
5
  "repository": {
6
6
  "type": "git",
package/src/schemas.ts CHANGED
@@ -86,8 +86,8 @@ export const payloadSchema = z
86
86
  fid: z.number().int().nonnegative(),
87
87
  inputs: z.record(z.string(), postInputValueSchema).default({}),
88
88
  timestamp: z.number().int(),
89
- nonce: z.string(),
90
- audience: z.string(),
89
+ nonce: z.string().optional(),
90
+ audience: z.string().optional(),
91
91
  })
92
92
  .strip();
93
93
 
@@ -52,6 +52,7 @@ export type ParseRequestOptions = {
52
52
  * The origin of the request. Derived from the request when not provided.
53
53
  */
54
54
  requestOrigin?: string;
55
+
55
56
  };
56
57
 
57
58
  export type ParseRequestResult =
@@ -147,33 +148,27 @@ export async function parseRequest(
147
148
  };
148
149
  }
149
150
 
150
- let expectedOrigin = options.requestOrigin;
151
- if (expectedOrigin === undefined) {
152
- try {
153
- expectedOrigin = new URL(request.url).origin;
154
- } catch {
155
- // do nothing
151
+ // Audience validation: only enforce when the client sends an audience field.
152
+ // v1 clients may not include nonce/audience yet.
153
+ if (body.audience !== undefined) {
154
+ let expectedOrigin = options.requestOrigin;
155
+ if (expectedOrigin === undefined) {
156
+ try {
157
+ expectedOrigin = new URL(request.url).origin;
158
+ } catch {
159
+ // do nothing
160
+ }
156
161
  }
157
- }
158
-
159
- if (expectedOrigin === undefined) {
160
- return {
161
- success: false,
162
- error: {
163
- type: "origin_mismatch",
164
- message: "request origin is required for validation",
165
- },
166
- };
167
- }
168
162
 
169
- if (body.audience !== expectedOrigin) {
170
- return {
171
- success: false,
172
- error: {
173
- type: "origin_mismatch",
174
- message: `payload audience "${body.audience}" does not match expected origin "${expectedOrigin}"`,
175
- },
176
- };
163
+ if (expectedOrigin !== undefined && body.audience !== expectedOrigin) {
164
+ return {
165
+ success: false,
166
+ error: {
167
+ type: "origin_mismatch",
168
+ message: `payload audience "${body.audience}" does not match expected origin "${expectedOrigin}"`,
169
+ },
170
+ };
171
+ }
177
172
  }
178
173
 
179
174
  return {