@farcaster/frame-node 0.0.10 → 0.0.12
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/farcaster.d.ts +1 -1
- package/dist/farcaster.js +17 -17
- package/dist/index.d.ts +7 -7
- package/dist/jfs.d.ts +3 -3
- package/dist/jfs.js +19 -19
- package/dist/neynar.d.ts +1 -1
- package/dist/neynar.js +4 -4
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -1
- package/dist/util.js +2 -2
- package/dist/webhook.d.ts +2 -2
- package/dist/webhook.js +4 -4
- package/esm/farcaster.d.ts +29 -19
- package/esm/farcaster.js +57 -49
- package/esm/index.d.ts +7 -7
- package/esm/index.js +7 -7
- package/esm/jfs.d.ts +33 -16
- package/esm/jfs.js +93 -74
- package/esm/neynar.d.ts +2 -2
- package/esm/neynar.js +14 -12
- package/esm/tsconfig.tsbuildinfo +1 -1
- package/esm/types.d.ts +27 -20
- package/esm/types.js +6 -6
- package/esm/util.d.ts +2 -2
- package/esm/util.js +4 -2
- package/esm/webhook.d.ts +17 -6
- package/esm/webhook.js +23 -18
- package/package.json +7 -5
- package/src/farcaster.ts +34 -36
- package/src/index.ts +7 -7
- package/src/jfs.ts +55 -50
- package/src/neynar.ts +11 -11
- package/src/types.ts +15 -15
- package/src/util.ts +3 -3
- package/src/webhook.ts +18 -14
package/dist/farcaster.d.ts
CHANGED
package/dist/farcaster.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createVerifyAppKeyWithHub = exports.signedKeyRequestAbi = void 0;
|
|
4
|
-
const types_1 = require("./types");
|
|
5
|
-
const zod_1 = require("zod");
|
|
6
4
|
const ox_1 = require("ox");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const types_1 = require("./types");
|
|
7
7
|
exports.signedKeyRequestAbi = [
|
|
8
8
|
{
|
|
9
9
|
components: [
|
|
10
10
|
{
|
|
11
|
-
name:
|
|
12
|
-
type:
|
|
11
|
+
name: 'requestFid',
|
|
12
|
+
type: 'uint256',
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
|
-
name:
|
|
16
|
-
type:
|
|
15
|
+
name: 'requestSigner',
|
|
16
|
+
type: 'address',
|
|
17
17
|
},
|
|
18
18
|
{
|
|
19
|
-
name:
|
|
20
|
-
type:
|
|
19
|
+
name: 'signature',
|
|
20
|
+
type: 'bytes',
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
|
-
name:
|
|
24
|
-
type:
|
|
23
|
+
name: 'deadline',
|
|
24
|
+
type: 'uint256',
|
|
25
25
|
},
|
|
26
26
|
],
|
|
27
|
-
name:
|
|
28
|
-
type:
|
|
27
|
+
name: 'SignedKeyRequest',
|
|
28
|
+
type: 'tuple',
|
|
29
29
|
},
|
|
30
30
|
];
|
|
31
31
|
const hubResponseSchema = zod_1.z.object({
|
|
@@ -37,8 +37,8 @@ const hubResponseSchema = zod_1.z.object({
|
|
|
37
37
|
})),
|
|
38
38
|
});
|
|
39
39
|
const createVerifyAppKeyWithHub = (hubUrl, requestOptions) => async (fid, appKey) => {
|
|
40
|
-
const url = new URL(
|
|
41
|
-
url.searchParams.append(
|
|
40
|
+
const url = new URL('/v1/onChainSignersByFid', hubUrl);
|
|
41
|
+
url.searchParams.append('fid', fid.toString());
|
|
42
42
|
const response = await fetch(url, requestOptions);
|
|
43
43
|
if (response.status !== 200) {
|
|
44
44
|
throw new types_1.BaseError(`Non-200 response received: ${await response.text()}`);
|
|
@@ -46,16 +46,16 @@ const createVerifyAppKeyWithHub = (hubUrl, requestOptions) => async (fid, appKey
|
|
|
46
46
|
const responseJson = await response.json();
|
|
47
47
|
const parsedResponse = hubResponseSchema.safeParse(responseJson);
|
|
48
48
|
if (parsedResponse.error) {
|
|
49
|
-
throw new types_1.BaseError(
|
|
49
|
+
throw new types_1.BaseError('Error parsing Hub response', parsedResponse.error);
|
|
50
50
|
}
|
|
51
51
|
const appKeyLower = appKey.toLowerCase();
|
|
52
52
|
const signerEvent = parsedResponse.data.events.find((event) => event.signerEventBody.key.toLowerCase() === appKeyLower);
|
|
53
53
|
if (!signerEvent) {
|
|
54
54
|
return { valid: false };
|
|
55
55
|
}
|
|
56
|
-
const decoded = ox_1.AbiParameters.decode(exports.signedKeyRequestAbi, Buffer.from(signerEvent.signerEventBody.metadata,
|
|
56
|
+
const decoded = ox_1.AbiParameters.decode(exports.signedKeyRequestAbi, Buffer.from(signerEvent.signerEventBody.metadata, 'base64'));
|
|
57
57
|
if (decoded.length !== 1) {
|
|
58
|
-
throw new types_1.BaseError(
|
|
58
|
+
throw new types_1.BaseError('Error decoding metadata');
|
|
59
59
|
}
|
|
60
60
|
const appFid = Number(decoded[0].requestFid);
|
|
61
61
|
return { valid: true, appFid };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
1
|
+
export * from '@farcaster/frame-core';
|
|
2
|
+
export * from './jfs';
|
|
3
|
+
export * from './neynar';
|
|
4
|
+
export * from './farcaster';
|
|
5
|
+
export * from './types';
|
|
6
|
+
export * from './webhook';
|
|
7
|
+
export * from './util';
|
package/dist/jfs.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EncodedJsonFarcasterSignatureSchema } from
|
|
2
|
-
import { BaseError, VerifyAppKey, VerifyJfsResult } from
|
|
1
|
+
import { type EncodedJsonFarcasterSignatureSchema } from '@farcaster/frame-core';
|
|
2
|
+
import { BaseError, type VerifyAppKey, type VerifyJfsResult } from './types';
|
|
3
3
|
export declare namespace VerifyJsonFarcasterSignature {
|
|
4
4
|
type ErrorType = InvalidJfsDataError | InvalidJfsAppKeyError | VerifyAppKeyError;
|
|
5
5
|
}
|
|
@@ -15,7 +15,7 @@ export declare class VerifyAppKeyError<C extends Error | undefined = undefined>
|
|
|
15
15
|
export declare function verifyJsonFarcasterSignature(data: unknown, verifyAppKey: VerifyAppKey): Promise<VerifyJfsResult>;
|
|
16
16
|
export declare function createJsonFarcasterSignature({ fid, type, privateKey, payload, }: {
|
|
17
17
|
fid: number;
|
|
18
|
-
type:
|
|
18
|
+
type: 'app_key';
|
|
19
19
|
privateKey: Uint8Array;
|
|
20
20
|
payload: Uint8Array;
|
|
21
21
|
}): EncodedJsonFarcasterSignatureSchema;
|
package/dist/jfs.js
CHANGED
|
@@ -8,15 +8,15 @@ const ed25519_1 = require("@noble/curves/ed25519");
|
|
|
8
8
|
const types_1 = require("./types");
|
|
9
9
|
const util_1 = require("./util");
|
|
10
10
|
class InvalidJfsDataError extends types_1.BaseError {
|
|
11
|
-
name =
|
|
11
|
+
name = 'VerifyJsonFarcasterSignature.InvalidDataError';
|
|
12
12
|
}
|
|
13
13
|
exports.InvalidJfsDataError = InvalidJfsDataError;
|
|
14
14
|
class InvalidJfsAppKeyError extends types_1.BaseError {
|
|
15
|
-
name =
|
|
15
|
+
name = 'VerifyJsonFarcasterSignature.InvalidAppKeyError';
|
|
16
16
|
}
|
|
17
17
|
exports.InvalidJfsAppKeyError = InvalidJfsAppKeyError;
|
|
18
18
|
class VerifyAppKeyError extends types_1.BaseError {
|
|
19
|
-
name =
|
|
19
|
+
name = 'VerifyJsonFarcasterSignature.VerifyAppKeyError';
|
|
20
20
|
}
|
|
21
21
|
exports.VerifyAppKeyError = VerifyAppKeyError;
|
|
22
22
|
async function verifyJsonFarcasterSignature(data, verifyAppKey) {
|
|
@@ -25,23 +25,23 @@ async function verifyJsonFarcasterSignature(data, verifyAppKey) {
|
|
|
25
25
|
//
|
|
26
26
|
const body = frame_core_1.encodedJsonFarcasterSignatureSchema.safeParse(data);
|
|
27
27
|
if (body.success === false) {
|
|
28
|
-
throw new InvalidJfsDataError(
|
|
28
|
+
throw new InvalidJfsDataError('Error parsing data', body.error);
|
|
29
29
|
}
|
|
30
30
|
let headerData;
|
|
31
31
|
try {
|
|
32
|
-
headerData = JSON.parse(Buffer.from(body.data.header,
|
|
32
|
+
headerData = JSON.parse(Buffer.from(body.data.header, 'base64url').toString('utf-8'));
|
|
33
33
|
}
|
|
34
34
|
catch (error) {
|
|
35
|
-
throw new InvalidJfsDataError(
|
|
35
|
+
throw new InvalidJfsDataError('Error decoding and parsing header');
|
|
36
36
|
}
|
|
37
37
|
const header = frame_core_1.jsonFarcasterSignatureHeaderSchema.safeParse(headerData);
|
|
38
38
|
if (header.success === false) {
|
|
39
|
-
throw new InvalidJfsDataError(
|
|
39
|
+
throw new InvalidJfsDataError('Error parsing header', header.error);
|
|
40
40
|
}
|
|
41
|
-
const payload = Buffer.from(body.data.payload,
|
|
42
|
-
const signature = Buffer.from(body.data.signature,
|
|
41
|
+
const payload = Buffer.from(body.data.payload, 'base64url');
|
|
42
|
+
const signature = Buffer.from(body.data.signature, 'base64url');
|
|
43
43
|
if (signature.byteLength !== 64) {
|
|
44
|
-
throw new InvalidJfsDataError(
|
|
44
|
+
throw new InvalidJfsDataError('Invalid signature length');
|
|
45
45
|
}
|
|
46
46
|
//
|
|
47
47
|
// Verify the signature
|
|
@@ -49,16 +49,16 @@ async function verifyJsonFarcasterSignature(data, verifyAppKey) {
|
|
|
49
49
|
const fid = header.data.fid;
|
|
50
50
|
const appKey = header.data.key;
|
|
51
51
|
const appKeyBytes = (0, util_1.hexToBytes)(appKey);
|
|
52
|
-
const signedInput = new Uint8Array(Buffer.from(body.data.header +
|
|
52
|
+
const signedInput = new Uint8Array(Buffer.from(body.data.header + '.' + body.data.payload));
|
|
53
53
|
let verifyResult;
|
|
54
54
|
try {
|
|
55
55
|
verifyResult = ed25519_1.ed25519.verify(signature, signedInput, appKeyBytes);
|
|
56
56
|
}
|
|
57
57
|
catch (e) {
|
|
58
|
-
throw new InvalidJfsDataError(
|
|
58
|
+
throw new InvalidJfsDataError('Error checking signature', e instanceof Error ? e : undefined);
|
|
59
59
|
}
|
|
60
60
|
if (!verifyResult) {
|
|
61
|
-
throw new InvalidJfsDataError(
|
|
61
|
+
throw new InvalidJfsDataError('Invalid signature');
|
|
62
62
|
}
|
|
63
63
|
//
|
|
64
64
|
// Verify that the app key belongs to the FID
|
|
@@ -68,21 +68,21 @@ async function verifyJsonFarcasterSignature(data, verifyAppKey) {
|
|
|
68
68
|
appKeyResult = await verifyAppKey(fid, appKey);
|
|
69
69
|
}
|
|
70
70
|
catch (error) {
|
|
71
|
-
throw new VerifyAppKeyError(
|
|
71
|
+
throw new VerifyAppKeyError('Error verifying app key', error instanceof Error ? error : undefined);
|
|
72
72
|
}
|
|
73
73
|
if (!appKeyResult.valid) {
|
|
74
|
-
throw new InvalidJfsAppKeyError(
|
|
74
|
+
throw new InvalidJfsAppKeyError('App key not valid for FID');
|
|
75
75
|
}
|
|
76
76
|
return { fid, appFid: appKeyResult.appFid, payload };
|
|
77
77
|
}
|
|
78
78
|
function createJsonFarcasterSignature({ fid, type, privateKey, payload, }) {
|
|
79
79
|
const publicKey = ed25519_1.ed25519.getPublicKey(privateKey);
|
|
80
80
|
const header = { fid, type, key: (0, util_1.bytesToHex)(publicKey) };
|
|
81
|
-
const encodedHeader = Buffer.from(JSON.stringify(header)).toString(
|
|
82
|
-
const encodedPayload = Buffer.from(payload).toString(
|
|
83
|
-
const signatureInput = new Uint8Array(Buffer.from(encodedHeader +
|
|
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
84
|
const signature = ed25519_1.ed25519.sign(signatureInput, privateKey);
|
|
85
|
-
const encodedSignature = Buffer.from(signature).toString(
|
|
85
|
+
const encodedSignature = Buffer.from(signature).toString('base64url');
|
|
86
86
|
return {
|
|
87
87
|
header: encodedHeader,
|
|
88
88
|
payload: encodedPayload,
|
package/dist/neynar.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { VerifyAppKey } from
|
|
1
|
+
import type { VerifyAppKey } from './types';
|
|
2
2
|
export declare const verifyAppKeyWithNeynar: VerifyAppKey;
|
package/dist/neynar.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.verifyAppKeyWithNeynar = void 0;
|
|
4
4
|
const farcaster_1 = require("./farcaster");
|
|
5
|
-
const apiKey = process.env.NEYNAR_API_KEY ||
|
|
5
|
+
const apiKey = process.env.NEYNAR_API_KEY || '';
|
|
6
6
|
const verifyAppKeyWithNeynar = async (fid, appKey) => {
|
|
7
7
|
if (!apiKey) {
|
|
8
|
-
throw new Error(
|
|
8
|
+
throw new Error('Environment variable NEYNAR_API_KEY needs to be set to use Neynar for app key verification');
|
|
9
9
|
}
|
|
10
|
-
const verifier = (0, farcaster_1.createVerifyAppKeyWithHub)(
|
|
10
|
+
const verifier = (0, farcaster_1.createVerifyAppKeyWithHub)('https://hub-api.neynar.com', {
|
|
11
11
|
headers: {
|
|
12
|
-
|
|
12
|
+
'x-api-key': apiKey,
|
|
13
13
|
},
|
|
14
14
|
});
|
|
15
15
|
return verifier(fid, appKey);
|
package/dist/types.d.ts
CHANGED
package/dist/types.js
CHANGED
package/dist/util.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.bytesToHex = bytesToHex;
|
|
4
4
|
exports.hexToBytes = hexToBytes;
|
|
5
5
|
function bytesToHex(bytes) {
|
|
6
|
-
return `0x${Buffer.from(bytes).toString(
|
|
6
|
+
return `0x${Buffer.from(bytes).toString('hex')}`;
|
|
7
7
|
}
|
|
8
8
|
function hexToBytes(hex) {
|
|
9
|
-
return Uint8Array.from(Buffer.from(hex.startsWith(
|
|
9
|
+
return Uint8Array.from(Buffer.from(hex.startsWith('0x') ? hex.slice(2) : hex, 'hex'));
|
|
10
10
|
}
|
package/dist/webhook.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { VerifyJsonFarcasterSignature } from
|
|
2
|
-
import { BaseError, ParseWebhookEventResult, VerifyAppKey } from
|
|
1
|
+
import { type VerifyJsonFarcasterSignature } from './jfs';
|
|
2
|
+
import { BaseError, type ParseWebhookEventResult, type VerifyAppKey } from './types';
|
|
3
3
|
export declare namespace ParseWebhookEvent {
|
|
4
4
|
type ErrorType = VerifyJsonFarcasterSignature.ErrorType | InvalidEventDataError;
|
|
5
5
|
}
|
package/dist/webhook.js
CHANGED
|
@@ -6,7 +6,7 @@ const frame_core_1 = require("@farcaster/frame-core");
|
|
|
6
6
|
const jfs_1 = require("./jfs");
|
|
7
7
|
const types_1 = require("./types");
|
|
8
8
|
class InvalidEventDataError extends types_1.BaseError {
|
|
9
|
-
name =
|
|
9
|
+
name = 'VerifyJsonFarcasterSignature.InvalidEventDataError';
|
|
10
10
|
}
|
|
11
11
|
exports.InvalidEventDataError = InvalidEventDataError;
|
|
12
12
|
async function parseWebhookEvent(rawData, verifyAppKey) {
|
|
@@ -14,14 +14,14 @@ async function parseWebhookEvent(rawData, verifyAppKey) {
|
|
|
14
14
|
// Pase and validate event payload
|
|
15
15
|
let payloadJson;
|
|
16
16
|
try {
|
|
17
|
-
payloadJson = JSON.parse(Buffer.from(payload).toString(
|
|
17
|
+
payloadJson = JSON.parse(Buffer.from(payload).toString('utf-8'));
|
|
18
18
|
}
|
|
19
19
|
catch (error) {
|
|
20
|
-
throw new InvalidEventDataError(
|
|
20
|
+
throw new InvalidEventDataError('Error decoding and parsing payload', error instanceof Error ? error : undefined);
|
|
21
21
|
}
|
|
22
22
|
const event = frame_core_1.serverEventSchema.safeParse(payloadJson);
|
|
23
23
|
if (event.success === false) {
|
|
24
|
-
throw new InvalidEventDataError(
|
|
24
|
+
throw new InvalidEventDataError('Invalid event payload', event.error);
|
|
25
25
|
}
|
|
26
26
|
return { fid, appFid, event: event.data };
|
|
27
27
|
}
|
package/esm/farcaster.d.ts
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
|
-
import { VerifyAppKey } from
|
|
2
|
-
export declare const signedKeyRequestAbi: readonly [
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
readonly
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
readonly name:
|
|
11
|
-
readonly type:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
readonly
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
import type { VerifyAppKey } from './types'
|
|
2
|
+
export declare const signedKeyRequestAbi: readonly [
|
|
3
|
+
{
|
|
4
|
+
readonly components: readonly [
|
|
5
|
+
{
|
|
6
|
+
readonly name: 'requestFid'
|
|
7
|
+
readonly type: 'uint256'
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
readonly name: 'requestSigner'
|
|
11
|
+
readonly type: 'address'
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
readonly name: 'signature'
|
|
15
|
+
readonly type: 'bytes'
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
readonly name: 'deadline'
|
|
19
|
+
readonly type: 'uint256'
|
|
20
|
+
},
|
|
21
|
+
]
|
|
22
|
+
readonly name: 'SignedKeyRequest'
|
|
23
|
+
readonly type: 'tuple'
|
|
24
|
+
},
|
|
25
|
+
]
|
|
26
|
+
export declare const createVerifyAppKeyWithHub: (
|
|
27
|
+
hubUrl: string,
|
|
28
|
+
requestOptions?: RequestInit,
|
|
29
|
+
) => VerifyAppKey
|
package/esm/farcaster.js
CHANGED
|
@@ -1,59 +1,67 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { z } from
|
|
3
|
-
import {
|
|
1
|
+
import { AbiParameters } from 'ox'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import { BaseError } from './types'
|
|
4
4
|
export const signedKeyRequestAbi = [
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
]
|
|
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
28
|
const hubResponseSchema = z.object({
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
events: z.array(
|
|
30
|
+
z.object({
|
|
31
|
+
signerEventBody: z.object({
|
|
32
|
+
key: z.string(),
|
|
33
|
+
metadata: z.string(),
|
|
34
|
+
}),
|
|
35
|
+
}),
|
|
36
|
+
),
|
|
37
|
+
})
|
|
38
|
+
export const createVerifyAppKeyWithHub =
|
|
39
|
+
(hubUrl, requestOptions) => async (fid, appKey) => {
|
|
40
|
+
const url = new URL('/v1/onChainSignersByFid', hubUrl)
|
|
41
|
+
url.searchParams.append('fid', fid.toString())
|
|
42
|
+
const response = await fetch(url, requestOptions)
|
|
40
43
|
if (response.status !== 200) {
|
|
41
|
-
|
|
44
|
+
throw new BaseError(`Non-200 response received: ${await response.text()}`)
|
|
42
45
|
}
|
|
43
|
-
const responseJson = await response.json()
|
|
44
|
-
const parsedResponse = hubResponseSchema.safeParse(responseJson)
|
|
46
|
+
const responseJson = await response.json()
|
|
47
|
+
const parsedResponse = hubResponseSchema.safeParse(responseJson)
|
|
45
48
|
if (parsedResponse.error) {
|
|
46
|
-
|
|
49
|
+
throw new BaseError('Error parsing Hub response', parsedResponse.error)
|
|
47
50
|
}
|
|
48
|
-
const appKeyLower = appKey.toLowerCase()
|
|
49
|
-
const signerEvent = parsedResponse.data.events.find(
|
|
51
|
+
const appKeyLower = appKey.toLowerCase()
|
|
52
|
+
const signerEvent = parsedResponse.data.events.find(
|
|
53
|
+
(event) => event.signerEventBody.key.toLowerCase() === appKeyLower,
|
|
54
|
+
)
|
|
50
55
|
if (!signerEvent) {
|
|
51
|
-
|
|
56
|
+
return { valid: false }
|
|
52
57
|
}
|
|
53
|
-
const decoded = AbiParameters.decode(
|
|
58
|
+
const decoded = AbiParameters.decode(
|
|
59
|
+
signedKeyRequestAbi,
|
|
60
|
+
Buffer.from(signerEvent.signerEventBody.metadata, 'base64'),
|
|
61
|
+
)
|
|
54
62
|
if (decoded.length !== 1) {
|
|
55
|
-
|
|
63
|
+
throw new BaseError('Error decoding metadata')
|
|
56
64
|
}
|
|
57
|
-
const appFid = Number(decoded[0].requestFid)
|
|
58
|
-
return { valid: true, appFid }
|
|
59
|
-
}
|
|
65
|
+
const appFid = Number(decoded[0].requestFid)
|
|
66
|
+
return { valid: true, appFid }
|
|
67
|
+
}
|
package/esm/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
1
|
+
export * from '@farcaster/frame-core'
|
|
2
|
+
export * from './jfs'
|
|
3
|
+
export * from './neynar'
|
|
4
|
+
export * from './farcaster'
|
|
5
|
+
export * from './types'
|
|
6
|
+
export * from './webhook'
|
|
7
|
+
export * from './util'
|
package/esm/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
1
|
+
export * from '@farcaster/frame-core'
|
|
2
|
+
export * from './jfs'
|
|
3
|
+
export * from './neynar'
|
|
4
|
+
export * from './farcaster'
|
|
5
|
+
export * from './types'
|
|
6
|
+
export * from './webhook'
|
|
7
|
+
export * from './util'
|
package/esm/jfs.d.ts
CHANGED
|
@@ -1,21 +1,38 @@
|
|
|
1
|
-
import { EncodedJsonFarcasterSignatureSchema } from
|
|
2
|
-
import { BaseError, VerifyAppKey, VerifyJfsResult } from
|
|
1
|
+
import type { EncodedJsonFarcasterSignatureSchema } from '@farcaster/frame-core'
|
|
2
|
+
import { BaseError, type VerifyAppKey, type VerifyJfsResult } from './types'
|
|
3
3
|
export declare namespace VerifyJsonFarcasterSignature {
|
|
4
|
-
|
|
4
|
+
type ErrorType =
|
|
5
|
+
| InvalidJfsDataError
|
|
6
|
+
| InvalidJfsAppKeyError
|
|
7
|
+
| VerifyAppKeyError
|
|
5
8
|
}
|
|
6
|
-
export declare class InvalidJfsDataError<
|
|
7
|
-
|
|
9
|
+
export declare class InvalidJfsDataError<
|
|
10
|
+
C extends Error | undefined = undefined,
|
|
11
|
+
> extends BaseError<C> {
|
|
12
|
+
readonly name = 'VerifyJsonFarcasterSignature.InvalidDataError'
|
|
8
13
|
}
|
|
9
|
-
export declare class InvalidJfsAppKeyError<
|
|
10
|
-
|
|
14
|
+
export declare class InvalidJfsAppKeyError<
|
|
15
|
+
C extends Error | undefined = undefined,
|
|
16
|
+
> extends BaseError<C> {
|
|
17
|
+
readonly name = 'VerifyJsonFarcasterSignature.InvalidAppKeyError'
|
|
11
18
|
}
|
|
12
|
-
export declare class VerifyAppKeyError<
|
|
13
|
-
|
|
19
|
+
export declare class VerifyAppKeyError<
|
|
20
|
+
C extends Error | undefined = undefined,
|
|
21
|
+
> extends BaseError<C> {
|
|
22
|
+
readonly name = 'VerifyJsonFarcasterSignature.VerifyAppKeyError'
|
|
14
23
|
}
|
|
15
|
-
export declare function verifyJsonFarcasterSignature(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
export declare function verifyJsonFarcasterSignature(
|
|
25
|
+
data: unknown,
|
|
26
|
+
verifyAppKey: VerifyAppKey,
|
|
27
|
+
): Promise<VerifyJfsResult>
|
|
28
|
+
export declare function createJsonFarcasterSignature({
|
|
29
|
+
fid,
|
|
30
|
+
type,
|
|
31
|
+
privateKey,
|
|
32
|
+
payload,
|
|
33
|
+
}: {
|
|
34
|
+
fid: number
|
|
35
|
+
type: 'app_key'
|
|
36
|
+
privateKey: Uint8Array
|
|
37
|
+
payload: Uint8Array
|
|
38
|
+
}): EncodedJsonFarcasterSignatureSchema
|