feat: auto-generate manifest

This commit is contained in:
lucas-neynar
2025-03-13 12:39:59 -07:00
parent 51f8c92eb3
commit b168e34521
14 changed files with 289 additions and 29 deletions

43
bin/manifest.js Normal file
View File

@@ -0,0 +1,43 @@
// utils to generate a manifest.json file for a frames v2 app
const { mnemonicToAccount } = require('viem/accounts');
async function generateManifest(fid, seedPhrase) {
if (!Number.isInteger(fid) || fid <= 0) {
throw new Error('FID must be a positive integer');
}
let account;
try {
account = mnemonicToAccount(seedPhrase);
} catch (error) {
throw new Error('Invalid seed phrase');
}
const custodyAddress = account.address;
const header = {
fid,
type: 'custody', // question: do we want to support type of 'app_key', which indicates the signature is from a registered App Key for the FID
key: custodyAddress,
};
const encodedHeader = Buffer.from(JSON.stringify(header), 'utf-8').toString('base64');
const payload = {
domain: 'warpcast.com'
};
const encodedPayload = Buffer.from(JSON.stringify(payload), 'utf-8').toString('base64url');
const signature = await account.signMessage({
message: `${encodedHeader}.${encodedPayload}`
});
const encodedSignature = Buffer.from(signature, 'utf-8').toString('base64url');
const jsonJfs = {
header: encodedHeader,
payload: encodedPayload,
signature: encodedSignature
};
return jsonJfs;
}
module.exports = { generateManifest };