@farcaster/snap 1.2.0 → 1.2.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/server/hubs.js +16 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/verify.d.ts +1 -0
- package/dist/server/verify.js +5 -2
- package/package.json +2 -3
- package/src/server/hubs.ts +41 -5
- package/src/server/index.ts +1 -1
- package/src/server/verify.ts +7 -2
package/dist/server/hubs.js
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
|
-
import { OnChainEventType, SignerEventType, } from "@farcaster/hub-nodejs";
|
|
2
1
|
import { decodeAbiParameters } from "viem";
|
|
2
|
+
// Protobuf enum values from @farcaster/hub-nodejs, inlined to avoid pulling
|
|
3
|
+
// in the full gRPC stack (which is incompatible with Edge runtimes).
|
|
4
|
+
const OnChainEventType = {
|
|
5
|
+
EVENT_TYPE_NONE: 0,
|
|
6
|
+
EVENT_TYPE_SIGNER: 1,
|
|
7
|
+
EVENT_TYPE_SIGNER_MIGRATED: 2,
|
|
8
|
+
EVENT_TYPE_ID_REGISTER: 3,
|
|
9
|
+
EVENT_TYPE_STORAGE_RENT: 4,
|
|
10
|
+
EVENT_TYPE_TIER_PURCHASE: 5,
|
|
11
|
+
};
|
|
12
|
+
const SignerEventType = {
|
|
13
|
+
NONE: 0,
|
|
14
|
+
ADD: 1,
|
|
15
|
+
REMOVE: 2,
|
|
16
|
+
ADMIN_RESET: 3,
|
|
17
|
+
};
|
|
3
18
|
// ---------------------------------------------------------------------------
|
|
4
19
|
// Hex (hub HTTP JSON decoders)
|
|
5
20
|
// ---------------------------------------------------------------------------
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { verifyJFSRequestBody, decodePayload } from "./verify.js";
|
|
1
|
+
export { verifyJFSRequestBody, decodePayload, encodePayload } from "./verify.js";
|
|
2
2
|
export { DEFAULT_SNAP_HUB_HTTP_BASE_URL, getActiveEd25519SignerKeysFromHubHttp, } from "./hubs.js";
|
|
3
3
|
export { parseRequest, type ParseRequestError, type ParseRequestOptions, type ParseRequestResult, } from "./parseRequest.js";
|
package/dist/server/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { verifyJFSRequestBody, decodePayload } from "./verify.js";
|
|
1
|
+
export { verifyJFSRequestBody, decodePayload, encodePayload } from "./verify.js";
|
|
2
2
|
export { DEFAULT_SNAP_HUB_HTTP_BASE_URL, getActiveEd25519SignerKeysFromHubHttp, } from "./hubs.js";
|
|
3
3
|
export { parseRequest, } from "./parseRequest.js";
|
package/dist/server/verify.d.ts
CHANGED
package/dist/server/verify.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { compact, decode, decodePayload as jfsDecodePayload,
|
|
1
|
+
import { compact, decode, decodePayload as jfsDecodePayload, encodePayload as jfsEncodePayload, verify, } from "@farcaster/jfs";
|
|
2
2
|
import { hexToBytes } from "viem";
|
|
3
3
|
import { DEFAULT_SNAP_HUB_HTTP_BASE_URL, getActiveEd25519SignerKeysFromHubHttp, } from "./hubs.js";
|
|
4
4
|
export async function verifyJFSRequestBody(requestBody, options = {}) {
|
|
@@ -27,7 +27,7 @@ export async function verifyJFSRequestBody(requestBody, options = {}) {
|
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
try {
|
|
30
|
-
await
|
|
30
|
+
await verify({ data: compactJfs, strict: true, keyTypes: ["app_key"] });
|
|
31
31
|
}
|
|
32
32
|
catch (error) {
|
|
33
33
|
return {
|
|
@@ -74,6 +74,9 @@ export async function verifyJFSRequestBody(requestBody, options = {}) {
|
|
|
74
74
|
export function decodePayload(payload) {
|
|
75
75
|
return jfsDecodePayload(payload);
|
|
76
76
|
}
|
|
77
|
+
export function encodePayload(payload) {
|
|
78
|
+
return jfsEncodePayload(payload);
|
|
79
|
+
}
|
|
77
80
|
function bytesEqual(a, b) {
|
|
78
81
|
if (a.length !== b.length)
|
|
79
82
|
return false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farcaster/snap",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "Farcaster Snaps 🫰",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -31,8 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"license": "MIT",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@farcaster/
|
|
35
|
-
"@farcaster/jfs": "^0.2.2",
|
|
34
|
+
"@farcaster/jfs": "^0.3.0",
|
|
36
35
|
"viem": "^2.21.0",
|
|
37
36
|
"zod": "^4.3.6"
|
|
38
37
|
},
|
package/src/server/hubs.ts
CHANGED
|
@@ -1,10 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
OnChainEventType,
|
|
3
|
-
SignerEventType,
|
|
4
|
-
type OnChainEvent,
|
|
5
|
-
} from "@farcaster/hub-nodejs";
|
|
6
1
|
import { decodeAbiParameters, type Hex } from "viem";
|
|
7
2
|
|
|
3
|
+
// Protobuf enum values from @farcaster/hub-nodejs, inlined to avoid pulling
|
|
4
|
+
// in the full gRPC stack (which is incompatible with Edge runtimes).
|
|
5
|
+
const OnChainEventType = {
|
|
6
|
+
EVENT_TYPE_NONE: 0,
|
|
7
|
+
EVENT_TYPE_SIGNER: 1,
|
|
8
|
+
EVENT_TYPE_SIGNER_MIGRATED: 2,
|
|
9
|
+
EVENT_TYPE_ID_REGISTER: 3,
|
|
10
|
+
EVENT_TYPE_STORAGE_RENT: 4,
|
|
11
|
+
EVENT_TYPE_TIER_PURCHASE: 5,
|
|
12
|
+
} as const;
|
|
13
|
+
type OnChainEventType =
|
|
14
|
+
(typeof OnChainEventType)[keyof typeof OnChainEventType];
|
|
15
|
+
|
|
16
|
+
const SignerEventType = {
|
|
17
|
+
NONE: 0,
|
|
18
|
+
ADD: 1,
|
|
19
|
+
REMOVE: 2,
|
|
20
|
+
ADMIN_RESET: 3,
|
|
21
|
+
} as const;
|
|
22
|
+
type SignerEventType = (typeof SignerEventType)[keyof typeof SignerEventType];
|
|
23
|
+
|
|
24
|
+
type OnChainEvent = {
|
|
25
|
+
type: OnChainEventType;
|
|
26
|
+
chainId: number;
|
|
27
|
+
blockNumber: number;
|
|
28
|
+
blockHash: Uint8Array;
|
|
29
|
+
blockTimestamp: number;
|
|
30
|
+
transactionHash: Uint8Array;
|
|
31
|
+
logIndex: number;
|
|
32
|
+
fid: number;
|
|
33
|
+
txIndex?: number;
|
|
34
|
+
version?: number;
|
|
35
|
+
signerEventBody?: {
|
|
36
|
+
key: Uint8Array;
|
|
37
|
+
keyType: number;
|
|
38
|
+
eventType: SignerEventType;
|
|
39
|
+
metadata: Uint8Array;
|
|
40
|
+
metadataType?: number;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
8
44
|
// ---------------------------------------------------------------------------
|
|
9
45
|
// Hex (hub HTTP JSON decoders)
|
|
10
46
|
// ---------------------------------------------------------------------------
|
package/src/server/index.ts
CHANGED
package/src/server/verify.ts
CHANGED
|
@@ -2,7 +2,8 @@ import {
|
|
|
2
2
|
compact,
|
|
3
3
|
decode,
|
|
4
4
|
decodePayload as jfsDecodePayload,
|
|
5
|
-
|
|
5
|
+
encodePayload as jfsEncodePayload,
|
|
6
|
+
verify,
|
|
6
7
|
} from "@farcaster/jfs";
|
|
7
8
|
import { hexToBytes, type Hex } from "viem";
|
|
8
9
|
import {
|
|
@@ -54,7 +55,7 @@ export async function verifyJFSRequestBody<TPayload>(
|
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
try {
|
|
57
|
-
await
|
|
58
|
+
await verify({ data: compactJfs, strict: true, keyTypes: ["app_key"] });
|
|
58
59
|
} catch (error) {
|
|
59
60
|
return {
|
|
60
61
|
valid: false,
|
|
@@ -114,6 +115,10 @@ export function decodePayload<TPayload>(payload: string): TPayload {
|
|
|
114
115
|
return jfsDecodePayload<TPayload>(payload);
|
|
115
116
|
}
|
|
116
117
|
|
|
118
|
+
export function encodePayload<TPayload>(payload: TPayload): string {
|
|
119
|
+
return jfsEncodePayload(payload);
|
|
120
|
+
}
|
|
121
|
+
|
|
117
122
|
function bytesEqual(a: Uint8Array, b: Uint8Array): boolean {
|
|
118
123
|
if (a.length !== b.length) return false;
|
|
119
124
|
let diff = 0;
|