@farcaster/snap 1.16.0 → 1.16.2

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,12 +68,17 @@ 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
+ */
71
76
  export declare const payloadSchema: z.ZodObject<{
72
77
  fid: z.ZodNumber;
73
78
  inputs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>>;
74
79
  timestamp: z.ZodNumber;
75
- nonce: z.ZodString;
76
- audience: z.ZodString;
80
+ nonce: z.ZodOptional<z.ZodString>;
81
+ audience: z.ZodOptional<z.ZodString>;
77
82
  }, z.core.$strip>;
78
83
  export type SnapPayload = z.infer<typeof payloadSchema>;
79
84
  export declare const ACTION_TYPE_GET: "get";
@@ -86,8 +91,8 @@ declare const snapPostActionSchema: z.ZodObject<{
86
91
  fid: z.ZodNumber;
87
92
  inputs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>>;
88
93
  timestamp: z.ZodNumber;
89
- nonce: z.ZodString;
90
- audience: z.ZodString;
94
+ nonce: z.ZodOptional<z.ZodString>;
95
+ audience: z.ZodOptional<z.ZodString>;
91
96
  type: z.ZodLiteral<"post">;
92
97
  }, z.core.$strip>;
93
98
  export type SnapPostAction = z.infer<typeof snapPostActionSchema>;
@@ -97,8 +102,8 @@ export declare const snapActionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
97
102
  fid: z.ZodNumber;
98
103
  inputs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>>;
99
104
  timestamp: z.ZodNumber;
100
- nonce: z.ZodString;
101
- audience: z.ZodString;
105
+ nonce: z.ZodOptional<z.ZodString>;
106
+ audience: z.ZodOptional<z.ZodString>;
102
107
  type: z.ZodLiteral<"post">;
103
108
  }, z.core.$strip>], "type">;
104
109
  export type SnapAction = z.infer<typeof snapActionSchema>;
package/dist/schemas.js CHANGED
@@ -31,13 +31,20 @@ 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
+ */
34
39
  export const payloadSchema = z
35
40
  .object({
36
41
  fid: z.number().int().nonnegative(),
37
42
  inputs: z.record(z.string(), postInputValueSchema).default({}),
38
43
  timestamp: z.number().int(),
39
- nonce: z.string(),
40
- audience: z.string(),
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(),
41
48
  })
42
49
  .strip();
43
50
  export const ACTION_TYPE_GET = "get";
@@ -77,33 +77,32 @@ 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
+ // 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
+ expectedOrigin = new URL(request.url).origin;
91
+ }
92
+ catch {
93
+ // do nothing
94
+ }
84
95
  }
85
- catch {
86
- // do nothing
96
+ if (expectedOrigin !== undefined && body.audience !== expectedOrigin) {
97
+ return {
98
+ success: false,
99
+ error: {
100
+ type: "origin_mismatch",
101
+ message: `payload audience "${body.audience}" does not match expected origin "${expectedOrigin}"`,
102
+ },
103
+ };
87
104
  }
88
105
  }
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
106
  return {
108
107
  success: true,
109
108
  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.2",
4
4
  "description": "Farcaster Snaps 🫰",
5
5
  "repository": {
6
6
  "type": "git",
package/src/schemas.ts CHANGED
@@ -81,13 +81,20 @@ 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
+ */
84
89
  export const payloadSchema = z
85
90
  .object({
86
91
  fid: z.number().int().nonnegative(),
87
92
  inputs: z.record(z.string(), postInputValueSchema).default({}),
88
93
  timestamp: z.number().int(),
89
- nonce: z.string(),
90
- audience: z.string(),
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(),
91
98
  })
92
99
  .strip();
93
100
 
@@ -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,34 @@ 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
156
- }
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
+ );
157
158
  }
158
159
 
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
- }
160
+ if (body.audience !== undefined) {
161
+ let expectedOrigin = options.requestOrigin;
162
+ if (expectedOrigin === undefined) {
163
+ try {
164
+ expectedOrigin = new URL(request.url).origin;
165
+ } catch {
166
+ // do nothing
167
+ }
168
+ }
168
169
 
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
- };
170
+ if (expectedOrigin !== undefined && body.audience !== expectedOrigin) {
171
+ return {
172
+ success: false,
173
+ error: {
174
+ type: "origin_mismatch",
175
+ message: `payload audience "${body.audience}" does not match expected origin "${expectedOrigin}"`,
176
+ },
177
+ };
178
+ }
177
179
  }
178
180
 
179
181
  return {