relay-plugin-ipfs/src/index.ts

31 lines
719 B
TypeScript
Raw Normal View History

import type { Plugin, PluginAPI } from "@lumeweb/relay-types";
2023-04-17 00:52:56 +00:00
import { MultiSocketProxy } from "@lumeweb/libhyperproxy";
2022-08-29 22:45:01 +00:00
const PROTOCOL = "lumeweb.proxy.ipfs";
2022-08-29 22:45:01 +00:00
interface PeerInfoResult {
publicKey: Uint8Array;
libp2pPublicKey: Uint8Array;
2022-08-29 22:45:01 +00:00
}
const plugin: Plugin = {
name: "ipfs",
async plugin(api: PluginAPI): Promise<void> {
2023-04-17 00:52:56 +00:00
const proxy = new MultiSocketProxy({
swarm: api.swarm,
protocol: PROTOCOL,
2023-04-17 04:23:15 +00:00
allowedPorts: [4001, 4002],
2023-04-17 00:52:56 +00:00
server: true,
2022-08-29 22:45:01 +00:00
});
2023-04-17 00:52:56 +00:00
api.swarm.join(api.util.crypto.createHash(PROTOCOL));
api.protocols.register(PROTOCOL, (peer: any, muxer: any) => {
proxy.handlePeer({
peer,
muxer,
});
2022-08-29 22:45:01 +00:00
});
},
};
export default plugin;