-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
added packages
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { gossipsub } from '@chainsafe/libp2p-gossipsub' | ||
import { noise } from '@chainsafe/libp2p-noise' | ||
import { yamux } from '@chainsafe/libp2p-yamux' | ||
import { circuitRelayTransport } from '@libp2p/circuit-relay-v2' | ||
import { identify } from '@libp2p/identify' | ||
import { mdns } from '@libp2p/mdns' | ||
import { tcp } from '@libp2p/tcp' | ||
import { webRTC } from '@libp2p/webrtc' | ||
import { webSockets } from '@libp2p/websockets' | ||
import { all } from '@libp2p/websockets/filters' | ||
|
||
import type { Libp2pOptions } from 'libp2p' | ||
|
||
export const DefaultLibp2pOptions: Libp2pOptions = { | ||
addresses: { | ||
listen: ['/ip4/127.0.0.1/tcp/0/ws'], | ||
}, | ||
peerDiscovery: [mdns()], | ||
transports: [ | ||
tcp(), | ||
webRTC(), | ||
webSockets({ filter: all }), | ||
circuitRelayTransport({ discoverRelays: 1 }), | ||
], | ||
connectionEncryption: [noise()], | ||
streamMuxers: [yamux()], | ||
connectionGater: { | ||
denyDialMultiaddr: () => false, | ||
}, | ||
services: { | ||
identify: identify(), | ||
pubsub: gossipsub({ allowPublishToZeroTopicPeers: true }), | ||
}, | ||
} | ||
|
||
export const DefaultLibp2pBrowserOptions: Libp2pOptions = { | ||
addresses: { | ||
listen: ['/webrtc'], | ||
}, | ||
transports: [ | ||
tcp(), | ||
webRTC(), | ||
webSockets({ filter: all }), | ||
circuitRelayTransport({ discoverRelays: 1 }), | ||
], | ||
connectionEncryption: [noise()], | ||
streamMuxers: [yamux()], | ||
connectionGater: { | ||
denyDialMultiaddr: () => false, | ||
}, | ||
services: { | ||
identify: identify(), | ||
pubsub: gossipsub({ allowPublishToZeroTopicPeers: true }), | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { bitswap } from '@helia/block-brokers' | ||
import { Identities, KeyStore, OrbitDBAccessController, PublicKeyIdentityProvider, createOrbitDB } from '@orbitdb/core' | ||
import { createHelia } from 'helia' | ||
import { createLibp2p } from 'libp2p' | ||
|
||
import { DefaultLibp2pOptions } from './config' | ||
import initLogger from '@regioni/lib/logger' | ||
|
||
const id = 'userA' | ||
const keysPath = './.out/keys' | ||
const options = DefaultLibp2pOptions | ||
|
||
const logger = initLogger() | ||
|
||
const ipfs = await createHelia({ | ||
libp2p: await createLibp2p({ ...options }), | ||
// blockstore: new LevelBlockstore(levelPath), | ||
blockBrokers: [bitswap()], | ||
}) | ||
|
||
await ipfs.start() | ||
|
||
const keystore = await KeyStore({ path: keysPath }) | ||
const identities = await Identities({ keystore, ipfs }) | ||
const provider = PublicKeyIdentityProvider({ keystore }) | ||
|
||
const identity = await identities.createIdentity({ id, provider }) | ||
const result = await identities.getIdentity(identity.hash) | ||
|
||
logger.log('result', result) | ||
logger.log('address', ipfs.libp2p.peerId) | ||
|
||
const orbit = await createOrbitDB({ | ||
id: 'orbitdb-AAA', | ||
ipfs, | ||
identities, | ||
identity, | ||
directory: './.out/orbitdb', | ||
}) | ||
|
||
const db = await orbit.open('test', { | ||
type: 'events', | ||
AccessController: OrbitDBAccessController({ | ||
write: [identity.id], | ||
}), | ||
}) | ||
|
||
for (let i = 0; i < 10; i++) { | ||
await db.add({ message: `Hello, world! ${i}` }) | ||
} | ||
|
||
logger.log('db', db.address) | ||
|
||
// await ipfs.stop() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { bitswap } from '@helia/block-brokers' | ||
import { | ||
createOrbitDB, | ||
} from '@orbitdb/core' | ||
import { LevelBlockstore } from 'blockstore-level' | ||
import { createHelia } from 'helia' | ||
import { createLibp2p } from 'libp2p' | ||
|
||
import { DefaultLibp2pBrowserOptions, DefaultLibp2pOptions } from './config' | ||
import initLogger from '@regioni/lib/logger' | ||
|
||
import type { | ||
CreateOrbitDBOptions, | ||
OrbitDBInstance, | ||
} from '@orbitdb/core' | ||
|
||
const logger = initLogger() | ||
|
||
let spied: any | ||
|
||
const isBrowser = () => typeof window !== 'undefined' | ||
export async function startOrbitDB({ | ||
id, | ||
identity, | ||
identities, | ||
directory = '.', | ||
}: Omit<CreateOrbitDBOptions, 'ipfs'>) { | ||
const options = isBrowser() | ||
? DefaultLibp2pBrowserOptions | ||
: DefaultLibp2pOptions | ||
|
||
const ipfs = await createHelia({ | ||
libp2p: await createLibp2p({ ...options }), | ||
blockstore: new LevelBlockstore(`${directory}/ipfs/blocks`), | ||
blockBrokers: [bitswap()], | ||
}) | ||
|
||
return createOrbitDB({ | ||
id, | ||
identity, | ||
identities, | ||
directory, | ||
ipfs, | ||
}) | ||
} | ||
|
||
export async function stopOrbitDB(orbitdb: OrbitDBInstance): Promise<void> { | ||
await orbitdb.stop() | ||
await orbitdb.ipfs.stop() | ||
|
||
logger.debug('orbitdb stopped', spied.calls, spied.returns) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
**/*.test.* |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
telemetry.enabled=false | ||
telemetry.consent=1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{ | ||
"recommendations": [ | ||
"aaron-bond.better-comments", | ||
"alefragnani.bookmarks", | ||
"aliariff.auto-add-brackets", | ||
"antfu.auto-npx", | ||
"antfu.file-nesting", | ||
"antfu.goto-alias", | ||
"antfu.iconify", | ||
"antfu.vite", | ||
"antfu.where-am-i", | ||
"arcanis.vscode-zipfs", | ||
"bibhasdn.unique-lines", | ||
"bierner.markdown-yaml-preamble", | ||
"bmalehorn.print-it", | ||
"bradlc.vscode-tailwindcss", | ||
"Cardinal90.multi-cursor-case-preserve", | ||
"christian-kohler.npm-intellisense", | ||
"christian-kohler.path-intellisense", | ||
"Codeium.codeium", | ||
"cpylua.language-postcss", | ||
"dbaeumer.vscode-eslint", | ||
"eamodio.gitlens", | ||
"editorconfig.editorconfig", | ||
"esbenp.prettier-vscode", | ||
"formulahendry.auto-rename-tag", | ||
"foxundermoon.shell-format", | ||
"helixquar.randomeverything", | ||
"heybourn.headwind", | ||
"howardzuo.vscode-npm-dependency", | ||
"IBM.output-colorizer", | ||
"kisstkondoros.vscode-codemetrics", | ||
"lacroixdavid1.vscode-format-context-menu", | ||
"lokalise.i18n-ally", | ||
"maciejdems.add-to-gitignore", | ||
"MatthewNespor.vscode-color-identifiers-mode", | ||
"Med-H.color-me", | ||
"mflo999.lintel", | ||
"mhutchie.git-graph", | ||
"micnil.vscode-checkpoints", | ||
"mikestead.dotenv", | ||
"mkxml.vscode-filesize", | ||
"ms-vscode.vscode-js-profile-flame", | ||
"Nuxt.mdc", | ||
"oderwat.indent-rainbow", | ||
"phind.phind", | ||
"piotrpalarz.vscode-gitignore-generator", | ||
"quicktype.quicktype", | ||
"solomonkinard.git-search", | ||
"stackbreak.comment-divider", | ||
"stivo.tailwind-fold", | ||
"stylelint.vscode-stylelint", | ||
"tombonnike.vscode-status-bar-format-toggle", | ||
"Tyriar.sort-lines", | ||
"usernamehw.errorlens", | ||
"VisualStudioExptTeam.vscodeintellicode", | ||
"vivaxy.vscode-conventional-commits", | ||
"vue.volar", | ||
"wejectchan.vue3-snippets-for-vscode", | ||
"wmaurer.change-case", | ||
"yatki.vscode-surround", | ||
"yoavbls.pretty-ts-errors", | ||
"Yseop.vscode-yseopml", | ||
"zardoy.ts-essential-plugins" | ||
], | ||
"unwantedRecommendations": ["vscode.typescript-language-features"] | ||
} |