mirror of
https://github.com/neynarxyz/create-farcaster-mini-app.git
synced 2025-11-19 09:26:07 -05:00
feat: auto-generate manifest
This commit is contained in:
43
bin/manifest.js
Normal file
43
bin/manifest.js
Normal 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 };
|
||||
Reference in New Issue
Block a user