@farcaster/frame-node 0.0.40 → 0.1.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/src/index.ts CHANGED
@@ -1,7 +1,10 @@
1
- export * from '@farcaster/frame-core'
2
- export * from './jfs.ts'
3
- export * from './neynar.ts'
4
- export * from './farcaster.ts'
5
- export * from './types.ts'
6
- export * from './webhook.ts'
7
- export * from './util.ts'
1
+ // Deprecation warning
2
+ if (typeof console !== 'undefined' && console.warn) {
3
+ console.warn(
4
+ '[DEPRECATION WARNING] @farcaster/frame-node is deprecated. Please migrate to @farcaster/miniapp-node. ' +
5
+ 'See https://github.com/farcasterxyz/frames/blob/main/MIGRATION.md for migration guide.',
6
+ )
7
+ }
8
+
9
+ // Re-export everything from miniapp-node
10
+ export * from '@farcaster/miniapp-node'
@@ -1,19 +0,0 @@
1
- import { type VerifyAppKey } from './types.ts';
2
- export declare const signedKeyRequestAbi: readonly [{
3
- readonly components: readonly [{
4
- readonly name: "requestFid";
5
- readonly type: "uint256";
6
- }, {
7
- readonly name: "requestSigner";
8
- readonly type: "address";
9
- }, {
10
- readonly name: "signature";
11
- readonly type: "bytes";
12
- }, {
13
- readonly name: "deadline";
14
- readonly type: "uint256";
15
- }];
16
- readonly name: "SignedKeyRequest";
17
- readonly type: "tuple";
18
- }];
19
- export declare const createVerifyAppKeyWithHub: (hubUrl: string, requestOptions?: RequestInit) => VerifyAppKey;
package/dist/farcaster.js DELETED
@@ -1,96 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.createVerifyAppKeyWithHub = exports.signedKeyRequestAbi = void 0;
37
- const AbiParameters = __importStar(require("ox/AbiParameters"));
38
- const zod_1 = require("zod");
39
- const types_ts_1 = require("./types.js");
40
- exports.signedKeyRequestAbi = [
41
- {
42
- components: [
43
- {
44
- name: 'requestFid',
45
- type: 'uint256',
46
- },
47
- {
48
- name: 'requestSigner',
49
- type: 'address',
50
- },
51
- {
52
- name: 'signature',
53
- type: 'bytes',
54
- },
55
- {
56
- name: 'deadline',
57
- type: 'uint256',
58
- },
59
- ],
60
- name: 'SignedKeyRequest',
61
- type: 'tuple',
62
- },
63
- ];
64
- const hubResponseSchema = zod_1.z.object({
65
- events: zod_1.z.array(zod_1.z.object({
66
- signerEventBody: zod_1.z.object({
67
- key: zod_1.z.string(),
68
- metadata: zod_1.z.string(),
69
- }),
70
- })),
71
- });
72
- const createVerifyAppKeyWithHub = (hubUrl, requestOptions) => async (fid, appKey) => {
73
- const url = new URL('/v1/onChainSignersByFid', hubUrl);
74
- url.searchParams.append('fid', fid.toString());
75
- const response = await fetch(url, requestOptions);
76
- if (response.status !== 200) {
77
- throw new types_ts_1.BaseError(`Non-200 response received: ${await response.text()}`);
78
- }
79
- const responseJson = await response.json();
80
- const parsedResponse = hubResponseSchema.safeParse(responseJson);
81
- if (parsedResponse.error) {
82
- throw new types_ts_1.BaseError('Error parsing Hub response', parsedResponse.error);
83
- }
84
- const appKeyLower = appKey.toLowerCase();
85
- const signerEvent = parsedResponse.data.events.find((event) => event.signerEventBody.key.toLowerCase() === appKeyLower);
86
- if (!signerEvent) {
87
- return { valid: false };
88
- }
89
- const decoded = AbiParameters.decode(exports.signedKeyRequestAbi, Buffer.from(signerEvent.signerEventBody.metadata, 'base64'));
90
- if (decoded.length !== 1) {
91
- throw new types_ts_1.BaseError('Error decoding metadata');
92
- }
93
- const appFid = Number(decoded[0].requestFid);
94
- return { valid: true, appFid };
95
- };
96
- exports.createVerifyAppKeyWithHub = createVerifyAppKeyWithHub;
package/dist/jfs.d.ts DELETED
@@ -1,21 +0,0 @@
1
- import { type EncodedJsonFarcasterSignatureSchema } from '@farcaster/frame-core';
2
- import { BaseError, type VerifyAppKey, type VerifyJfsResult } from './types.ts';
3
- export declare namespace VerifyJsonFarcasterSignature {
4
- type ErrorType = InvalidJfsDataError | InvalidJfsAppKeyError | VerifyAppKeyError;
5
- }
6
- export declare class InvalidJfsDataError<C extends Error | undefined = undefined> extends BaseError<C> {
7
- readonly name = "VerifyJsonFarcasterSignature.InvalidDataError";
8
- }
9
- export declare class InvalidJfsAppKeyError<C extends Error | undefined = undefined> extends BaseError<C> {
10
- readonly name = "VerifyJsonFarcasterSignature.InvalidAppKeyError";
11
- }
12
- export declare class VerifyAppKeyError<C extends Error | undefined = undefined> extends BaseError<C> {
13
- readonly name = "VerifyJsonFarcasterSignature.VerifyAppKeyError";
14
- }
15
- export declare function verifyJsonFarcasterSignature(data: unknown, verifyAppKey: VerifyAppKey): Promise<VerifyJfsResult>;
16
- export declare function createJsonFarcasterSignature({ fid, type, privateKey, payload, }: {
17
- fid: number;
18
- type: 'app_key';
19
- privateKey: Uint8Array;
20
- payload: Uint8Array;
21
- }): EncodedJsonFarcasterSignatureSchema;
package/dist/jfs.js DELETED
@@ -1,91 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VerifyAppKeyError = exports.InvalidJfsAppKeyError = exports.InvalidJfsDataError = void 0;
4
- exports.verifyJsonFarcasterSignature = verifyJsonFarcasterSignature;
5
- exports.createJsonFarcasterSignature = createJsonFarcasterSignature;
6
- const frame_core_1 = require("@farcaster/frame-core");
7
- const ed25519_1 = require("@noble/curves/ed25519");
8
- const types_ts_1 = require("./types.js");
9
- const util_ts_1 = require("./util.js");
10
- class InvalidJfsDataError extends types_ts_1.BaseError {
11
- name = 'VerifyJsonFarcasterSignature.InvalidDataError';
12
- }
13
- exports.InvalidJfsDataError = InvalidJfsDataError;
14
- class InvalidJfsAppKeyError extends types_ts_1.BaseError {
15
- name = 'VerifyJsonFarcasterSignature.InvalidAppKeyError';
16
- }
17
- exports.InvalidJfsAppKeyError = InvalidJfsAppKeyError;
18
- class VerifyAppKeyError extends types_ts_1.BaseError {
19
- name = 'VerifyJsonFarcasterSignature.VerifyAppKeyError';
20
- }
21
- exports.VerifyAppKeyError = VerifyAppKeyError;
22
- async function verifyJsonFarcasterSignature(data, verifyAppKey) {
23
- //
24
- // Parse, decode and validate data
25
- //
26
- const body = frame_core_1.encodedJsonFarcasterSignatureSchema.safeParse(data);
27
- if (body.success === false) {
28
- throw new InvalidJfsDataError('Error parsing data', body.error);
29
- }
30
- let headerData;
31
- try {
32
- headerData = JSON.parse(Buffer.from(body.data.header, 'base64url').toString('utf-8'));
33
- }
34
- catch (error) {
35
- throw new InvalidJfsDataError('Error decoding and parsing header');
36
- }
37
- const header = frame_core_1.jsonFarcasterSignatureHeaderSchema.safeParse(headerData);
38
- if (header.success === false) {
39
- throw new InvalidJfsDataError('Error parsing header', header.error);
40
- }
41
- const payload = Buffer.from(body.data.payload, 'base64url');
42
- const signature = Buffer.from(body.data.signature, 'base64url');
43
- if (signature.byteLength !== 64) {
44
- throw new InvalidJfsDataError('Invalid signature length');
45
- }
46
- //
47
- // Verify the signature
48
- //
49
- const fid = header.data.fid;
50
- const appKey = header.data.key;
51
- const appKeyBytes = (0, util_ts_1.hexToBytes)(appKey);
52
- const signedInput = new Uint8Array(Buffer.from(body.data.header + '.' + body.data.payload));
53
- let verifyResult;
54
- try {
55
- verifyResult = ed25519_1.ed25519.verify(signature, signedInput, appKeyBytes);
56
- }
57
- catch (e) {
58
- throw new InvalidJfsDataError('Error checking signature', e instanceof Error ? e : undefined);
59
- }
60
- if (!verifyResult) {
61
- throw new InvalidJfsDataError('Invalid signature');
62
- }
63
- //
64
- // Verify that the app key belongs to the FID
65
- //
66
- let appKeyResult;
67
- try {
68
- appKeyResult = await verifyAppKey(fid, appKey);
69
- }
70
- catch (error) {
71
- throw new VerifyAppKeyError('Error verifying app key', error instanceof Error ? error : undefined);
72
- }
73
- if (!appKeyResult.valid) {
74
- throw new InvalidJfsAppKeyError('App key not valid for FID');
75
- }
76
- return { fid, appFid: appKeyResult.appFid, payload };
77
- }
78
- function createJsonFarcasterSignature({ fid, type, privateKey, payload, }) {
79
- const publicKey = ed25519_1.ed25519.getPublicKey(privateKey);
80
- const header = { fid, type, key: (0, util_ts_1.bytesToHex)(publicKey) };
81
- const encodedHeader = Buffer.from(JSON.stringify(header)).toString('base64url');
82
- const encodedPayload = Buffer.from(payload).toString('base64url');
83
- const signatureInput = new Uint8Array(Buffer.from(encodedHeader + '.' + encodedPayload, 'utf-8'));
84
- const signature = ed25519_1.ed25519.sign(signatureInput, privateKey);
85
- const encodedSignature = Buffer.from(signature).toString('base64url');
86
- return {
87
- header: encodedHeader,
88
- payload: encodedPayload,
89
- signature: encodedSignature,
90
- };
91
- }
package/dist/neynar.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import type { VerifyAppKey } from './types.ts';
2
- export declare const verifyAppKeyWithNeynar: VerifyAppKey;
package/dist/neynar.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.verifyAppKeyWithNeynar = void 0;
4
- const farcaster_ts_1 = require("./farcaster.js");
5
- const apiKey = process.env.NEYNAR_API_KEY || '';
6
- const verifyAppKeyWithNeynar = async (fid, appKey) => {
7
- if (!apiKey) {
8
- throw new Error('Environment variable NEYNAR_API_KEY needs to be set to use Neynar for app key verification');
9
- }
10
- const verifier = (0, farcaster_ts_1.createVerifyAppKeyWithHub)('https://hub-api.neynar.com', {
11
- headers: {
12
- 'x-api-key': apiKey,
13
- },
14
- });
15
- return verifier(fid, appKey);
16
- };
17
- exports.verifyAppKeyWithNeynar = verifyAppKeyWithNeynar;
package/dist/types.d.ts DELETED
@@ -1,23 +0,0 @@
1
- import type { FrameServerEvent } from '@farcaster/frame-core';
2
- export type VerifyAppKeyResult = {
3
- valid: true;
4
- appFid: number;
5
- } | {
6
- valid: false;
7
- };
8
- export type VerifyAppKey = (fid: number, appKey: string) => Promise<VerifyAppKeyResult>;
9
- export type VerifyJfsResult = {
10
- fid: number;
11
- appFid: number;
12
- payload: Uint8Array;
13
- };
14
- export type ParseWebhookEventResult = {
15
- fid: number;
16
- appFid: number;
17
- event: FrameServerEvent;
18
- };
19
- export declare class BaseError<C extends Error | undefined = undefined> extends Error {
20
- name: string;
21
- cause: C;
22
- constructor(message: string, cause?: C);
23
- }
package/dist/types.js DELETED
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseError = void 0;
4
- class BaseError extends Error {
5
- name = 'BaseError';
6
- cause;
7
- constructor(message, cause) {
8
- super(message);
9
- this.cause = cause;
10
- }
11
- }
12
- exports.BaseError = BaseError;
package/dist/util.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export declare function bytesToHex(bytes: Uint8Array): string;
2
- export declare function hexToBytes(hex: string): Uint8Array;
package/dist/util.js DELETED
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.bytesToHex = bytesToHex;
4
- exports.hexToBytes = hexToBytes;
5
- function bytesToHex(bytes) {
6
- return `0x${Buffer.from(bytes).toString('hex')}`;
7
- }
8
- function hexToBytes(hex) {
9
- return Uint8Array.from(Buffer.from(hex.startsWith('0x') ? hex.slice(2) : hex, 'hex'));
10
- }
package/dist/webhook.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import { type VerifyJsonFarcasterSignature } from './jfs.ts';
2
- import { BaseError, type ParseWebhookEventResult, type VerifyAppKey } from './types.ts';
3
- export declare namespace ParseWebhookEvent {
4
- type ErrorType = VerifyJsonFarcasterSignature.ErrorType | InvalidEventDataError;
5
- }
6
- export declare class InvalidEventDataError<C extends Error | undefined = undefined> extends BaseError<C> {
7
- readonly name = "VerifyJsonFarcasterSignature.InvalidEventDataError";
8
- }
9
- export declare function parseWebhookEvent(rawData: unknown, verifyAppKey: VerifyAppKey): Promise<ParseWebhookEventResult>;
package/dist/webhook.js DELETED
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InvalidEventDataError = void 0;
4
- exports.parseWebhookEvent = parseWebhookEvent;
5
- const frame_core_1 = require("@farcaster/frame-core");
6
- const jfs_ts_1 = require("./jfs.js");
7
- const types_ts_1 = require("./types.js");
8
- class InvalidEventDataError extends types_ts_1.BaseError {
9
- name = 'VerifyJsonFarcasterSignature.InvalidEventDataError';
10
- }
11
- exports.InvalidEventDataError = InvalidEventDataError;
12
- async function parseWebhookEvent(rawData, verifyAppKey) {
13
- const { fid, appFid, payload } = await (0, jfs_ts_1.verifyJsonFarcasterSignature)(rawData, verifyAppKey);
14
- // Pase and validate event payload
15
- let payloadJson;
16
- try {
17
- payloadJson = JSON.parse(Buffer.from(payload).toString('utf-8'));
18
- }
19
- catch (error) {
20
- throw new InvalidEventDataError('Error decoding and parsing payload', error instanceof Error ? error : undefined);
21
- }
22
- const event = frame_core_1.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 };
27
- }
@@ -1,19 +0,0 @@
1
- import { type VerifyAppKey } from './types.ts';
2
- export declare const signedKeyRequestAbi: readonly [{
3
- readonly components: readonly [{
4
- readonly name: "requestFid";
5
- readonly type: "uint256";
6
- }, {
7
- readonly name: "requestSigner";
8
- readonly type: "address";
9
- }, {
10
- readonly name: "signature";
11
- readonly type: "bytes";
12
- }, {
13
- readonly name: "deadline";
14
- readonly type: "uint256";
15
- }];
16
- readonly name: "SignedKeyRequest";
17
- readonly type: "tuple";
18
- }];
19
- export declare const createVerifyAppKeyWithHub: (hubUrl: string, requestOptions?: RequestInit) => VerifyAppKey;
package/esm/farcaster.js DELETED
@@ -1,59 +0,0 @@
1
- import * as AbiParameters from 'ox/AbiParameters';
2
- import { z } from 'zod';
3
- import { BaseError, } from "./types.js";
4
- export const signedKeyRequestAbi = [
5
- {
6
- components: [
7
- {
8
- name: 'requestFid',
9
- type: 'uint256',
10
- },
11
- {
12
- name: 'requestSigner',
13
- type: 'address',
14
- },
15
- {
16
- name: 'signature',
17
- type: 'bytes',
18
- },
19
- {
20
- name: 'deadline',
21
- type: 'uint256',
22
- },
23
- ],
24
- name: 'SignedKeyRequest',
25
- type: 'tuple',
26
- },
27
- ];
28
- const hubResponseSchema = z.object({
29
- events: z.array(z.object({
30
- signerEventBody: z.object({
31
- key: z.string(),
32
- metadata: z.string(),
33
- }),
34
- })),
35
- });
36
- export const createVerifyAppKeyWithHub = (hubUrl, requestOptions) => async (fid, appKey) => {
37
- const url = new URL('/v1/onChainSignersByFid', hubUrl);
38
- url.searchParams.append('fid', fid.toString());
39
- const response = await fetch(url, requestOptions);
40
- if (response.status !== 200) {
41
- throw new BaseError(`Non-200 response received: ${await response.text()}`);
42
- }
43
- const responseJson = await response.json();
44
- const parsedResponse = hubResponseSchema.safeParse(responseJson);
45
- if (parsedResponse.error) {
46
- throw new BaseError('Error parsing Hub response', parsedResponse.error);
47
- }
48
- const appKeyLower = appKey.toLowerCase();
49
- const signerEvent = parsedResponse.data.events.find((event) => event.signerEventBody.key.toLowerCase() === appKeyLower);
50
- if (!signerEvent) {
51
- return { valid: false };
52
- }
53
- const decoded = AbiParameters.decode(signedKeyRequestAbi, Buffer.from(signerEvent.signerEventBody.metadata, 'base64'));
54
- if (decoded.length !== 1) {
55
- throw new BaseError('Error decoding metadata');
56
- }
57
- const appFid = Number(decoded[0].requestFid);
58
- return { valid: true, appFid };
59
- };
package/esm/jfs.d.ts DELETED
@@ -1,21 +0,0 @@
1
- import { type EncodedJsonFarcasterSignatureSchema } from '@farcaster/frame-core';
2
- import { BaseError, type VerifyAppKey, type VerifyJfsResult } from './types.ts';
3
- export declare namespace VerifyJsonFarcasterSignature {
4
- type ErrorType = InvalidJfsDataError | InvalidJfsAppKeyError | VerifyAppKeyError;
5
- }
6
- export declare class InvalidJfsDataError<C extends Error | undefined = undefined> extends BaseError<C> {
7
- readonly name = "VerifyJsonFarcasterSignature.InvalidDataError";
8
- }
9
- export declare class InvalidJfsAppKeyError<C extends Error | undefined = undefined> extends BaseError<C> {
10
- readonly name = "VerifyJsonFarcasterSignature.InvalidAppKeyError";
11
- }
12
- export declare class VerifyAppKeyError<C extends Error | undefined = undefined> extends BaseError<C> {
13
- readonly name = "VerifyJsonFarcasterSignature.VerifyAppKeyError";
14
- }
15
- export declare function verifyJsonFarcasterSignature(data: unknown, verifyAppKey: VerifyAppKey): Promise<VerifyJfsResult>;
16
- export declare function createJsonFarcasterSignature({ fid, type, privateKey, payload, }: {
17
- fid: number;
18
- type: 'app_key';
19
- privateKey: Uint8Array;
20
- payload: Uint8Array;
21
- }): EncodedJsonFarcasterSignatureSchema;
package/esm/jfs.js DELETED
@@ -1,83 +0,0 @@
1
- import { encodedJsonFarcasterSignatureSchema, jsonFarcasterSignatureHeaderSchema, } from '@farcaster/frame-core';
2
- import { ed25519 } from '@noble/curves/ed25519';
3
- import { BaseError, } from "./types.js";
4
- import { bytesToHex, hexToBytes } from "./util.js";
5
- export class InvalidJfsDataError extends BaseError {
6
- name = 'VerifyJsonFarcasterSignature.InvalidDataError';
7
- }
8
- export class InvalidJfsAppKeyError extends BaseError {
9
- name = 'VerifyJsonFarcasterSignature.InvalidAppKeyError';
10
- }
11
- export class VerifyAppKeyError extends BaseError {
12
- name = 'VerifyJsonFarcasterSignature.VerifyAppKeyError';
13
- }
14
- export async function verifyJsonFarcasterSignature(data, verifyAppKey) {
15
- //
16
- // Parse, decode and validate data
17
- //
18
- const body = encodedJsonFarcasterSignatureSchema.safeParse(data);
19
- if (body.success === false) {
20
- throw new InvalidJfsDataError('Error parsing data', body.error);
21
- }
22
- let headerData;
23
- try {
24
- headerData = JSON.parse(Buffer.from(body.data.header, 'base64url').toString('utf-8'));
25
- }
26
- catch (error) {
27
- throw new InvalidJfsDataError('Error decoding and parsing header');
28
- }
29
- const header = jsonFarcasterSignatureHeaderSchema.safeParse(headerData);
30
- if (header.success === false) {
31
- throw new InvalidJfsDataError('Error parsing header', header.error);
32
- }
33
- const payload = Buffer.from(body.data.payload, 'base64url');
34
- const signature = Buffer.from(body.data.signature, 'base64url');
35
- if (signature.byteLength !== 64) {
36
- throw new InvalidJfsDataError('Invalid signature length');
37
- }
38
- //
39
- // Verify the signature
40
- //
41
- const fid = header.data.fid;
42
- const appKey = header.data.key;
43
- const appKeyBytes = hexToBytes(appKey);
44
- const signedInput = new Uint8Array(Buffer.from(body.data.header + '.' + body.data.payload));
45
- let verifyResult;
46
- try {
47
- verifyResult = ed25519.verify(signature, signedInput, appKeyBytes);
48
- }
49
- catch (e) {
50
- throw new InvalidJfsDataError('Error checking signature', e instanceof Error ? e : undefined);
51
- }
52
- if (!verifyResult) {
53
- throw new InvalidJfsDataError('Invalid signature');
54
- }
55
- //
56
- // Verify that the app key belongs to the FID
57
- //
58
- let appKeyResult;
59
- try {
60
- appKeyResult = await verifyAppKey(fid, appKey);
61
- }
62
- catch (error) {
63
- throw new VerifyAppKeyError('Error verifying app key', error instanceof Error ? error : undefined);
64
- }
65
- if (!appKeyResult.valid) {
66
- throw new InvalidJfsAppKeyError('App key not valid for FID');
67
- }
68
- return { fid, appFid: appKeyResult.appFid, payload };
69
- }
70
- export function createJsonFarcasterSignature({ fid, type, privateKey, payload, }) {
71
- const publicKey = ed25519.getPublicKey(privateKey);
72
- const header = { fid, type, key: bytesToHex(publicKey) };
73
- const encodedHeader = Buffer.from(JSON.stringify(header)).toString('base64url');
74
- const encodedPayload = Buffer.from(payload).toString('base64url');
75
- const signatureInput = new Uint8Array(Buffer.from(encodedHeader + '.' + encodedPayload, 'utf-8'));
76
- const signature = ed25519.sign(signatureInput, privateKey);
77
- const encodedSignature = Buffer.from(signature).toString('base64url');
78
- return {
79
- header: encodedHeader,
80
- payload: encodedPayload,
81
- signature: encodedSignature,
82
- };
83
- }
package/esm/neynar.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import type { VerifyAppKey } from './types.ts';
2
- export declare const verifyAppKeyWithNeynar: VerifyAppKey;
package/esm/neynar.js DELETED
@@ -1,13 +0,0 @@
1
- import { createVerifyAppKeyWithHub } from "./farcaster.js";
2
- const apiKey = process.env.NEYNAR_API_KEY || '';
3
- export const verifyAppKeyWithNeynar = async (fid, appKey) => {
4
- if (!apiKey) {
5
- throw new Error('Environment variable NEYNAR_API_KEY needs to be set to use Neynar for app key verification');
6
- }
7
- const verifier = createVerifyAppKeyWithHub('https://hub-api.neynar.com', {
8
- headers: {
9
- 'x-api-key': apiKey,
10
- },
11
- });
12
- return verifier(fid, appKey);
13
- };
package/esm/types.d.ts DELETED
@@ -1,23 +0,0 @@
1
- import type { FrameServerEvent } from '@farcaster/frame-core';
2
- export type VerifyAppKeyResult = {
3
- valid: true;
4
- appFid: number;
5
- } | {
6
- valid: false;
7
- };
8
- export type VerifyAppKey = (fid: number, appKey: string) => Promise<VerifyAppKeyResult>;
9
- export type VerifyJfsResult = {
10
- fid: number;
11
- appFid: number;
12
- payload: Uint8Array;
13
- };
14
- export type ParseWebhookEventResult = {
15
- fid: number;
16
- appFid: number;
17
- event: FrameServerEvent;
18
- };
19
- export declare class BaseError<C extends Error | undefined = undefined> extends Error {
20
- name: string;
21
- cause: C;
22
- constructor(message: string, cause?: C);
23
- }
package/esm/types.js DELETED
@@ -1,8 +0,0 @@
1
- export class BaseError extends Error {
2
- name = 'BaseError';
3
- cause;
4
- constructor(message, cause) {
5
- super(message);
6
- this.cause = cause;
7
- }
8
- }
package/esm/util.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export declare function bytesToHex(bytes: Uint8Array): string;
2
- export declare function hexToBytes(hex: string): Uint8Array;
package/esm/util.js DELETED
@@ -1,6 +0,0 @@
1
- export function bytesToHex(bytes) {
2
- return `0x${Buffer.from(bytes).toString('hex')}`;
3
- }
4
- export function hexToBytes(hex) {
5
- return Uint8Array.from(Buffer.from(hex.startsWith('0x') ? hex.slice(2) : hex, 'hex'));
6
- }
package/esm/webhook.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import { type VerifyJsonFarcasterSignature } from './jfs.ts';
2
- import { BaseError, type ParseWebhookEventResult, type VerifyAppKey } from './types.ts';
3
- export declare namespace ParseWebhookEvent {
4
- type ErrorType = VerifyJsonFarcasterSignature.ErrorType | InvalidEventDataError;
5
- }
6
- export declare class InvalidEventDataError<C extends Error | undefined = undefined> extends BaseError<C> {
7
- readonly name = "VerifyJsonFarcasterSignature.InvalidEventDataError";
8
- }
9
- export declare function parseWebhookEvent(rawData: unknown, verifyAppKey: VerifyAppKey): Promise<ParseWebhookEventResult>;
package/esm/webhook.js DELETED
@@ -1,22 +0,0 @@
1
- import { serverEventSchema } from '@farcaster/frame-core';
2
- import { verifyJsonFarcasterSignature, } from "./jfs.js";
3
- import { BaseError, } from "./types.js";
4
- export class InvalidEventDataError extends BaseError {
5
- name = 'VerifyJsonFarcasterSignature.InvalidEventDataError';
6
- }
7
- export async function parseWebhookEvent(rawData, verifyAppKey) {
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 };
22
- }