
[ad_1]
I am attempting to make a perform in javascript shopper aspect that permit’s a consumer enter anybody’s npub after which follows their followers. Nonetheless with nostr-tools it appears to be like like i want the consumer’s non-public key to signal a comply with occasion.
How would I do that in any other case? Clearly I will not have anybody’s non-public key.
// Your Nostr non-public key
//const privateKey = 'your_private_key'; // Exchange together with your precise non-public key
// Perform to get followers for a given npub
async perform getAndFollowUsersFollowers(targetNpub) {
//const { relayInit, finishEvent, generatePrivateKey, getPublicKey } = window.nostr;
const relayUrl="wss://relay.primal.web"; // Exchange together with your chosen relay URL
const shopper = new nostr.Shopper();
// Hook up with the relay
await shopper.join(relayUrl);
// Subscription to get 'meta' occasions
const subscription = {
filter: {
sorts: [4], // Form 4 for 'meta' occasions
authors: [targetNpub] // The npub of the goal consumer
},
cb: (occasion) => {
// Deal with the occasion - extract followers
if (occasion.content material && occasion.content material.comply with) {
occasion.content material.comply with.forEach(async (followerNpub) => {
// Observe every follower
await followUser(followerNpub, shopper);
});
}
}
};
shopper.subscribe(subscription);
}
// Perform to comply with a consumer
async perform followUser(followerNpub, shopper) {
const { pubkey } = (await window.webln.getInfo()).node;
const occasion = {
pubkey,
variety: 4, // Form 4 for 'meta' occasions
content material: {
comply with: [followerNpub]
},
tags: [],
created_at: Math.ground(new Date().getTime() / 1000),
};
// Signal the occasion together with your non-public key
occasion.id = nostr.getEventId(occasion, privateKey);
occasion.sig = nostr.getEventSignature(occasion, privateKey);
// Publish the occasion
await shopper.publish(occasion);
}
[ad_2]
Supply hyperlink