@farcaster/frame-node 0.0.18 → 0.0.21
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/README.md +10 -12
- package/dist/farcaster.js +35 -2
- package/esm/farcaster.d.ts +19 -29
- package/esm/farcaster.js +49 -57
- package/esm/index.d.ts +7 -7
- package/esm/index.js +7 -7
- package/esm/jfs.d.ts +16 -33
- package/esm/jfs.js +74 -93
- package/esm/neynar.d.ts +2 -2
- package/esm/neynar.js +12 -14
- package/esm/tsconfig.tsbuildinfo +1 -1
- package/esm/types.d.ts +20 -27
- package/esm/types.js +6 -6
- package/esm/util.d.ts +2 -2
- package/esm/util.js +2 -4
- package/esm/webhook.d.ts +6 -17
- package/esm/webhook.js +18 -23
- package/package.json +2 -2
- package/src/farcaster.ts +1 -1
package/esm/util.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function bytesToHex(bytes: Uint8Array): string
|
|
2
|
-
export declare function hexToBytes(hex: string): Uint8Array
|
|
1
|
+
export declare function bytesToHex(bytes: Uint8Array): string;
|
|
2
|
+
export declare function hexToBytes(hex: string): Uint8Array;
|
package/esm/util.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
export function bytesToHex(bytes) {
|
|
2
|
-
|
|
2
|
+
return `0x${Buffer.from(bytes).toString('hex')}`;
|
|
3
3
|
}
|
|
4
4
|
export function hexToBytes(hex) {
|
|
5
|
-
|
|
6
|
-
Buffer.from(hex.startsWith('0x') ? hex.slice(2) : hex, 'hex'),
|
|
7
|
-
)
|
|
5
|
+
return Uint8Array.from(Buffer.from(hex.startsWith('0x') ? hex.slice(2) : hex, 'hex'));
|
|
8
6
|
}
|
package/esm/webhook.d.ts
CHANGED
|
@@ -1,20 +1,9 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import {
|
|
3
|
-
BaseError,
|
|
4
|
-
type ParseWebhookEventResult,
|
|
5
|
-
type VerifyAppKey,
|
|
6
|
-
} from './types'
|
|
1
|
+
import { type VerifyJsonFarcasterSignature } from './jfs';
|
|
2
|
+
import { BaseError, type ParseWebhookEventResult, type VerifyAppKey } from './types';
|
|
7
3
|
export declare namespace ParseWebhookEvent {
|
|
8
|
-
|
|
9
|
-
| VerifyJsonFarcasterSignature.ErrorType
|
|
10
|
-
| InvalidEventDataError
|
|
4
|
+
type ErrorType = VerifyJsonFarcasterSignature.ErrorType | InvalidEventDataError;
|
|
11
5
|
}
|
|
12
|
-
export declare class InvalidEventDataError<
|
|
13
|
-
|
|
14
|
-
> extends BaseError<C> {
|
|
15
|
-
readonly name = 'VerifyJsonFarcasterSignature.InvalidEventDataError'
|
|
6
|
+
export declare class InvalidEventDataError<C extends Error | undefined = undefined> extends BaseError<C> {
|
|
7
|
+
readonly name = "VerifyJsonFarcasterSignature.InvalidEventDataError";
|
|
16
8
|
}
|
|
17
|
-
export declare function parseWebhookEvent(
|
|
18
|
-
rawData: unknown,
|
|
19
|
-
verifyAppKey: VerifyAppKey,
|
|
20
|
-
): Promise<ParseWebhookEventResult>
|
|
9
|
+
export declare function parseWebhookEvent(rawData: unknown, verifyAppKey: VerifyAppKey): Promise<ParseWebhookEventResult>;
|
package/esm/webhook.js
CHANGED
|
@@ -1,27 +1,22 @@
|
|
|
1
|
-
import { serverEventSchema } from '@farcaster/frame-core'
|
|
2
|
-
import { verifyJsonFarcasterSignature } from './jfs'
|
|
3
|
-
import { BaseError } from './types'
|
|
1
|
+
import { serverEventSchema } from '@farcaster/frame-core';
|
|
2
|
+
import { verifyJsonFarcasterSignature, } from './jfs';
|
|
3
|
+
import { BaseError, } from './types';
|
|
4
4
|
export class InvalidEventDataError extends BaseError {
|
|
5
|
-
|
|
5
|
+
name = 'VerifyJsonFarcasterSignature.InvalidEventDataError';
|
|
6
6
|
}
|
|
7
7
|
export async function parseWebhookEvent(rawData, verifyAppKey) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const event = serverEventSchema.safeParse(payloadJson)
|
|
23
|
-
if (event.success === false) {
|
|
24
|
-
throw new InvalidEventDataError('Invalid event payload', event.error)
|
|
25
|
-
}
|
|
26
|
-
return { fid, appFid, event: event.data }
|
|
8
|
+
const { fid, appFid, payload } = await verifyJsonFarcasterSignature(rawData, verifyAppKey);
|
|
9
|
+
// Pase and validate event payload
|
|
10
|
+
let payloadJson;
|
|
11
|
+
try {
|
|
12
|
+
payloadJson = JSON.parse(Buffer.from(payload).toString('utf-8'));
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
throw new InvalidEventDataError('Error decoding and parsing payload', error instanceof Error ? error : undefined);
|
|
16
|
+
}
|
|
17
|
+
const event = serverEventSchema.safeParse(payloadJson);
|
|
18
|
+
if (event.success === false) {
|
|
19
|
+
throw new InvalidEventDataError('Invalid event payload', event.error);
|
|
20
|
+
}
|
|
21
|
+
return { fid, appFid, event: event.data };
|
|
27
22
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farcaster/frame-node",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@noble/curves": "^1.7.0",
|
|
26
26
|
"ox": "^0.4.4",
|
|
27
27
|
"zod": "^3.24.1",
|
|
28
|
-
"@farcaster/frame-core": "0.0.
|
|
28
|
+
"@farcaster/frame-core": "0.0.32"
|
|
29
29
|
},
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public"
|
package/src/farcaster.ts
CHANGED