├── .dockerignore ├── .github ├── FUNDING.yml └── workflows │ └── ci.yml ├── .gitignore ├── .npmignore ├── .prettierignore ├── .travis.yml ├── CHANGELOG.md ├── Dockerfile ├── LICENSE.md ├── Procfile ├── README.md ├── RELEASE.md ├── SECURITY.md ├── app.json ├── as.js ├── axe.js ├── bower.json ├── browser.js ├── examples ├── .gitignore ├── Main.js ├── angular │ ├── .angular-cli.json │ ├── .editorconfig │ ├── .gitignore │ ├── README.md │ ├── e2e │ │ ├── app.e2e-spec.ts │ │ ├── app.po.ts │ │ └── tsconfig.e2e.json │ ├── example_package.json │ ├── karma.conf.js │ ├── protractor.conf.js │ ├── server.js │ ├── src │ │ ├── app │ │ │ ├── app.component.css │ │ │ ├── app.component.html │ │ │ ├── app.component.spec.ts │ │ │ ├── app.component.ts │ │ │ ├── app.module.ts │ │ │ ├── gun.helper.ts │ │ │ └── gun.service.ts │ │ ├── assets │ │ │ └── .gitkeep │ │ ├── environments │ │ │ ├── environment.prod.ts │ │ │ └── environment.ts │ │ ├── favicon.ico │ │ ├── index.html │ │ ├── main.ts │ │ ├── polyfills.ts │ │ ├── styles.css │ │ ├── test.ts │ │ ├── tsconfig.app.json │ │ ├── tsconfig.spec.json │ │ └── typings.d.ts │ ├── tsconfig.json │ └── tslint.json ├── axe.html ├── basic │ ├── chat.html │ ├── emoji.html │ ├── meet.html │ ├── note.html │ ├── paste.html │ ├── poll.html │ ├── post.html │ ├── private.html │ ├── schedule.html │ ├── screen.html │ ├── stream.html │ ├── tables.html │ ├── upload.html │ ├── user.html │ └── video.html ├── chat │ ├── index.html │ └── user.html ├── contact │ └── index.html ├── docs.html ├── express.js ├── game │ ├── furball.html │ ├── nts.html │ ├── space.html │ └── win.html ├── hapi.js ├── http.js ├── https.sh ├── index.html ├── infinite-scroll │ ├── ScrollWindow.js │ ├── index.html │ ├── index.js │ └── style.css ├── install.sh ├── iris ├── jquery.js ├── json │ └── index.html ├── move │ └── index.html ├── party.html ├── pop.png ├── react-native │ ├── .babelrc │ ├── .buckconfig │ ├── .flowconfig │ ├── .gitattributes │ ├── .gitignore │ ├── .watchmanconfig │ ├── README.md │ ├── android │ │ ├── app │ │ │ ├── BUCK │ │ │ ├── build.gradle │ │ │ ├── proguard-rules.pro │ │ │ └── src │ │ │ │ └── main │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── assets │ │ │ │ └── html │ │ │ │ │ └── blank.html │ │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── gundemo │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ └── MainApplication.java │ │ │ │ └── res │ │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ └── values │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ ├── build.gradle │ │ ├── gradle.properties │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ ├── keystores │ │ │ ├── BUCK │ │ │ └── debug.keystore.properties │ │ └── settings.gradle │ ├── app.json │ ├── index.js │ ├── ios │ │ ├── GunDemo-tvOS │ │ │ └── Info.plist │ │ ├── GunDemo-tvOSTests │ │ │ └── Info.plist │ │ ├── GunDemo.xcodeproj │ │ │ └── project.pbxproj │ │ ├── GunDemo │ │ │ ├── AppDelegate.h │ │ │ ├── AppDelegate.m │ │ │ ├── Base.lproj │ │ │ │ └── LaunchScreen.xib │ │ │ ├── Images.xcassets │ │ │ │ ├── AppIcon.appiconset │ │ │ │ │ └── Contents.json │ │ │ │ └── Contents.json │ │ │ ├── Info.plist │ │ │ └── main.m │ │ └── GunDemoTests │ │ │ ├── GunDemoTests.m │ │ │ └── Info.plist │ ├── package.json │ ├── shim.js │ └── src │ │ ├── App │ │ ├── Demo.js │ │ ├── PolyFillCrypto.js │ │ ├── app.js │ │ └── index.js │ │ ├── extensions │ │ ├── asyncStorageAdapter.js │ │ └── sea.js │ │ └── webview-crypto │ │ ├── MainWorker.d.ts │ │ ├── MainWorker.js │ │ ├── MainWorker.js.map │ │ ├── WebViewWorker.d.ts │ │ ├── WebViewWorker.js │ │ ├── WebViewWorker.js.map │ │ ├── asyncSerialize.d.ts │ │ ├── asyncSerialize.js │ │ ├── asyncSerialize.js.map │ │ ├── compat.d.ts │ │ ├── compat.js │ │ ├── compat.js.map │ │ ├── index.d.ts │ │ ├── index.js │ │ ├── index.js.map │ │ ├── serializeBinary.d.ts │ │ ├── serializeBinary.js │ │ ├── serializeBinary.js.map │ │ ├── webViewWorkerString.d.ts │ │ ├── webViewWorkerString.js │ │ └── webViewWorkerString.js.map ├── react │ ├── README.md │ ├── public │ │ ├── favicon.ico │ │ └── index.html │ ├── src │ │ ├── App.js │ │ ├── App.test.js │ │ ├── Chat.js │ │ ├── Json.js │ │ ├── Todos.js │ │ ├── index.css │ │ ├── index.js │ │ └── style.css │ └── todo.html ├── relay.service ├── smoothie.js ├── start.js.html ├── stats.html ├── style.css ├── todo │ └── index.html ├── vanilla │ ├── screen.html │ ├── todo.html │ ├── user.html │ └── video.html ├── vue │ ├── index.html │ └── todo.html ├── wave.html ├── webpack │ ├── .gitignore │ ├── package.json │ ├── src │ │ ├── app.js │ │ └── index.html │ └── webpack.config.js └── where │ └── index.html ├── gun.d.ts ├── gun.js ├── gun.min.js ├── hooks ├── build └── post_push ├── index.d.ts ├── index.js ├── lib ├── afore.js ├── aws.js ├── axe.js ├── book.js ├── bye.js ├── crashed.js ├── cryptomodules.js ├── debug.js ├── dom.js ├── email.js ├── erase.js ├── evict.js ├── file.js ├── forget.js ├── fork.js ├── fsrm.js ├── fun.js ├── hot.js ├── http.js ├── hub.js ├── ipfs.js ├── ison.js ├── jsonp.js ├── later.d.ts ├── later.js ├── les.js ├── level.js ├── lex.js ├── list.js ├── load.d.ts ├── load.js ├── match.js ├── memdisk.js ├── meta.js ├── mix.js ├── mobile.js ├── monotype.js ├── multicast.js ├── nomem.js ├── normalize.js ├── not.d.ts ├── not.js ├── open.d.ts ├── open.js ├── path.d.ts ├── path.js ├── promise.d.ts ├── promise.js ├── radisk.d.ts ├── radisk.js ├── radisk2.js ├── radix.d.ts ├── radix.js ├── radix2.js ├── radmigtmp.js ├── ras.js ├── reboot.js ├── rfs.js ├── rfsmix.js ├── rindexed.d.ts ├── rindexed.js ├── rls.js ├── rmem.js ├── role.js ├── rs3.js ├── serve.js ├── server.js ├── service.js ├── shim.js ├── space.js ├── stats.js ├── store.d.ts ├── store.js ├── super.js ├── text-encoding │ ├── LICENSE.md │ ├── README.md │ ├── index.js │ ├── lib │ │ ├── encoding-indexes.js │ │ └── encoding.js │ └── package.json ├── then.d.ts ├── then.js ├── time.js ├── unbuild.js ├── unset.d.ts ├── unset.js ├── untitled.js ├── upload.js ├── utils.js ├── uws.js ├── verify.js ├── wave.js ├── webrtc.d.ts ├── webrtc.js ├── wire.js ├── ws.js ├── wsp.js ├── wsproto.js └── yson.js ├── nts.js ├── package-lock.json ├── package.json ├── rad.js ├── sea.d.ts ├── sea.js ├── sea ├── aeskey.js ├── array.js ├── auth.js ├── base64.js ├── buffer.js ├── certify.js ├── create.js ├── decrypt.js ├── encrypt.js ├── https.js ├── index.js ├── pair.js ├── recall.js ├── root.js ├── sea.js ├── secret.js ├── settings.js ├── sha1.js ├── sha256.js ├── share.js ├── shim.js ├── sign.js ├── then.js ├── user.js ├── verify.js └── work.js ├── src ├── ask.js ├── back.js ├── book.js ├── chain.js ├── core.js ├── dup.js ├── get.js ├── index.js ├── localStorage.js ├── map.js ├── mesh.js ├── on.js ├── onto.js ├── polyfill │ └── unbuild.js ├── put.js ├── root.js ├── set.js ├── shim.js ├── state.js ├── valid.js └── websocket.js ├── test ├── abc.js ├── bug │ ├── 121.js │ ├── 1243.js │ ├── 322.js │ ├── 686.js │ └── 783.js ├── common.js ├── debug │ └── deep-set.html ├── download-log.html ├── expect.js ├── gun.html ├── https │ ├── ca.crt │ ├── ca.csr │ ├── ca.key │ ├── server.crt │ ├── server.csr │ ├── server.key │ ├── server.key.passphrase │ └── test.js ├── hub │ ├── .hubignore │ ├── hub-test.js │ ├── index.html │ └── whatever │ │ └── aws-key.txt ├── index.js ├── json2.js ├── mocha.css ├── mocha.html ├── mocha.js ├── normalize │ └── normalize.html ├── old │ ├── all.js │ ├── interface.js │ ├── performance.js │ ├── s3pricing.html │ ├── server.js │ ├── set.js │ ├── shoot.html │ ├── shoot.js │ ├── shotgun.js │ ├── timelines.txt │ └── tmp.js ├── panic.html ├── panic │ ├── 1putackget.js │ ├── 2getget.js │ ├── 3puts.js │ ├── 4putackdedup.js │ ├── axe │ │ ├── 1no_self.js │ │ ├── 2no_dup.js │ │ ├── 3get_turns.js │ │ ├── 4get_subs.js │ │ ├── 5mob.js │ │ ├── data_balance.js │ │ ├── data_balance_webrtc.js │ │ ├── index.html │ │ └── load_balance.js │ ├── b2s2s2b.js │ ├── bulkimport.js │ ├── chat-user.js │ ├── chat.js │ ├── curl-server.js │ ├── e2e │ │ ├── distributed.js │ │ ├── holy │ │ │ ├── grail.js │ │ │ ├── gun-server.js │ │ │ ├── index.html │ │ │ └── ports.json │ │ └── package.json │ ├── holy-grail.js │ ├── index.html │ ├── infinite-scroll │ │ ├── index.html │ │ └── index.js │ ├── large-nodes.js │ ├── latency.js │ ├── level.js │ ├── lexical.js │ ├── livestream.js │ ├── load.js │ ├── no-override.js │ ├── on-recovery.js │ ├── radisk.js │ ├── s2s-all-delayed-peer-add.js │ ├── s2s-all.js │ ├── scale.js │ ├── set.js │ ├── shocknet.js │ ├── speak.js │ ├── thread.js │ ├── user-paste.js │ ├── users.js │ ├── util │ │ ├── load-browser-scripts.js │ │ └── open.js │ └── who.js ├── ptsd │ ├── benchmark.js │ ├── memdisk.html │ ├── memdisk.js │ ├── memory.html │ ├── perf.js │ ├── ptsd.html │ ├── ptsd.js │ ├── radix.html │ ├── radix.js │ ├── spam.js │ ├── stool.css │ └── streampipe.js ├── rad │ ├── 2020and2021.js │ ├── bench.js │ ├── book.html │ ├── book.js │ ├── browser.html │ ├── crash.js │ ├── mocha.html │ ├── old2020json │ │ ├── ! │ │ └── %1C │ ├── parse.rad │ ├── rad.book.spec.js │ ├── rad.js │ └── recover.js ├── radix.js ├── sea │ ├── nodeauth.js │ ├── sea-tmp.html │ ├── sea.html │ ├── sea.js │ └── sea_old.js ├── server │ ├── http.js │ ├── node-client.js │ └── node-write.js ├── tmp │ ├── bigsync.js │ ├── contact.html │ ├── contacts.html │ ├── indexedDB.html │ ├── mitra │ │ ├── client_to_server.js │ │ └── gun_https2.js │ ├── radisk.html │ ├── say.html │ ├── seanode.js │ ├── space.html │ ├── time.html │ └── tmp.html ├── trace.html ├── trace.js └── wire.txt ├── tsconfig.json └── types ├── gun ├── GunCallbackGet.d.ts ├── GunCallbackMap.d.ts ├── GunCallbackOn.d.ts ├── GunCallbackOnce.d.ts ├── GunCallbackPut.d.ts ├── GunDataNode.d.ts ├── GunHookCallbackBye.d.ts ├── GunHookCallbackCreate.d.ts ├── GunHookCallbackGet.d.ts ├── GunHookCallbackHi.d.ts ├── GunHookCallbackIn.d.ts ├── GunHookCallbackOpt.d.ts ├── GunHookCallbackOut.d.ts ├── GunHookCallbackPut.d.ts ├── GunNodeGet.d.ts ├── GunNodePut.d.ts ├── GunOptions.d.ts ├── GunOptionsOn.d.ts ├── GunOptionsOnce.d.ts ├── GunOptionsPut.d.ts ├── GunPeer.d.ts ├── GunSchema.d.ts ├── GunSoul.d.ts ├── GunValueSimple.d.ts ├── IGun.d.ts ├── IGunChain.d.ts ├── IGunHookContext.d.ts ├── IGunInstance.d.ts ├── IGunInstanceHookHandler.d.ts ├── IGunInstanceRoot.d.ts ├── IGunMeta.d.ts ├── IGunOnEvent.d.ts ├── LEX.d.ts ├── LEXQuery.d.ts ├── _GunRoot.d.ts ├── index.d.ts └── pany.d.ts ├── index.d.ts ├── sea ├── GunCallbackUserAuth.d.ts ├── GunCallbackUserCreate.d.ts ├── GunHookCallbackAuth.d.ts ├── GunUser.d.ts ├── IGun.d.ts ├── IGunInstance.d.ts ├── IGunInstanceHookHandler.d.ts ├── IGunInstanceRoot.d.ts ├── IGunUserInstance.d.ts ├── IPolicy.d.ts ├── ISEA.d.ts ├── ISEAPair.d.ts ├── OptionsUserAuth.d.ts ├── OptionsUserRecall.d.ts ├── Policy.d.ts └── index.d.ts ├── test ├── gun-back.test-d.ts ├── gun-get.test-d.ts ├── gun-instance.test-d.ts ├── gun-map.test-d.ts ├── gun-on.test-d.ts ├── gun-once.test-d.ts ├── gun-opt.test-d.ts ├── gun-put.test-d.ts ├── gun-set.test-d.ts ├── gun-user-auth.test-d.ts ├── gun-user-leave.test-d.ts ├── gun-user-recall.test-d.ts ├── gun-user.test-d.ts ├── sea-certify.test-d.ts └── sea.test-d.ts └── utils.d.ts /.dockerignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | radata 3 | stats.radata 4 | .git 5 | .gitignore 6 | *.md 7 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: amark 4 | patreon: gunDB 5 | open_collective: gun 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | yarn.lock 4 | *data.json 5 | *data* 6 | *.db 7 | .idea/ 8 | *.bak 9 | *.new 10 | *.log 11 | v8.json 12 | *.DS_store 13 | isolate*.log 14 | .esm-cache 15 | .sessionStorage 16 | .localStorage 17 | /types/**/*.ts 18 | !/types/**/*.d.ts 19 | !/types/**/*.test-d.ts 20 | /gun.ts 21 | /temp/ -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | *.ts 2 | /temp/ 3 | !*.d.ts 4 | *.radata 5 | isolate-* 6 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | * -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | branches: 3 | except: 4 | - debug 5 | - manhattan 6 | node_js: 7 | - 10 8 | cache: 9 | directories: 10 | - node_modules 11 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # install packages 2 | FROM node:lts-alpine as builder 3 | RUN mkdir /work 4 | WORKDIR /work 5 | RUN apk add --no-cache alpine-sdk python3 6 | COPY package*.json ./ 7 | RUN mkdir -p node_modules 8 | RUN npm ci --only=production 9 | 10 | # fresh image without dev packages 11 | FROM node:lts-alpine 12 | # build-time metadata as defined at http://label-schema.org 13 | ARG BUILD_DATE 14 | ARG VCS_REF 15 | ARG VCS_URL 16 | ARG VERSION 17 | LABEL org.label-schema.build-date=$BUILD_DATE \ 18 | org.label-schema.name="Gun - Offline First, Javascript Graph Database" \ 19 | org.label-schema.url="http://gun.js.org" \ 20 | org.label-schema.vcs-ref=$VCS_REF \ 21 | org.label-schema.vcs-url=$VCS_URL \ 22 | org.label-schema.vendor="The Gun Database Team" \ 23 | org.label-schema.version=$VERSION \ 24 | org.label-schema.schema-version="1.0" 25 | ARG SHA 26 | RUN mkdir /work 27 | WORKDIR /work 28 | COPY --from=builder /work/node_modules ./node_modules 29 | RUN npm rebuild -q 30 | ADD . . 31 | RUN echo "{ \"sha\": \"$SHA\" }" > version.json 32 | RUN cat version.json 33 | EXPOSE 8080 34 | EXPOSE 8765 35 | CMD ["npm","start"] 36 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: node --inspect examples/http.js -------------------------------------------------------------------------------- /RELEASE.md: -------------------------------------------------------------------------------- 1 | Every push or pull request will 2 | 3 | - run the tests 4 | 5 | Every push to master will 6 | 7 | - run the tests 8 | - publish the latest docker image to dockerhub 9 | 10 | Creating a tag that starts with `v` will 11 | 12 | - create a new github release 13 | - publish the release to npm 14 | - publish the release to dockerhub 15 | 16 | Creating a release from the github web interface will 17 | 18 | - publish the release to npm 19 | - publish the release to dockerhub 20 | 21 | Creating the release for version `0.2021.001` from the command line works as follows 22 | 23 | git tag v0.2021.001 24 | git push --tags 25 | 26 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gun-server", 3 | "website": "http://gun.eco/", 4 | "repository": "https://github.com/amark/gun", 5 | "logo": "https://avatars3.githubusercontent.com/u/8811914", 6 | "keywords": ["node", "gun", "gunDB", "database","graph","offline-first"], 7 | "description": "Javascript, Offline-First Javascript Graph Database Server Peer", 8 | "env": { 9 | "NPM_CONFIG_PRODUCTION": { 10 | "description": "If you do not want default features, set to \"true\".", 11 | "value": "false" 12 | }, 13 | "PEERS": { 14 | "description": "Comma-separated list of peer urls to connect to", 15 | "required": false 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gun", 3 | "main": "gun.js", 4 | "version": "0.1.5", 5 | "homepage": "http://gunDB.io", 6 | "authors": [ 7 | { "name": "Mark Nadal", "email": "mark@accelsor.com" }, 8 | { "name": "Alex LaFroscia", "email": "alex@lafroscia.com" } 9 | ], 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/amark/gun" 13 | }, 14 | "description": "A distributed, embedded, graph database engine.", 15 | "moduleType": [ 16 | "globals" 17 | ], 18 | "keywords": [ 19 | "graph", 20 | "database", 21 | "gun", 22 | "gundb", 23 | "nodb" 24 | ], 25 | "license": "MIT", 26 | "ignore": [ 27 | "**/.*", 28 | "node_modules", 29 | "bower_components", 30 | "test", 31 | "tests" 32 | ] 33 | } 34 | -------------------------------------------------------------------------------- /browser.js: -------------------------------------------------------------------------------- 1 | // if(!(typeof navigator == "undefined") && navigator.product == "ReactNative"){ 2 | // require("./lib/mobile.js"); 3 | // } 4 | module.exports = require('./gun.js'); 5 | -------------------------------------------------------------------------------- /examples/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/* 2 | npm-debug.log 3 | *data.json 4 | -------------------------------------------------------------------------------- /examples/angular/.angular-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "project": { 4 | "name": "angular" 5 | }, 6 | "apps": [ 7 | { 8 | "root": "src", 9 | "outDir": "dist", 10 | "assets": [ 11 | "assets", 12 | "favicon.ico" 13 | ], 14 | "index": "index.html", 15 | "main": "main.ts", 16 | "polyfills": "polyfills.ts", 17 | "test": "test.ts", 18 | "tsconfig": "tsconfig.app.json", 19 | "testTsconfig": "tsconfig.spec.json", 20 | "prefix": "app", 21 | "styles": [ 22 | "styles.css" 23 | ], 24 | "scripts": [], 25 | "environmentSource": "environments/environment.ts", 26 | "environments": { 27 | "dev": "environments/environment.ts", 28 | "prod": "environments/environment.prod.ts" 29 | } 30 | } 31 | ], 32 | "e2e": { 33 | "protractor": { 34 | "config": "./protractor.conf.js" 35 | } 36 | }, 37 | "lint": [ 38 | { 39 | "project": "src/tsconfig.app.json", 40 | "exclude": "**/node_modules/**" 41 | }, 42 | { 43 | "project": "src/tsconfig.spec.json" 44 | }, 45 | { 46 | "project": "e2e/tsconfig.e2e.json" 47 | } 48 | ], 49 | "test": { 50 | "karma": { 51 | "config": "./karma.conf.js" 52 | } 53 | }, 54 | "defaults": { 55 | "styleExt": "css", 56 | "component": {} 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /examples/angular/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /examples/angular/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | 8 | # dependencies 9 | /node_modules 10 | 11 | # IDEs and editors 12 | /.idea 13 | .project 14 | .classpath 15 | .c9/ 16 | *.launch 17 | .settings/ 18 | *.sublime-workspace 19 | 20 | # IDE - VSCode 21 | .vscode/* 22 | !.vscode/settings.json 23 | !.vscode/tasks.json 24 | !.vscode/launch.json 25 | !.vscode/extensions.json 26 | 27 | # misc 28 | /.sass-cache 29 | /connect.lock 30 | /coverage 31 | /libpeerconnection.log 32 | npm-debug.log 33 | testem.log 34 | /typings 35 | 36 | # e2e 37 | /e2e/*.js 38 | /e2e/*.map 39 | 40 | # System Files 41 | .DS_Store 42 | Thumbs.db 43 | -------------------------------------------------------------------------------- /examples/angular/README.md: -------------------------------------------------------------------------------- 1 | # Angular 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 1.0.0. 4 | 5 | ## Development server 6 | 7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive/pipe/service/class/module`. 12 | 13 | ## Build 14 | 15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build. 16 | 17 | ## Running unit tests 18 | 19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 20 | 21 | ## Running end-to-end tests 22 | 23 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 24 | Before running the tests make sure you are serving the app via `ng serve`. 25 | 26 | ## Further help 27 | 28 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 29 | -------------------------------------------------------------------------------- /examples/angular/e2e/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AngularPage } from './app.po'; 2 | 3 | describe('angular App', () => { 4 | let page: AngularPage; 5 | 6 | beforeEach(() => { 7 | page = new AngularPage(); 8 | }); 9 | 10 | it('should display message saying app works', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('app works!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /examples/angular/e2e/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, element, by } from 'protractor'; 2 | 3 | export class AngularPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /examples/angular/e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types":[ 8 | "jasmine", 9 | "node" 10 | ] 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/angular/example_package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular", 3 | "version": "0.0.0", 4 | "license": "MIT", 5 | "scripts": { 6 | "ng": "ng", 7 | "start": "ng serve", 8 | "build": "ng build", 9 | "test": "ng test", 10 | "lint": "ng lint", 11 | "e2e": "ng e2e" 12 | }, 13 | "private": true, 14 | "dependencies": { 15 | "@angular/common": "^4.1.0", 16 | "@angular/compiler": "^4.1.0", 17 | "@angular/core": "^4.1.0", 18 | "@angular/forms": "^4.1.0", 19 | "@angular/http": "^4.1.0", 20 | "@angular/platform-browser": "^4.1.0", 21 | "@angular/platform-browser-dynamic": "^4.1.0", 22 | "@angular/router": "^4.1.0", 23 | "core-js": "^2.4.1", 24 | "express-http-proxy": "^1.0.1", 25 | "gun": "https://github.com/amark/gun.git#master", 26 | "ngx-pipes": "^2.0.5", 27 | "rxjs": "^5.3.0", 28 | "underscore": "^1.8.3", 29 | "zone.js": "^0.8.9" 30 | }, 31 | "devDependencies": { 32 | "@angular/cli": "1.0.0", 33 | "@angular/compiler-cli": "^4.1.0", 34 | "@types/jasmine": "2.5.38", 35 | "@types/node": "~6.0.60", 36 | "@types/underscore": "^1.8.0", 37 | "codelyzer": "^2.1.1", 38 | "jasmine-core": "^2.6.1", 39 | "jasmine-spec-reporter": "^4.0.0", 40 | "karma": "^1.6.0", 41 | "karma-chrome-launcher": "~2.0.0", 42 | "karma-cli": "~1.0.1", 43 | "karma-coverage-istanbul-reporter": "^1.2.0", 44 | "karma-jasmine": "~1.1.0", 45 | "karma-jasmine-html-reporter": "^0.2.2", 46 | "protractor": "~5.1.0", 47 | "ts-node": "^3.0.2", 48 | "tslint": "~4.5.0", 49 | "typescript": "^2.3.2" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /examples/angular/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/0.13/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular/cli'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular/cli/plugins/karma') 14 | ], 15 | client:{ 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | files: [ 19 | { pattern: './src/test.ts', watched: false } 20 | ], 21 | preprocessors: { 22 | './src/test.ts': ['@angular/cli'] 23 | }, 24 | mime: { 25 | 'text/x-typescript': ['ts','tsx'] 26 | }, 27 | coverageIstanbulReporter: { 28 | reports: [ 'html', 'lcovonly' ], 29 | fixWebpackSourcePaths: true 30 | }, 31 | angularCli: { 32 | environment: 'dev' 33 | }, 34 | reporters: config.angularCli && config.angularCli.codeCoverage 35 | ? ['progress', 'coverage-istanbul'] 36 | : ['progress', 'kjhtml'], 37 | port: 9876, 38 | colors: true, 39 | logLevel: config.LOG_INFO, 40 | autoWatch: true, 41 | browsers: ['Chrome'], 42 | singleRun: false 43 | }); 44 | }; 45 | -------------------------------------------------------------------------------- /examples/angular/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './e2e/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | beforeLaunch: function() { 23 | require('ts-node').register({ 24 | project: 'e2e/tsconfig.e2e.json' 25 | }); 26 | }, 27 | onPrepare() { 28 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 29 | } 30 | }; 31 | -------------------------------------------------------------------------------- /examples/angular/server.js: -------------------------------------------------------------------------------- 1 | var port = process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || process.argv[2] || 8765; 2 | var host = process.env.OPENSHIFT_NODEJS_HOST || process.env.VCAP_APP_HOST || process.env.HOST || 'localhost'; 3 | 4 | var express = require('express'); 5 | var proxy = require('express-http-proxy'); 6 | var http = require('http'); 7 | var app = express(); 8 | var server = http.createServer(app); 9 | 10 | var Gun = require('gun'); 11 | var gun = Gun({ 12 | file: 'data.json', 13 | web: server 14 | }); 15 | 16 | app.use(Gun.serve); 17 | app.use(proxy(host + ':4200')); 18 | server.listen(port); 19 | 20 | console.log('Server started on port ' + port + ' with /gun'); 21 | -------------------------------------------------------------------------------- /examples/angular/src/app/app.component.css: -------------------------------------------------------------------------------- 1 | html, body { font-size: 14pt; padding: 10px 2.5%;} 2 | .hide { display: none; } 3 | form .who { width: 10%; } 4 | form .what { width: 80%; } 5 | ul { list-style: none; padding: 0; } 6 | ul .when {color: #555; font-size: 12pt; float: right; display: none; } 7 | li:hover .when {display: inline;} 8 | -------------------------------------------------------------------------------- /examples/angular/src/app/app.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 | 5 | 6 |
7 |
8 | 11 | 12 | 13 |
14 | -------------------------------------------------------------------------------- /examples/angular/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | 3 | import { AppComponent } from './app.component'; 4 | 5 | describe('AppComponent', () => { 6 | beforeEach(async(() => { 7 | TestBed.configureTestingModule({ 8 | declarations: [ 9 | AppComponent 10 | ], 11 | }).compileComponents(); 12 | })); 13 | 14 | it('should create the app', async(() => { 15 | const fixture = TestBed.createComponent(AppComponent); 16 | const app = fixture.debugElement.componentInstance; 17 | expect(app).toBeTruthy(); 18 | })); 19 | 20 | it(`should have as title 'app works!'`, async(() => { 21 | const fixture = TestBed.createComponent(AppComponent); 22 | const app = fixture.debugElement.componentInstance; 23 | expect(app.title).toEqual('app works!'); 24 | })); 25 | 26 | it('should render title in a h1 tag', async(() => { 27 | const fixture = TestBed.createComponent(AppComponent); 28 | fixture.detectChanges(); 29 | const compiled = fixture.debugElement.nativeElement; 30 | expect(compiled.querySelector('h1').textContent).toContain('app works!'); 31 | })); 32 | }); 33 | -------------------------------------------------------------------------------- /examples/angular/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Observable } from 'rxjs/Observable'; 3 | import { Subscription } from 'rxjs/Subscription'; 4 | import Gun from 'gun/gun'; 5 | 6 | import { GunDb } from 'app/gun.service'; 7 | import { on$ } from 'app/gun.helper'; 8 | 9 | @Component({ 10 | selector: 'app-root', 11 | templateUrl: './app.component.html', 12 | styleUrls: ['./app.component.css'] 13 | }) 14 | export class AppComponent implements OnInit { 15 | newTodo = ''; 16 | 17 | todos = this.db.gun.get('todos'); 18 | todos$: Observable = on$(this.todos); 19 | 20 | todosSub: Subscription; 21 | 22 | constructor(private db: GunDb) { } 23 | 24 | ngOnInit() { } 25 | 26 | add() { 27 | if (this.newTodo) { 28 | this.todos.get(Gun.text.random()).put(this.newTodo); 29 | this.newTodo = ''; 30 | } 31 | } 32 | 33 | delete(key: string) { 34 | this.todos.get(key).put(null); 35 | } 36 | 37 | sub() { 38 | this.todosSub = this.todos$.subscribe(v => console.log(v)); 39 | } 40 | 41 | unsub() { 42 | this.todosSub.unsubscribe(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /examples/angular/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule, Injectable } from '@angular/core'; 3 | import { FormsModule } from '@angular/forms'; 4 | import { HttpModule } from '@angular/http'; 5 | import { Observable } from 'rxjs/Observable'; 6 | import { NgPipesModule } from 'ngx-pipes'; 7 | 8 | import { AppComponent } from './app.component'; 9 | import { GunDb } from 'app/gun.service'; 10 | 11 | @NgModule({ 12 | declarations: [ 13 | AppComponent 14 | ], 15 | imports: [ 16 | BrowserModule, 17 | FormsModule, 18 | HttpModule, 19 | NgPipesModule 20 | ], 21 | providers: [GunDb], 22 | bootstrap: [AppComponent] 23 | }) 24 | export class AppModule { } 25 | -------------------------------------------------------------------------------- /examples/angular/src/app/gun.helper.ts: -------------------------------------------------------------------------------- 1 | import { Observable } from 'rxjs/Observable'; 2 | import { Gun } from 'gun/gun'; 3 | import { pick } from 'underscore'; 4 | 5 | export function on$(node, cleanup = true): Observable { 6 | return Observable.fromEventPattern( 7 | h => { 8 | // there is no way to off() an on() until at least one value is triggered 9 | // so that we can access the event listener to off() it 10 | const signal = { stop: false }; 11 | node.on((data, key, at, ev) => { 12 | if (signal.stop) { 13 | ev.off(); 14 | } else { 15 | // modifying data directly does not seem to work... 16 | h(cleanup ? pick(data, (v, k, o) => v !== null && k !== '_') : data); 17 | } 18 | }); 19 | return signal; 20 | }, 21 | (h, signal) => { signal.stop = true; } 22 | ); 23 | } 24 | 25 | export function val$(node): Observable { 26 | return new Observable(o => node.val(v => { 27 | o.next(v); 28 | o.complete(); 29 | })); 30 | } 31 | -------------------------------------------------------------------------------- /examples/angular/src/app/gun.service.ts: -------------------------------------------------------------------------------- 1 | import { NgModule, Injectable } from '@angular/core'; 2 | import Gun from 'gun/gun'; 3 | 4 | @Injectable() 5 | export class GunDb { 6 | readonly gun = Gun(location.origin + '/gun'); 7 | } 8 | -------------------------------------------------------------------------------- /examples/angular/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amark/gun/4b43fa7f2c085a866551ee36372daed10316354c/examples/angular/src/assets/.gitkeep -------------------------------------------------------------------------------- /examples/angular/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /examples/angular/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // The file contents for the current environment will overwrite these during build. 2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do 3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead. 4 | // The list of which env maps to which file can be found in `.angular-cli.json`. 5 | 6 | export const environment = { 7 | production: false 8 | }; 9 | -------------------------------------------------------------------------------- /examples/angular/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amark/gun/4b43fa7f2c085a866551ee36372daed10316354c/examples/angular/src/favicon.ico -------------------------------------------------------------------------------- /examples/angular/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Angular 6 | 7 | 8 | 9 | 10 | 11 | 12 | Loading... 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/angular/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | import 'rxjs/add/operator/startWith'; 8 | import 'rxjs/add/operator/map'; 9 | 10 | import 'rxjs/add/observable/fromEventPattern'; 11 | 12 | if (environment.production) { 13 | enableProdMode(); 14 | } 15 | 16 | platformBrowserDynamic().bootstrapModule(AppModule); 17 | -------------------------------------------------------------------------------- /examples/angular/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /examples/angular/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/long-stack-trace-zone'; 4 | import 'zone.js/dist/proxy.js'; 5 | import 'zone.js/dist/sync-test'; 6 | import 'zone.js/dist/jasmine-patch'; 7 | import 'zone.js/dist/async-test'; 8 | import 'zone.js/dist/fake-async-test'; 9 | import { getTestBed } from '@angular/core/testing'; 10 | import { 11 | BrowserDynamicTestingModule, 12 | platformBrowserDynamicTesting 13 | } from '@angular/platform-browser-dynamic/testing'; 14 | 15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. 16 | declare var __karma__: any; 17 | declare var require: any; 18 | 19 | // Prevent Karma from running prematurely. 20 | __karma__.loaded = function () {}; 21 | 22 | // First, initialize the Angular testing environment. 23 | getTestBed().initTestEnvironment( 24 | BrowserDynamicTestingModule, 25 | platformBrowserDynamicTesting() 26 | ); 27 | // Then we find all the tests. 28 | const context = require.context('./', true, /\.spec\.ts$/); 29 | // And load the modules. 30 | context.keys().map(context); 31 | // Finally, start Karma to run the tests. 32 | __karma__.start(); 33 | -------------------------------------------------------------------------------- /examples/angular/src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "es2015", 6 | "baseUrl": "", 7 | "types": [] 8 | }, 9 | "exclude": [ 10 | "test.ts", 11 | "**/*.spec.ts" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /examples/angular/src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "baseUrl": "", 8 | "types": [ 9 | "jasmine", 10 | "node" 11 | ] 12 | }, 13 | "files": [ 14 | "test.ts" 15 | ], 16 | "include": [ 17 | "**/*.spec.ts", 18 | "**/*.d.ts" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /examples/angular/src/typings.d.ts: -------------------------------------------------------------------------------- 1 | /* SystemJS module definition */ 2 | declare var module: NodeModule; 3 | interface NodeModule { 4 | id: string; 5 | } 6 | -------------------------------------------------------------------------------- /examples/angular/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "outDir": "./dist/out-tsc", 5 | "baseUrl": "src", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "moduleResolution": "node", 9 | "emitDecoratorMetadata": true, 10 | "experimentalDecorators": true, 11 | "target": "es5", 12 | "typeRoots": [ 13 | "node_modules/@types" 14 | ], 15 | "lib": [ 16 | "es2016", 17 | "dom" 18 | ] 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /examples/axe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Testing AXE 8 | 9 | 10 | 11 |

12 | 13 | 14 | 15 | 16 | 17 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /examples/basic/chat.html: -------------------------------------------------------------------------------- 1 | 2 |
    3 |
    4 | 5 | 6 | 7 |
    8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /examples/basic/emoji.html: -------------------------------------------------------------------------------- 1 | 2 |

    Moved to ./chat.html!

    -------------------------------------------------------------------------------- /examples/basic/note.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /examples/basic/paste.html: -------------------------------------------------------------------------------- 1 | 2 |

    Moved to ./note.html!

    -------------------------------------------------------------------------------- /examples/basic/post.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

    Posts

    4 | 5 |
    6 | 7 | 8 | 9 | 10 |
    11 | 12 |
    13 | 14 | 15 |
    16 | 17 |
      18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /examples/basic/upload.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 |
      9 |

      Drag & drop videos, songs, or images!

      10 |
      11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/basic/user.html: -------------------------------------------------------------------------------- 1 | 2 |

      Moved to ./post.html!

      -------------------------------------------------------------------------------- /examples/chat/user.html: -------------------------------------------------------------------------------- 1 | 2 | 6 | -------------------------------------------------------------------------------- /examples/express.js: -------------------------------------------------------------------------------- 1 | console.log("If module not found, install express globally `npm i express -g`!"); 2 | var port = process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || process.argv[2] || 8765; 3 | var express = require('express'); 4 | var Gun = require('..'); 5 | require('../axe'); 6 | 7 | var app = express(); 8 | app.use(Gun.serve); 9 | app.use(express.static(__dirname)); 10 | 11 | var server = app.listen(port); 12 | var gun = Gun({ file: 'data', web: server }); 13 | 14 | global.Gun = Gun; /// make global to `node --inspect` - debug only 15 | global.gun = gun; /// make global to `node --inspect` - debug only 16 | 17 | console.log('Server started on port ' + port + ' with /gun'); 18 | -------------------------------------------------------------------------------- /examples/game/nts.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |

      7 | 8 | 9 | 10 | 19 | 20 | -------------------------------------------------------------------------------- /examples/hapi.js: -------------------------------------------------------------------------------- 1 | console.log("If module not found, install hapi globally `npm i hapi inert -g`!") 2 | 3 | const Hapi = require('hapi') 4 | const Inert = require('inert') 5 | const Gun = require('..') 6 | 7 | const server = new Hapi.Server({ 8 | port: 8765, 9 | host: 'localhost', 10 | routes: { 11 | files: { 12 | relativeTo: require('path').join(__dirname, '..') 13 | } 14 | } 15 | }) 16 | 17 | async function runtime() { 18 | 19 | const db = new Gun({ 20 | web: server.listener, 21 | file: 'data.json' 22 | }) 23 | 24 | await server.register(Inert) 25 | 26 | server.route({ 27 | method: 'GET', 28 | path: '/gun.js', 29 | handler: { 30 | file: 'gun.min.js' 31 | } 32 | }) 33 | 34 | server.route({ 35 | method: 'GET', 36 | path: '/gun/nts.js', 37 | handler: { 38 | file: 'nts.js' 39 | } 40 | }) 41 | 42 | server.route({ 43 | method: 'GET', 44 | path: '/{param*}', 45 | handler: { 46 | directory: { 47 | path: __dirname, 48 | redirectToSlash: true, 49 | index: true 50 | } 51 | } 52 | }) 53 | 54 | await server.start() 55 | console.log('Server running at:', server.info.uri) 56 | } 57 | 58 | runtime() 59 | -------------------------------------------------------------------------------- /examples/http.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | var cluster = require('cluster'); 3 | if(cluster.isMaster){ 4 | return cluster.fork() && cluster.on('exit',function(){ cluster.fork(); require('../lib/crashed') }); 5 | } 6 | 7 | var fs = require('fs'), env = process.env; 8 | var GUN = require('../'); // require('gun'); 9 | var opt = { 10 | port: env.PORT || process.argv[2] || 8765, 11 | peers: env.PEERS && env.PEERS.split(',') || [] 12 | }; 13 | 14 | if(fs.existsSync((opt.home = require('os').homedir())+'/cert.pem')){ 15 | env.HTTPS_KEY = env.HTTPS_KEY || opt.home+'/key.pem'; 16 | env.HTTPS_CERT = env.HTTPS_CERT || opt.home+'/cert.pem'; 17 | } 18 | if(env.HTTPS_KEY){ 19 | opt.port = 443; 20 | opt.key = fs.readFileSync(env.HTTPS_KEY); 21 | opt.cert = fs.readFileSync(env.HTTPS_CERT); 22 | opt.server = require('https').createServer(opt, GUN.serve(__dirname)); 23 | require('http').createServer(function(req, res){ 24 | res.writeHead(301, {"Location": "https://"+req.headers['host']+req.url }); 25 | res.end(); 26 | }).listen(80); 27 | } else { 28 | opt.server = require('http').createServer(GUN.serve(__dirname)); 29 | } 30 | 31 | var gun = GUN({web: opt.server.listen(opt.port), peers: opt.peers}); 32 | console.log('Relay peer started on port ' + opt.port + ' with /gun'); 33 | module.exports = gun; 34 | }()); -------------------------------------------------------------------------------- /examples/https.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd ~ 3 | git clone https://github.com/acmesh-official/acme.sh.git 4 | cd ~/acme.sh 5 | ./acme.sh --install -m $EMAIL 6 | 7 | bash ~/acme.sh/acme.sh --issue -d $DOMAIN -w $WEB 8 | bash ~/acme.sh/acme.sh --install-cert -d $DOMAIN --key-file ~/key.pem --fullchain-file ~/cert.pem --reloadcmd "service relay force-reload" -------------------------------------------------------------------------------- /examples/index.html: -------------------------------------------------------------------------------- 1 | 2 |

      This is the examples folder. 3 |

      The most basic example is ./basic/note.html!

      4 |

      Home page temporarily disabled.

      -------------------------------------------------------------------------------- /examples/infinite-scroll/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Infinite scroll example 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
      13 |
      14 | 15 | 16 |
      17 |
      18 | 19 |
      20 |
      21 | 22 |
      23 |
      24 |
      25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /examples/infinite-scroll/style.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | margin: 0; 3 | padding: 0; 4 | } 5 | 6 | body { 7 | padding-top: 65px; 8 | } 9 | 10 | header { 11 | background: rgba(255,255,255,0.75); 12 | padding: 15px; 13 | } 14 | 15 | header { 16 | position: fixed; 17 | top: 0; left: 0; right: 0; 18 | } 19 | 20 | #bottom { 21 | position: fixed; 22 | right: 15px; 23 | bottom: 15px; 24 | } 25 | 26 | input { 27 | border: 0; 28 | background-color: #efefef; 29 | padding: 15px; 30 | border-radius: 50px; 31 | } 32 | 33 | button { 34 | background-color: #4a4f9d; 35 | border: 0; 36 | padding: 15px; 37 | color: white; 38 | border-radius: 50px; 39 | } 40 | 41 | input, button { 42 | outline: none; 43 | opacity: 1; 44 | } 45 | 46 | input:focus, button:focus, button:hover { 47 | opacity: 0.8; 48 | } 49 | 50 | button:hover { 51 | cursor: pointer; 52 | } 53 | 54 | #top-buttons, form { 55 | display: inline-block; 56 | margin: 0; 57 | } 58 | 59 | #top-buttons { 60 | float: right; 61 | } 62 | 63 | .post { 64 | margin: 15px; 65 | padding: 15px; 66 | background-color: #9de1fe; 67 | border-radius: 5px; 68 | } 69 | 70 | .post b { 71 | margin-right: 5; 72 | } 73 | 74 | .post img { 75 | display: block; 76 | margin: 10px 0; 77 | } 78 | -------------------------------------------------------------------------------- /examples/iris: -------------------------------------------------------------------------------- 1 | ../node_modules/iris-messenger/src -------------------------------------------------------------------------------- /examples/pop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amark/gun/4b43fa7f2c085a866551ee36372daed10316354c/examples/pop.png -------------------------------------------------------------------------------- /examples/react-native/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["module:metro-react-native-babel-preset"] 3 | } 4 | -------------------------------------------------------------------------------- /examples/react-native/.buckconfig: -------------------------------------------------------------------------------- 1 | 2 | [android] 3 | target = Google Inc.:Google APIs:23 4 | 5 | [maven_repositories] 6 | central = https://repo1.maven.org/maven2 7 | -------------------------------------------------------------------------------- /examples/react-native/.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | -------------------------------------------------------------------------------- /examples/react-native/.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | # 7 | build/ 8 | *.pbxuser 9 | !default.pbxuser 10 | *.mode1v3 11 | !default.mode1v3 12 | *.mode2v3 13 | !default.mode2v3 14 | *.perspectivev3 15 | !default.perspectivev3 16 | xcuserdata 17 | *.xccheckout 18 | *.moved-aside 19 | DerivedData 20 | *.hmap 21 | *.ipa 22 | *.xcuserstate 23 | project.xcworkspace 24 | 25 | # Android/IntelliJ 26 | # 27 | build/ 28 | .idea 29 | .gradle 30 | local.properties 31 | *.iml 32 | 33 | # node.js 34 | # 35 | node_modules/ 36 | npm-debug.log 37 | yarn-error.log 38 | 39 | # BUCK 40 | buck-out/ 41 | \.buckd/ 42 | *.keystore 43 | 44 | # fastlane 45 | # 46 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 47 | # screenshots whenever they are needed. 48 | # For more information about the recommended setup visit: 49 | # https://docs.fastlane.tools/best-practices/source-control/ 50 | 51 | */fastlane/report.xml 52 | */fastlane/Preview.html 53 | */fastlane/screenshots 54 | 55 | # Bundle artifact 56 | *.jsbundle 57 | -------------------------------------------------------------------------------- /examples/react-native/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /examples/react-native/README.md: -------------------------------------------------------------------------------- 1 | # Gun on react-native! 2 | --- 3 | ### running the demo 4 | 1. do `yarn install` on the directory of the demo `examples/react-native` 5 | 2. run the demo with `react-native run-ios` or `react-native run-android` 6 | 7 | ### debugging 8 | i would recommend using [react-native-debugger](https://github.com/facebook/react-devtools/tree/master/packages/react-devtools) but you can use chrome's debugger as well 9 | 10 | - ios: `cmd+D` then `Debug JS Remotely` 11 | - android: `cmd+M` then `Debug JS Remotely` 12 | 13 | now you have access to the gun globals on the console which are 14 | `gun` -> the root gun 15 | `user` -> the gun user 16 | --- 17 | # how it all of this is done 18 | since react-native doesnt provide the crypto module that we desire the most and all of the packages are incompatible with react-native/sea, and so to get `sea.js` working we use a webview(react-native browser) and bridge the crypto module from that browser to the global `window` and thats exactly what `webview-crypto` does, thanks to [webview-crypto repo](https://github.com/saulshanabrook/webview-crypto), the webview-crypto provided in this repo is somewhat the same but modified to get it working and mostly compatible with sea/react-native (even though there is a polyfiller for that but it just doesnt work ;/). -------------------------------------------------------------------------------- /examples/react-native/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /examples/react-native/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 13 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /examples/react-native/android/app/src/main/assets/html/blank.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amark/gun/4b43fa7f2c085a866551ee36372daed10316354c/examples/react-native/android/app/src/main/assets/html/blank.html -------------------------------------------------------------------------------- /examples/react-native/android/app/src/main/java/com/gundemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.gundemo; 2 | 3 | import com.facebook.react.ReactActivity; 4 | 5 | public class MainActivity extends ReactActivity { 6 | 7 | /** 8 | * Returns the name of the main component registered from JavaScript. 9 | * This is used to schedule rendering of the component. 10 | */ 11 | @Override 12 | protected String getMainComponentName() { 13 | return "GunDemo"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/react-native/android/app/src/main/java/com/gundemo/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.gundemo; 2 | 3 | import android.app.Application; 4 | 5 | import com.facebook.react.ReactApplication; 6 | import com.github.alinz.reactnativewebviewbridge.WebViewBridgePackage; 7 | import com.facebook.react.ReactNativeHost; 8 | import com.facebook.react.ReactPackage; 9 | import com.facebook.react.shell.MainReactPackage; 10 | import com.facebook.soloader.SoLoader; 11 | 12 | import java.util.Arrays; 13 | import java.util.List; 14 | 15 | public class MainApplication extends Application implements ReactApplication { 16 | 17 | private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { 18 | @Override 19 | public boolean getUseDeveloperSupport() { 20 | return BuildConfig.DEBUG; 21 | } 22 | 23 | @Override 24 | protected List getPackages() { 25 | return Arrays.asList( 26 | new MainReactPackage(), 27 | new WebViewBridgePackage() 28 | ); 29 | } 30 | 31 | @Override 32 | protected String getJSMainModuleName() { 33 | return "index"; 34 | } 35 | }; 36 | 37 | @Override 38 | public ReactNativeHost getReactNativeHost() { 39 | return mReactNativeHost; 40 | } 41 | 42 | @Override 43 | public void onCreate() { 44 | super.onCreate(); 45 | SoLoader.init(this, /* native exopackage */ false); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /examples/react-native/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amark/gun/4b43fa7f2c085a866551ee36372daed10316354c/examples/react-native/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/react-native/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amark/gun/4b43fa7f2c085a866551ee36372daed10316354c/examples/react-native/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /examples/react-native/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amark/gun/4b43fa7f2c085a866551ee36372daed10316354c/examples/react-native/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/react-native/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amark/gun/4b43fa7f2c085a866551ee36372daed10316354c/examples/react-native/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /examples/react-native/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amark/gun/4b43fa7f2c085a866551ee36372daed10316354c/examples/react-native/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/react-native/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amark/gun/4b43fa7f2c085a866551ee36372daed10316354c/examples/react-native/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /examples/react-native/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amark/gun/4b43fa7f2c085a866551ee36372daed10316354c/examples/react-native/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/react-native/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amark/gun/4b43fa7f2c085a866551ee36372daed10316354c/examples/react-native/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /examples/react-native/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amark/gun/4b43fa7f2c085a866551ee36372daed10316354c/examples/react-native/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/react-native/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amark/gun/4b43fa7f2c085a866551ee36372daed10316354c/examples/react-native/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /examples/react-native/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | GunDemo 3 | 4 | -------------------------------------------------------------------------------- /examples/react-native/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /examples/react-native/android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext { 5 | buildToolsVersion = "27.0.3" 6 | minSdkVersion = 16 7 | compileSdkVersion = 27 8 | targetSdkVersion = 26 9 | supportLibVersion = "27.1.1" 10 | } 11 | repositories { 12 | google() 13 | jcenter() 14 | } 15 | dependencies { 16 | classpath 'com.android.tools.build:gradle:3.1.4' 17 | 18 | // NOTE: Do not place your application dependencies here; they belong 19 | // in the individual module build.gradle files 20 | } 21 | } 22 | 23 | allprojects { 24 | repositories { 25 | mavenLocal() 26 | google() 27 | jcenter() 28 | maven { 29 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 30 | url "$rootDir/../node_modules/react-native/android" 31 | } 32 | } 33 | } 34 | 35 | 36 | task wrapper(type: Wrapper) { 37 | gradleVersion = '4.4' 38 | distributionUrl = distributionUrl.replace("bin", "all") 39 | } 40 | -------------------------------------------------------------------------------- /examples/react-native/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | -------------------------------------------------------------------------------- /examples/react-native/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amark/gun/4b43fa7f2c085a866551ee36372daed10316354c/examples/react-native/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /examples/react-native/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip 6 | -------------------------------------------------------------------------------- /examples/react-native/android/keystores/BUCK: -------------------------------------------------------------------------------- 1 | keystore( 2 | name = "debug", 3 | properties = "debug.keystore.properties", 4 | store = "debug.keystore", 5 | visibility = [ 6 | "PUBLIC", 7 | ], 8 | ) 9 | -------------------------------------------------------------------------------- /examples/react-native/android/keystores/debug.keystore.properties: -------------------------------------------------------------------------------- 1 | key.store=debug.keystore 2 | key.alias=androiddebugkey 3 | key.store.password=android 4 | key.alias.password=android 5 | -------------------------------------------------------------------------------- /examples/react-native/android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'GunDemo' 2 | include ':react-native-webview-bridge' 3 | project(':react-native-webview-bridge').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-webview-bridge/android') 4 | 5 | include ':app' 6 | -------------------------------------------------------------------------------- /examples/react-native/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "GunDemo", 3 | "displayName": "GunDemo" 4 | } -------------------------------------------------------------------------------- /examples/react-native/index.js: -------------------------------------------------------------------------------- 1 | /** @format */ 2 | import './shim'; 3 | import {AppRegistry} from 'react-native'; 4 | import App from './src/App'; 5 | import {name as appName} from './app.json'; 6 | 7 | AppRegistry.registerComponent(appName, () => App); 8 | console.disableYellowBox = true; 9 | -------------------------------------------------------------------------------- /examples/react-native/ios/GunDemo-tvOSTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /examples/react-native/ios/GunDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #import 9 | 10 | @interface AppDelegate : UIResponder 11 | 12 | @property (nonatomic, strong) UIWindow *window; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /examples/react-native/ios/GunDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #import "AppDelegate.h" 9 | 10 | #import 11 | #import 12 | 13 | @implementation AppDelegate 14 | 15 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 16 | { 17 | NSURL *jsCodeLocation; 18 | 19 | jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; 20 | 21 | RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation 22 | moduleName:@"GunDemo" 23 | initialProperties:nil 24 | launchOptions:launchOptions]; 25 | rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; 26 | 27 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 28 | UIViewController *rootViewController = [UIViewController new]; 29 | rootViewController.view = rootView; 30 | self.window.rootViewController = rootViewController; 31 | [self.window makeKeyAndVisible]; 32 | return YES; 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /examples/react-native/ios/GunDemo/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /examples/react-native/ios/GunDemo/Images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/react-native/ios/GunDemo/main.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #import 9 | 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/react-native/ios/GunDemoTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /examples/react-native/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "GunDemo", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "start": "node node_modules/react-native/local-cli/cli.js start", 7 | "test": "jest" 8 | }, 9 | "dependencies": { 10 | "buffer": "^5.2.1", 11 | "encode-utf8": "^1.0.2", 12 | "fast-base64-encode": "^1.0.0", 13 | "gun": "^0.9.99999", 14 | "lodash": "^4.17.11", 15 | "react": "16.6.1", 16 | "react-native": "0.57.5", 17 | "react-native-webview-bridge": "^0.40.1", 18 | "serialize-error": "^3.0.0", 19 | "text-encoding": "^0.7.0" 20 | }, 21 | "devDependencies": { 22 | "babel-jest": "23.6.0", 23 | "jest": "23.6.0", 24 | "metro-react-native-babel-preset": "0.49.2", 25 | "react-test-renderer": "16.6.1" 26 | }, 27 | "jest": { 28 | "preset": "react-native" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/react-native/shim.js: -------------------------------------------------------------------------------- 1 | if (typeof __dirname === 'undefined') global.__dirname = '/' 2 | if (typeof __filename === 'undefined') global.__filename = '' 3 | 4 | if (typeof Buffer === 'undefined') global.Buffer = require('buffer').Buffer 5 | 6 | const isDev = typeof __DEV__ === 'boolean' && __DEV__ 7 | process.env['NODE_ENV'] = isDev ? 'development' : 'production' 8 | if (typeof localStorage !== 'undefined') { 9 | localStorage.debug = isDev ? '*' : '' 10 | } 11 | 12 | global.location = { 13 | protocol: 'file:', 14 | host: '', 15 | }; 16 | 17 | const { TextEncoder, TextDecoder } = require('text-encoding'); 18 | 19 | global.TextDecoder = TextDecoder; 20 | global.TextEncoder = TextEncoder; -------------------------------------------------------------------------------- /examples/react-native/src/App/app.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample React Native App 3 | * https://github.com/facebook/react-native 4 | * 5 | * @format 6 | * @flow 7 | */ 8 | 9 | import React, {Component} from 'react'; 10 | import {View} from 'react-native'; 11 | 12 | import {Demo} from './Demo'; 13 | 14 | import PolyFillCrypto from './PolyFillCrypto'; 15 | 16 | 17 | export class App extends Component { 18 | render() { 19 | return ( 20 | 21 | 22 | 23 | 24 | ); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /examples/react-native/src/App/index.js: -------------------------------------------------------------------------------- 1 | export {App as default} from './app'; 2 | -------------------------------------------------------------------------------- /examples/react-native/src/webview-crypto/MainWorker.d.ts: -------------------------------------------------------------------------------- 1 | export default class MainWorker { 2 | private sendToWebView; 3 | private debug; 4 | readonly crypto: Crypto; 5 | private readonly subtle; 6 | private static uuid; 7 | private toSend; 8 | private readyToSend; 9 | private messages; 10 | constructor(sendToWebView: (message: string) => void, debug?: boolean); 11 | onWebViewMessage(message: string): void; 12 | private getRandomValues; 13 | private callMethod; 14 | } 15 | -------------------------------------------------------------------------------- /examples/react-native/src/webview-crypto/WebViewWorker.d.ts: -------------------------------------------------------------------------------- 1 | export declare class WebViewWorker { 2 | private sendToMain; 3 | constructor(sendToMain: (message: string) => void); 4 | onMainMessage(message: string): Promise; 5 | send(data: any): Promise; 6 | } 7 | -------------------------------------------------------------------------------- /examples/react-native/src/webview-crypto/asyncSerialize.d.ts: -------------------------------------------------------------------------------- 1 | export interface ISerializer { 2 | id: string; 3 | isType: (o: any) => boolean; 4 | toObject?: (t: T) => Promise; 5 | fromObject?: (o: S) => Promise; 6 | } 7 | export declare function toObjects(serializers: Array>, o: any): Promise; 8 | export declare function fromObjects(serializers: Array>, o: any): Promise; 9 | -------------------------------------------------------------------------------- /examples/react-native/src/webview-crypto/asyncSerialize.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"asyncSerialize.js","sourceRoot":"","sources":["../src/asyncSerialize.ts"],"names":[],"mappings":";;;;;;;;AAAA,iBAAiB;AACjB,OAAO,IAAI,MAAM,aAAa,CAAC;AAS/B,MAAM,UAAU;CAIf;AAED,SAAS,YAAY,CAAC,MAAW;IAChC,OAAO,MAAM,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;AACjD,CAAC;AAED,MAAM,UAAgB,SAAS,CAC9B,WAAyC,EACzC,CAAM;;QAEN,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE;YAC1B,OAAO,CAAC,CAAC;SACT;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9D,IAAI,UAAU,EAAE;YACf,MAAM,KAAK,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACrE,OAAO;gBACN,eAAe,EAAE,UAAU,CAAC,EAAE;gBAC9B,KAAK,EAAE,MAAM,SAAS,CAAC,WAAW,EAAE,KAAK,CAAC;aAC5B,CAAC;SAChB;QAED,MAAM,IAAI,GAAQ,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/C,KAAK,MAAM,GAAG,IAAI,CAAC,EAAE;YACpB,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,SAAS,CAAC,WAAW,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;SACjD;QACD,OAAO,IAAI,CAAC;IACb,CAAC;CAAA;AAED,MAAM,UAAgB,WAAW,CAChC,WAAyC,EACzC,CAAM;;QAEN,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE;YAC1B,OAAO,CAAC,CAAC;SACT;QAED,IAAI,YAAY,CAAC,CAAC,CAAC,EAAE;YACpB,MAAM,KAAK,GAAG,MAAM,WAAW,CAAC,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;YACtD,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,eAAe,CAAC,CAAC,IAAI,EAAS,CAAC;YAC7E,IAAI,UAAU,CAAC,UAAU,EAAE;gBAC1B,OAAO,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;aACpC;YACD,OAAO,KAAK,CAAC;SACb;QAED,MAAM,IAAI,GAAQ,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/C,KAAK,MAAM,GAAG,IAAI,CAAC,EAAE;YACpB,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,WAAW,CAAC,WAAW,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;SACnD;QACD,OAAO,IAAI,CAAC;IACb,CAAC;CAAA"} -------------------------------------------------------------------------------- /examples/react-native/src/webview-crypto/compat.d.ts: -------------------------------------------------------------------------------- 1 | export declare function subtle(): SubtleCrypto; 2 | -------------------------------------------------------------------------------- /examples/react-native/src/webview-crypto/compat.js: -------------------------------------------------------------------------------- 1 | export function subtle() { 2 | return window.crypto.subtle || window.crypto.webkitSubtle; 3 | } 4 | //# sourceMappingURL=compat.js.map -------------------------------------------------------------------------------- /examples/react-native/src/webview-crypto/compat.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"compat.js","sourceRoot":"","sources":["../src/compat.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,MAAM;IACrB,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,IAAK,MAAM,CAAC,MAAc,CAAC,YAAY,CAAC;AACpE,CAAC"} -------------------------------------------------------------------------------- /examples/react-native/src/webview-crypto/index.d.ts: -------------------------------------------------------------------------------- 1 | import MainWorker from './MainWorker'; 2 | import webViewWorkerString from './webViewWorkerString'; 3 | export { MainWorker, webViewWorkerString }; 4 | -------------------------------------------------------------------------------- /examples/react-native/src/webview-crypto/index.js: -------------------------------------------------------------------------------- 1 | import MainWorker from './MainWorker'; 2 | import webViewWorkerString from './webViewWorkerString'; 3 | export { MainWorker, webViewWorkerString }; 4 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /examples/react-native/src/webview-crypto/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,cAAc,CAAC;AACtC,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AAExD,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,CAAC"} -------------------------------------------------------------------------------- /examples/react-native/src/webview-crypto/serializeBinary.d.ts: -------------------------------------------------------------------------------- 1 | export declare function parse(text: string): Promise; 2 | export declare function stringify(value: any, waitForArrayBufferView?: boolean): Promise; 3 | export interface IArrayBufferViewWithPromise extends ArrayBufferView { 4 | _promise?: Promise; 5 | } 6 | -------------------------------------------------------------------------------- /examples/react/README.md: -------------------------------------------------------------------------------- 1 | You can use `todo.html` as a project template to get started with React + GUN. 2 | 3 | It is an extremely simple in-memory only todo app that you can [try here](https://gunjs.herokuapp.com/react/todo.html). 4 | 5 | There are some other simple examples in the `src` folder. 6 | 7 | If you want to see next level stuff, check out any of [Nick's React apps](https://github.com/nmaro?utf8=%E2%9C%93&tab=repositories&q=gun&type=&language=). 8 | -------------------------------------------------------------------------------- /examples/react/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amark/gun/4b43fa7f2c085a866551ee36372daed10316354c/examples/react/public/favicon.ico -------------------------------------------------------------------------------- /examples/react/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 17 | Gun - React Examples 18 | 19 | 20 |
      21 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /examples/react/src/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import Gun from 'gun/gun' 3 | import Todos from './Todos' 4 | import Chat from './Chat' 5 | import Json from './Json' 6 | 7 | class App extends Component { 8 | constructor() { 9 | super(); 10 | this.gun = Gun(location.origin + '/gun') 11 | } 12 | 13 | render() { 14 | return ( 15 |
      16 |

      React Examples

      17 |

      Todo

      18 | 19 |
      20 |
      21 |

      Chat

      22 | 23 |
      24 |
      25 |

      Json

      26 | 27 |
      28 | ); 29 | } 30 | } 31 | 32 | export default App; 33 | -------------------------------------------------------------------------------- /examples/react/src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render(, div); 8 | }); 9 | -------------------------------------------------------------------------------- /examples/react/src/Json.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | 3 | const formatJson = json => 4 | Object.keys(json) 5 | .map(key => ({ key, val: json[key]})) 6 | .filter(el => el.key !== '_') 7 | 8 | export default class Json extends Component { 9 | constructor({gun}) { 10 | super() 11 | this.gun = gun.get('json'); 12 | this.state = { newField: '', json: [] } 13 | } 14 | 15 | componentWillMount() { 16 | this.gun.on(json => this.setState({ json: formatJson(json) })) 17 | } 18 | 19 | edit = key => e => { 20 | e.preventDefault() 21 | this.gun.path(key).put(e.target.value) 22 | } 23 | 24 | add = e => { 25 | e.preventDefault() 26 | this.gun.path(this.state.newField).put('value') 27 | this.setState({newField: ''}) 28 | } 29 | 30 | render() { 31 | return
      32 |
        33 | {this.state.json.map(({ key, val }) => 34 |
      • {key}:
      • 35 | )} 36 |
      37 |
      38 | this.setState({ newField: e.target.value})} /> 39 | 40 |
      41 |
      42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /examples/react/src/Todos.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import Gun from 'gun/gun' 3 | import path from 'gun/lib/path' 4 | import './style.css' 5 | 6 | const formatTodos = todos => Object.keys(todos) 7 | .map(key => ({ key, val: todos[key] })) 8 | .filter(t => Boolean(t.val) && t.key !== '_') 9 | 10 | export default class Todos extends Component { 11 | constructor({gun}) { 12 | super() 13 | this.gun = gun.get('todos'); 14 | this.state = {newTodo: '', todos: []} 15 | } 16 | 17 | componentWillMount() { 18 | this.gun.on(todos => this.setState({ 19 | todos: formatTodos(todos) 20 | })) 21 | } 22 | 23 | add = e => { 24 | e.preventDefault() 25 | this.gun.path(Gun.text.random()).put(this.state.newTodo) 26 | this.setState({newTodo: ''}) 27 | } 28 | 29 | del = key => this.gun.path(key).put(null) 30 | 31 | handleChange = e => this.setState({ newTodo: e.target.value}) 32 | 33 | render() { 34 | return
      35 |
      36 | 37 | 38 |
      39 |
      40 |
        41 | {this.state.todos.map(todo =>
      • this.del(todo.key)}>{todo.val}
      • )} 42 |
      43 |
      44 | } 45 | 46 | } 47 | 48 | -------------------------------------------------------------------------------- /examples/react/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | font-family: sans-serif; 5 | } 6 | -------------------------------------------------------------------------------- /examples/react/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | import './index.css'; 5 | 6 | ReactDOM.render( 7 | , 8 | document.getElementById('root') 9 | ); 10 | -------------------------------------------------------------------------------- /examples/react/src/style.css: -------------------------------------------------------------------------------- 1 | html, body { font-size: 14pt; padding: 10px 2.5%;} 2 | .hide { display: none; } 3 | form .who { width: 10%; } 4 | form .what { width: 80%; } 5 | ul { list-style: none; padding: 0; } 6 | ul .when {color: #555; font-size: 12pt; float: right; display: none; } 7 | li:hover .when {display: inline;} 8 | -------------------------------------------------------------------------------- /examples/react/todo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
      5 | 6 | 7 | 8 | 9 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /examples/relay.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=GUN relay 3 | Documentation=https://gun.eco 4 | After=network.target 5 | 6 | [Install] 7 | WantedBy=multi-user.target 8 | 9 | [Service] 10 | Environment=PATH=/usr/bin:/usr/local/bin 11 | LimitNOFILE=infinity 12 | LimitNPROC=infinity 13 | LimitCORE=infinity 14 | StartLimitBurst=999999 15 | StartLimitIntervalSec=999999 16 | Restart=always 17 | ExecStart=node examples/http.js 80 18 | # Environment=NODE_ENV=production 19 | WorkingDirectory= -------------------------------------------------------------------------------- /examples/start.js.html: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /examples/wave.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Wave example 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /examples/webpack/.gitignore: -------------------------------------------------------------------------------- 1 | package-lock.json 2 | node_modules 3 | public -------------------------------------------------------------------------------- /examples/webpack/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webpack", 3 | "version": "1.0.0", 4 | "description": "webpack build example", 5 | "scripts": { 6 | "build": "webpack --devtool source-map --config webpack.config.js", 7 | "prepare": "npm run build" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "gun": "github:amark/gun", 13 | "html-webpack-plugin": "^5.5.0", 14 | "webpack": "^5.72.1", 15 | "webpack-cli": "^4.9.2" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /examples/webpack/src/app.js: -------------------------------------------------------------------------------- 1 | define(function(require, exports, module) { 2 | 3 | var Gun = require("gun"); 4 | 5 | var gun = new Gun(); 6 | 7 | gun.get("hello").get("world").put("from gun").on((data, key) => console.log(data, key)); 8 | 9 | }); -------------------------------------------------------------------------------- /examples/webpack/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /examples/webpack/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const HtmlWebpackPlugin = require('html-webpack-plugin'); 3 | 4 | let plugins = []; 5 | 6 | plugins.push(new HtmlWebpackPlugin({ 7 | filename: './index.html', 8 | template: './src/index.html', 9 | inject: true, 10 | minify: false, 11 | hash: false, 12 | cache: false, 13 | showErrors: false 14 | })); 15 | 16 | console.log("webpack config loaded"); 17 | 18 | module.exports = { 19 | 20 | mode: "development", 21 | 22 | // stats: 'minimal', 23 | stats: 'normal', 24 | // stats: 'verbose', 25 | 26 | entry: [path.resolve(__dirname, './src/app.js')], 27 | 28 | output: { 29 | path: path.resolve(__dirname, './public'), 30 | clean: true, 31 | filename: './app.js' 32 | }, 33 | 34 | plugins: plugins 35 | }; 36 | -------------------------------------------------------------------------------- /gun.d.ts: -------------------------------------------------------------------------------- 1 | import { IGun, LEX } from './types/gun'; 2 | 3 | declare const Gun: IGun; 4 | export default Gun; 5 | 6 | import {} from './types/gun/IGun'; 7 | declare module './types/gun/IGun' { 8 | export interface IGun { 9 | window: Window 10 | } 11 | } 12 | 13 | declare global { 14 | interface Window { 15 | Gun: IGun; 16 | GUN: IGun; 17 | } 18 | 19 | interface StringConstructor { 20 | match(t: string, o: LEX | string): boolean; 21 | random(length?: number, alphabet?: string): string; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /hooks/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | FOO=${IMAGE_NAME:=`whoami`/gun:git-local} 3 | BAR=${SOURCE_BRANCH:=`git rev-parse --abbrev-ref HEAD`} 4 | docker build --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \ 5 | --build-arg VCS_REF=`git rev-parse --short HEAD` \ 6 | --build-arg VCS_URL=`git config --get remote.origin.url` \ 7 | --build-arg VERSION=$SOURCE_BRANCH -t $IMAGE_NAME . 8 | -------------------------------------------------------------------------------- /hooks/post_push: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | docker tag $IMAGE_NAME $DOCKER_REPO:latest 3 | docker push $DOCKER_REPO:latest 4 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './types/gun'; 2 | export * from './types/sea'; 3 | 4 | import { IGun, LEX } from './types/gun'; 5 | import { ISEA } from './types/sea'; 6 | 7 | declare const Gun: IGun; 8 | export default Gun; 9 | 10 | export const SEA: ISEA; 11 | 12 | declare global { 13 | const Gun: IGun; 14 | 15 | interface StringConstructor { 16 | match(t: string, o: LEX | string): boolean; 17 | random(length?: number, alphabet?: string): string; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./lib/server'); -------------------------------------------------------------------------------- /lib/afore.js: -------------------------------------------------------------------------------- 1 | function afore(tag, hear){ 2 | if(!tag){ return } 3 | tag = tag.the; // grab the linked list root 4 | var tmp = tag.to; // grab first listener 5 | hear = tmp.on.on(tag.tag, hear); // add us to end 6 | hear.to = tmp || hear.to; // make our next be current first 7 | hear.back.to = hear.to; // make our back point to our next 8 | tag.last = hear.back; // make last be same as before 9 | hear.back = tag; // make our back be the start 10 | tag.to = hear; // make the start be us 11 | return hear; 12 | } 13 | if(typeof module !== "undefined"){ module.exports = afore } // afore(gun._.on('in'), function(){ }) -------------------------------------------------------------------------------- /lib/book.js: -------------------------------------------------------------------------------- 1 | console.log("Officially moved to gun.js core, use gun/src/book.js on own."); -------------------------------------------------------------------------------- /lib/bye.js: -------------------------------------------------------------------------------- 1 | var Gun = (typeof window !== "undefined")? window.Gun : require('../gun'); 2 | 3 | Gun.on('create', function(root){ 4 | this.to.next(root); 5 | var mesh = root.opt.mesh; 6 | if(!mesh){ return } 7 | mesh.hear['bye'] = function(msg, peer){ 8 | (peer.byes = peer.byes || []).push(msg.bye); 9 | } 10 | root.on('bye', function(peer){ 11 | this.to.next(peer); 12 | if(!peer.byes){ return } 13 | var gun = root.$; 14 | Gun.obj.map(peer.byes, function(data){ 15 | Gun.obj.map(data, function(put, soul){ 16 | gun.get(soul).put(put); 17 | }); 18 | }); 19 | peer.byes = []; 20 | }); 21 | }); 22 | 23 | Gun.chain.bye = function(){ 24 | var gun = this, bye = gun.chain(), root = gun.back(-1), put = bye.put; 25 | bye.put = function(data){ 26 | gun.back(function(at){ 27 | if(!at.get){ return } 28 | var tmp = data; 29 | (data = {})[at.get] = tmp; 30 | }); 31 | root.on('out', {bye: data}); 32 | return gun; 33 | } 34 | return bye; 35 | } 36 | -------------------------------------------------------------------------------- /lib/crashed.js: -------------------------------------------------------------------------------- 1 | ;(function(){ try { 2 | var fs = require('fs'), logs = [], up = __dirname+'/../'; 3 | fs.readdir(up, function(err, list){ try{ 4 | var i = 0, f; while(f = list[i++]){ 5 | if(0 === f.indexOf('isolate-') && '.log' === f.slice(-4)){ logs.push(f) } 6 | } 7 | logs = logs.sort(); 8 | var i = 0, f, lf; while(f = list[i++]){ 9 | if(0 <= f.indexOf('-v8-') && '.log' === f.slice(-4)){ lf = f } 10 | } f = lf; 11 | if(!f){ return } 12 | fs.rename(up+f, up+'v8.log', function(err,ok){ 13 | var i = 0, f; while(f = logs[i++]){ fs.unlink(up+f, noop) } 14 | if(!process.env.EMAIL){ return } // ONLY EMAIL IF DEVELOPER OPTS IN!!! 15 | email(); // ONLY EMAIL IF DEVELOPER OPTS IN!!! 16 | }); 17 | }catch(e){} }); 18 | function noop(){}; 19 | function email(){ try{ 20 | if(!process.env.EMAIL){ return } // ONLY EMAIL IF DEVELOPER OPTS IN!!! 21 | var address = process.env.EMAIL || "mark@gun.eco"; 22 | // you also have to specify your EMAIL_KEY gmail 2F' app's password (not reg) to send out. 23 | require('./email').send({ 24 | text: "log attached", 25 | from: address, 26 | to: address, 27 | subject: "GUN V8 LOG", 28 | attachment:[{path: up+'v8.log', type:"text/plain", name:"v8.log"}] 29 | }, noop); 30 | }catch(e){} }; 31 | }catch(e){} 32 | }()); -------------------------------------------------------------------------------- /lib/cryptomodules.js: -------------------------------------------------------------------------------- 1 | ;console.log("cryptomodules no longer needed"); -------------------------------------------------------------------------------- /lib/email.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | var email, fail = {send: function(opt, cb){ cb && cb("You do not have email installed.") } }; 3 | if(!process.env.EMAIL){ return module.exports = fail } 4 | try{ email = require('emailjs') }catch(e){}; 5 | if(!email){ return module.exports = fail } 6 | return module.exports = email.server.connect({ 7 | user: process.env.EMAIL, 8 | password: process.env.EMAIL_KEY, 9 | host: process.env.EMAIL_HOST || "smtp.gmail.com", 10 | ssl: process.env.EMAIL_SSL || true 11 | }); 12 | }()); -------------------------------------------------------------------------------- /lib/erase.js: -------------------------------------------------------------------------------- 1 | var Gun = (typeof window !== "undefined")? window.Gun : require('../gun'); 2 | 3 | Gun.on('opt', function(root){ 4 | this.to.next(root); 5 | if(root.once){ return } 6 | root.on('put', function(msg){ 7 | Gun.graph.is(msg.put, null, function(val, key, node, soul){ 8 | if(null !== val){ return } 9 | // TODO: Refactor this to use `.off()`? 10 | var tmp = root.graph[soul]; 11 | if(tmp){ 12 | delete tmp[key]; 13 | } 14 | tmp = tmp && tmp._ && tmp._['>']; 15 | if(tmp){ 16 | delete tmp[key]; 17 | } 18 | tmp = root.next; 19 | if(tmp && (tmp = tmp[soul]) && (tmp = tmp.put)){ 20 | delete tmp[key]; 21 | tmp = tmp._ && tmp._['>']; 22 | if(tmp){ 23 | delete tmp[key]; 24 | } 25 | } 26 | }); 27 | this.to.next(msg); 28 | }); 29 | }); -------------------------------------------------------------------------------- /lib/forget.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | var Gun = (typeof window !== "undefined")? window.Gun : require('../gun'); 3 | 4 | Gun.on('opt', function(root){ 5 | once(root); 6 | this.to.next(root); 7 | }); 8 | 9 | function once(root){ 10 | if(root.once){ return } 11 | var forget = root.opt.forget = root.opt.forget || {}; 12 | root.on('put', function(msg){ 13 | Gun.graph.is(msg.put, function(node, soul){ 14 | if(!Gun.obj.has(forget, soul)){ return } 15 | delete msg.put[soul]; 16 | }); 17 | this.to.next(msg); 18 | }); 19 | } 20 | 21 | }()); -------------------------------------------------------------------------------- /lib/fsrm.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var nodePath = require('path'); 3 | 4 | var dir = __dirname + '/../'; 5 | 6 | module.exports = function rm(path, full) { 7 | path = full || nodePath.join(dir, path); 8 | if(!fs.existsSync(path)){ return } 9 | fs.readdirSync(path).forEach(function(file,index){ 10 | var curPath = path + "/" + file; 11 | if(fs.lstatSync(curPath).isDirectory()) { // recurse 12 | rm(null, curPath); 13 | } else { // delete file 14 | fs.unlinkSync(curPath); 15 | } 16 | }); 17 | fs.rmdirSync(path); 18 | }; -------------------------------------------------------------------------------- /lib/fun.js: -------------------------------------------------------------------------------- 1 | window.fun = function fun(e){ setTimeout(() => { 2 | e = e || {}; var $img = $('
      ') 3 | .css({position: 'fixed', width: 100, 4 | top: (e.y || e.clientY || (Math.random() * $(window).height()))-50, 5 | left: (e.x || e.clientX || e.pageX || (Math.random() * $(window).width()))-50, 6 | transform: 'rotate('+(Math.random() * 360)+'deg)' 7 | }).appendTo('body'); 8 | setTimeout(() => { $img.remove() },800); 9 | },10)}; 10 | $(document).on('keyup', fun).on('touchstart', fun).on('mousedown', fun); -------------------------------------------------------------------------------- /lib/jsonp.js: -------------------------------------------------------------------------------- 1 | var Gun = require('../gun'); 2 | module.exports = function(req, cb){ 3 | if(!req.url || !req.url.query || !req.url.query.jsonp){ return cb } 4 | cb.jsonp = req.url.query.jsonp; 5 | delete req.url.query.jsonp; 6 | Gun.obj.map(Gun.obj.ify(req.url.query['`']), function(val, i){ 7 | req.headers[i] = val; 8 | }); 9 | delete req.url.query['`']; 10 | if(req.url.query.$){ 11 | req.body = req.url.query.$; 12 | if(!Gun.obj.has(req.url.query, '^') || 'json' == req.url.query['^']){ 13 | req.body = Gun.obj.ify(req.body); // TODO: BUG! THIS IS WRONG! This doesn't handle multipart chunking, and will fail! 14 | } 15 | } 16 | delete req.url.query.$; 17 | delete req.url.query['^']; 18 | delete req.url.query['%']; 19 | var reply = {headers:{}}; 20 | return function(res){ 21 | if(!res){ return } 22 | if(res.headers){ 23 | Gun.obj.map(res.headers, function(val, field){ 24 | reply.headers[field] = val; 25 | }); 26 | } 27 | reply.headers['Content-Type'] = "text/javascript"; 28 | if(Gun.obj.has(res,'chunk') && (!reply.body || Gun.list.is(reply.chunks))){ 29 | (reply.chunks = reply.chunks || []).push(res.chunk); 30 | } 31 | if(Gun.obj.has(res,'body')){ 32 | reply.body = res.body; // self-reference yourself so on the client we can get the headers and body. 33 | reply.body = ';'+ cb.jsonp + '(' + Gun.text.ify(reply) + ');'; // javascriptify it! can't believe the client trusts us. 34 | cb(reply); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/later.d.ts: -------------------------------------------------------------------------------- 1 | import {} from '../types/gun/IGunChain'; 2 | declare module '../types/gun/IGunChain' { 3 | export interface IGunChain { 4 | /** 5 | * > Warning: Dependency script for browser: ` 6 | * 7 | * Exact timing is not guaranteed! Because it uses `setTimeout` underneath. Further, after 8 | * the timeout, it must then open and load the snapshot, this will likely add at least 1ms 9 | * to the delay. Experimental: If this is problematic, please report it, as we can modify 10 | * the implementation of later to be more precise.) 11 | * 12 | * If a process/browser has to restart, the timeout will not be called. Experimental: If 13 | * this behavior is needed, please report it, as it could be added to the implementation 14 | * 15 | * Say you save some data, but want to do something with it later, like expire it or refresh 16 | * it. Well, then later is for you! You could use this to easily implement a TTL or similar 17 | * behavior 18 | * 19 | * @param seconds the number of seconds you want to wait before firing the callback 20 | */ 21 | later( 22 | /** 23 | * @param data a safe snapshot of what you saved, including full depth documents or circular 24 | * graphs, without any of the metadata 25 | * @param key name of the data 26 | */ 27 | callback: (data: TNode, key: string) => void, 28 | seconds: number 29 | ): IGunChain; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lib/later.js: -------------------------------------------------------------------------------- 1 | var Gun = Gun || require('../gun'); 2 | Gun.chain.open || require('./open'); 3 | 4 | Gun.chain.later = function(cb, age){ 5 | var gun = this; 6 | age = age * 1000; // convert to milliseconds. 7 | setTimeout(function(){ 8 | gun.open(cb, {off: true}); 9 | }, age); 10 | return gun; 11 | } -------------------------------------------------------------------------------- /lib/load.d.ts: -------------------------------------------------------------------------------- 1 | import {} from '../types/gun/IGunChain'; 2 | declare module '../types/gun/IGunChain' { 3 | export interface IGunChain { 4 | /** 5 | * > Warning: Dependency script for browser: ` 6 | * 7 | * Loads the full object once. It is the same as open but with the behavior of once 8 | */ 9 | load( 10 | callback: (data: TNode) => void 11 | ): IGunChain; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /lib/load.js: -------------------------------------------------------------------------------- 1 | var Gun = (typeof window !== "undefined")? window.Gun : require('../gun'); 2 | Gun.chain.open || require('./open'); 3 | 4 | Gun.chain.load = function(cb, opt, at){ 5 | (opt = opt || {}).off = !0; 6 | return this.open(cb, opt, at); 7 | } -------------------------------------------------------------------------------- /lib/match.js: -------------------------------------------------------------------------------- 1 | var Type = require('../src/type'); 2 | function match(t, o){ var r = false; 3 | t = t || ''; 4 | o = Type.text.is(o)? {'=': o} : o || {}; // {'~', '=', '*', '<', '>', '+', '-', '?', '!'} // ignore case, exactly equal, anything after, lexically larger, lexically lesser, added in, subtacted from, questionable fuzzy match, and ends with. 5 | if(Type.obj.has(o,'~')){ t = t.toLowerCase(); o['='] = (o['='] || o['~']).toLowerCase() } 6 | if(Type.obj.has(o,'=')){ return t === o['='] } 7 | if(Type.obj.has(o,'*')){ if(t.slice(0, o['*'].length) === o['*']){ r = true; t = t.slice(o['*'].length) } else { return false }} 8 | if(Type.obj.has(o,'!')){ if(t.slice(-o['!'].length) === o['!']){ r = true } else { return false }} 9 | if(Type.obj.has(o,'+')){ 10 | if(Type.list.map(Type.list.is(o['+'])? o['+'] : [o['+']], function(m){ 11 | if(t.indexOf(m) >= 0){ r = true } else { return true } 12 | })){ return false } 13 | } 14 | if(Type.obj.has(o,'-')){ 15 | if(Type.list.map(Type.list.is(o['-'])? o['-'] : [o['-']], function(m){ 16 | if(t.indexOf(m) < 0){ r = true } else { return true } 17 | })){ return false } 18 | } 19 | if(Type.obj.has(o,'>')){ if(t > o['>']){ r = true } else { return false }} 20 | if(Type.obj.has(o,'<')){ if(t < o['<']){ r = true } else { return false }} 21 | function fuzzy(t,f){ var n = -1, i = 0, c; for(;c = f[i++];){ if(!~(n = t.indexOf(c, n+1))){ return false }} return true } // via http://stackoverflow.com/questions/9206013/javascript-fuzzy-search 22 | if(Type.obj.has(o,'?')){ if(fuzzy(t, o['?'])){ r = true } else { return false }} // change name! 23 | return r; 24 | } 25 | module.exports = match; -------------------------------------------------------------------------------- /lib/mix.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | var Gun = (typeof window !== "undefined")? window.Gun : require('../gun'); 3 | Gun.state.node = function(node, vertex, opt){ 4 | opt = opt || {}; 5 | opt.state = opt.state || Gun.state(); 6 | var now = Gun.obj.copy(vertex); 7 | Gun.node.is(node, function(val, key){ 8 | var ham = Gun.HAM(opt.state, Gun.state.is(node, key), Gun.state.is(vertex, key), val, vertex[key]); 9 | if(!ham.incoming){ 10 | // if(ham.defer){} 11 | return; 12 | } 13 | now = Gun.state.to(node, key, now); 14 | }); 15 | return now; 16 | } 17 | }()); -------------------------------------------------------------------------------- /lib/mobile.js: -------------------------------------------------------------------------------- 1 | import Buffer from "buffer"; 2 | import { TextEncoder, TextDecoder } from "text-encoding"; 3 | global.Buffer = global.Buffer || Buffer.Buffer; 4 | global.TextEncoder = TextEncoder; 5 | global.TextDecoder = TextDecoder; -------------------------------------------------------------------------------- /lib/nomem.js: -------------------------------------------------------------------------------- 1 | function Nomem(){ 2 | var opt = {}, u; 3 | opt.put = function(file, data, cb){ cb(null, -9) }; // dev/null! 4 | opt.get = function(file, cb){ cb(null) }; 5 | return opt; 6 | } 7 | if(typeof window !== "undefined"){ 8 | window.Nomem = Nomem; 9 | } else { 10 | try{ module.exports = Nomem }catch(e){} 11 | } -------------------------------------------------------------------------------- /lib/not.d.ts: -------------------------------------------------------------------------------- 1 | import {} from '../types/gun/IGunChain'; 2 | declare module '../types/gun/IGunChain' { 3 | export interface IGunChain { 4 | /** 5 | * > Warning: `.not` has no guarantees, since data could theoretically exist on an unrelated 6 | * peer that we have no knowledge of. If you only have one server, and data is synced 7 | * through it, then you have a pretty reasonable assurance that a not found means that 8 | * the data doesn't exist yet. Just be mindful of how you use it 9 | * 10 | * @param callback If there's reason to believe the data doesn't exist, the callback will be 11 | * invoked. This can be used as a check to prevent implicitly writing data 12 | */ 13 | not( 14 | callback: (key: string) => void 15 | ): IGunChain; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /lib/not.js: -------------------------------------------------------------------------------- 1 | if(typeof window !== "undefined"){ 2 | var Gun = window.Gun; 3 | } else { 4 | var Gun = require('../gun'); 5 | } 6 | 7 | var u; 8 | 9 | Gun.chain.not = function(cb, opt, t){ 10 | return this.get(ought, {not: cb}); 11 | } 12 | 13 | function ought(at, ev){ ev.off(); 14 | if(at.err || (u !== at.put)){ return } 15 | if(!this.not){ return } 16 | this.not.call(at.gun, at.get, function(){ console.log("Please report this bug on https://gitter.im/amark/gun and in the issues."); need.to.implement; }); 17 | } -------------------------------------------------------------------------------- /lib/open.d.ts: -------------------------------------------------------------------------------- 1 | import {} from '../types/gun/IGunChain'; 2 | declare module '../types/gun/IGunChain' { 3 | export interface IGunChain { 4 | /** 5 | * Note: This will automatically load everything it can find on the context. This may sound 6 | * convenient, but may be unnecessary and excessive - resulting in more bandwidth and 7 | * slower load times for larger data. It could also result in your entire database being 8 | * loaded, if your app is highly interconnected 9 | * 10 | * Open behaves very similarly to `gun.on`, except it gives you the full depth of a document 11 | * on every update. It also works with graphs, tables, or other data structures. Think of 12 | * it as opening up a live connection to a document 13 | * 14 | * @param callback The callback has 1 parameter, and will get called every time an update 15 | * happens anywhere in the full depth of the data. Unlike most of the API, open does not 16 | * give you a node. It gives you a copy of your data with all metadata removed. Updates to 17 | * the callback will return the same data, with changes modified onto it 18 | */ 19 | open( 20 | callback: (data: TNode) => void 21 | ): IGunChain; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /lib/path.js: -------------------------------------------------------------------------------- 1 | var Gun = (typeof window !== "undefined")? window.Gun : require('../gun'); 2 | 3 | Gun.chain.path = function(field, opt){ 4 | var back = this, gun = back, tmp; 5 | if(typeof field === 'string'){ 6 | tmp = field.split(opt || '.'); 7 | if(1 === tmp.length){ 8 | gun = back.get(field); 9 | return gun; 10 | } 11 | field = tmp; 12 | } 13 | if(field instanceof Array){ 14 | if(field.length > 1){ 15 | gun = back; 16 | var i = 0, l = field.length; 17 | for(i; i < l; i++){ 18 | //gun = gun.get(field[i], (i+1 === l)? cb : null, opt); 19 | gun = gun.get(field[i]); 20 | } 21 | } else { 22 | gun = back.get(field[0]); 23 | } 24 | return gun; 25 | } 26 | if(!field && 0 != field){ 27 | return back; 28 | } 29 | gun = back.get(''+field); 30 | return gun; 31 | } -------------------------------------------------------------------------------- /lib/radisk.d.ts: -------------------------------------------------------------------------------- 1 | import { IRadix } from './radix'; 2 | 3 | import {} from './radisk' 4 | declare module './radisk' { 5 | export const Radisk: IRadisk; 6 | export interface IRadisk { 7 | Radix: IRadix; 8 | } 9 | } 10 | 11 | declare global { 12 | interface Window { 13 | Radisk: IRadisk; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /lib/radix.d.ts: -------------------------------------------------------------------------------- 1 | import {} from './radix' 2 | declare module './radix' { 3 | export const Radix: IRadix; 4 | export interface IRadix {} 5 | } 6 | 7 | declare global { 8 | interface Window { 9 | Radix: IRadix; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /lib/radmigtmp.js: -------------------------------------------------------------------------------- 1 | module.exports = function(r){ 2 | var Radix = require('./radix'); 3 | r.find('a', function(){ 4 | var l = []; 5 | Radix.map(r.list, function(v,f){ 6 | if(!(f.indexOf('%1B') + 1)){ return } 7 | if(!v){ return } 8 | l.push([f,v]); 9 | }); 10 | if(l.length){ 11 | console.log("\n! ! ! WARNING ! ! !\nRAD v0.2020.x has detected OLD v0.2019.x data & automatically migrating. Automatic migration will be turned OFF in future versions! If you are just developing/testing, we recommend you reset your data. Please contact us if you have any concerns.\nThis message should only log once.") 12 | } 13 | var f, v; 14 | l.forEach(function(a){ 15 | f = a[0]; v = a[1]; 16 | r.list(decodeURIComponent(f), v); 17 | r.list(f, 0); 18 | }); 19 | if(!f){ return } 20 | r.find.bad(f); 21 | }) 22 | }; -------------------------------------------------------------------------------- /lib/ras.js: -------------------------------------------------------------------------------- 1 | (function(){ 2 | 3 | /** 4 | Radix AsyncStorage adapter 5 | make sure to pass AsyncStorage instance in opt.AsyncStorage 6 | example: 7 | import AsyncStorage from 'react-native' 8 | const store = Store({AsyncStorage}) 9 | const gun = new Gun({store,peers:[...]}) 10 | **/ 11 | function Store(opt){ 12 | opt = opt || {}; 13 | const store = function(){} 14 | const as = opt.AsyncStorage; 15 | store.put = function(key, data, cb) 16 | { 17 | as.setItem(''+key,data) 18 | .then(_ => cb(null,1)) 19 | .then(_ => console.log("ok put")) 20 | .catch(_ => { 21 | console.error(`failed saving to asyncstorage`,{key, data}) 22 | cb(null,0) 23 | }) 24 | } 25 | 26 | store.get = (key,cb) => { 27 | as.getItem(''+key) 28 | .then(data => cb(null,data)) 29 | .then(_ => console.log("ok get")) 30 | .catch(_ => { 31 | console.error(`failed fetching from asyncstorage`,{key}) 32 | cb(null,0) 33 | }) 34 | } 35 | 36 | return store; 37 | } 38 | 39 | module.exports = Store 40 | 41 | }()); -------------------------------------------------------------------------------- /lib/reboot.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | var exec = require('child_process').execSync; 3 | var dir = __dirname, tmp; 4 | 5 | try{exec("crontab -l"); 6 | }catch(e){tmp = e} 7 | if(0 > tmp.toString().indexOf('no')){ return } 8 | 9 | try{tmp = exec('which node').toString(); 10 | }catch(e){console.log(e);return} 11 | 12 | try{tmp = exec('echo "@reboot '+tmp+' '+dir+'/../examples/http.js" > '+dir+'/reboot.cron'); 13 | }catch(e){console.log(e);return} 14 | 15 | try{tmp = exec('crontab '+dir+'/reboot.cron'); 16 | }catch(e){console.log(e);return} 17 | console.log(tmp.toString()); 18 | 19 | }()); -------------------------------------------------------------------------------- /lib/rfsmix.js: -------------------------------------------------------------------------------- 1 | module.exports = function(opt, store){ 2 | var rfs = require('./rfs')(opt); 3 | var p = store.put; 4 | var g = store.get; 5 | store.put = function(file, data, cb){ 6 | var a, b, c = function(err, ok){ 7 | if(b){ return cb(err || b) } 8 | if(a){ return cb(err, ok) } 9 | a = true; 10 | b = err; 11 | } 12 | p(file, data, c); // parallel 13 | rfs.put(file, data, c); // parallel 14 | } 15 | store.get = function(file, cb){ 16 | rfs.get(file, function(err, data){ 17 | //console.log("rfs3 hijacked", file); 18 | if(data){ return cb(err, data) } 19 | g(file, cb); 20 | }); 21 | } 22 | return store; 23 | } -------------------------------------------------------------------------------- /lib/rindexed.d.ts: -------------------------------------------------------------------------------- 1 | import {} from './rindexed' 2 | declare module './rindexed' { 3 | export const Store: IRindexedDB; 4 | export interface IRindexedDB { 5 | indexedDB: IRindexedDB; 6 | window: Window; 7 | } 8 | } 9 | 10 | declare global { 11 | interface Window { 12 | RindexedDB: IRindexedDB; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /lib/rls.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | 3 | function Store(opt){ 4 | opt = opt || {}; 5 | opt.file = String(opt.file || 'radata'); 6 | var store = function Store(){}; 7 | 8 | var ls = localStorage; 9 | store.put = function(key, data, cb){ ls[''+key] = data; cb(null, 1) } 10 | store.get = function(key, cb){ cb(null, ls[''+key]) } 11 | 12 | return store; 13 | } 14 | 15 | if(typeof window !== "undefined"){ 16 | (Store.window = window).RlocalStorage = Store; 17 | } else { 18 | try{ module.exports = Store }catch(e){} 19 | } 20 | 21 | try{ 22 | var Gun = Store.window.Gun || require('../gun'); 23 | Gun.on('create', function(root){ 24 | this.to.next(root); 25 | root.opt.store = root.opt.store || Store(root.opt); 26 | }); 27 | }catch(e){} 28 | 29 | }()); -------------------------------------------------------------------------------- /lib/rmem.js: -------------------------------------------------------------------------------- 1 | function Rmem(){ 2 | var opt = {}, store = {}, u; 3 | opt.put = function(file, data, cb){ 4 | //setTimeout(function(){ // make async 5 | store[file] = data; 6 | cb(null, 1); 7 | //}, 1); 8 | }; 9 | opt.get = function(file, cb){ 10 | //setTimeout(function(){ // make async 11 | var tmp = store[file] || u; 12 | cb(null, tmp); 13 | //}, 1); 14 | }; 15 | return opt; 16 | } 17 | 18 | if(typeof window !== "undefined"){ 19 | window.Rmem = Rmem; 20 | } else { 21 | try{ module.exports = Rmem }catch(e){} 22 | } -------------------------------------------------------------------------------- /lib/server.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | require('./yson'); 3 | var Gun = require('../gun'), u; 4 | Gun.serve = require('./serve'); 5 | //process.env.GUN_ENV = process.env.GUN_ENV || 'debug'; 6 | //console.LOG = {}; // only do this for dev. 7 | Gun.on('opt', function(root){ 8 | if(u === root.opt.super){ root.opt.super = true } 9 | if(u === root.opt.faith){ root.opt.faith = true } // HNPERF: This should probably be off, but we're testing performance improvements, please audit. 10 | root.opt.log = root.opt.log || Gun.log; 11 | this.to.next(root); 12 | }) 13 | //require('../nts'); 14 | require('./store'); 15 | require('./rfs'); 16 | require('./rs3'); 17 | require('./wire'); 18 | 19 | try{require('../sea');}catch(e){} 20 | try{require('../axe');}catch(e){} 21 | //require('./file'); 22 | //require('./evict'); 23 | require('./multicast'); 24 | require('./stats'); 25 | module.exports = Gun; 26 | }()); 27 | -------------------------------------------------------------------------------- /lib/shim.js: -------------------------------------------------------------------------------- 1 | var Gun = (typeof window !== "undefined")? window.Gun : require('../gun'); 2 | 3 | Gun.chain.open || require('./open'); 4 | 5 | var _on = Gun.chain.on; 6 | Gun.chain.on = function(a,b,c){ 7 | if('value' === a){ 8 | return this.open(b,c); 9 | } 10 | return _on.call(this, a,b,c); 11 | } 12 | 13 | Gun.chain.bye || require('./bye'); 14 | Gun.chain.onDisconnect = Gun.chain.bye; 15 | Gun.chain.connected = function(cb){ 16 | var root = this.back(-1), last; 17 | root.on('hi', function(peer){ 18 | if(!cb){ return } 19 | cb(last = true, peer); 20 | }); 21 | root.on('bye', function(peer){ 22 | if(!cb || last === peer){ return } 23 | cb(false, last = peer); 24 | }); 25 | return this; 26 | } -------------------------------------------------------------------------------- /lib/store.d.ts: -------------------------------------------------------------------------------- 1 | import {} from './store' 2 | declare module './store' {} 3 | -------------------------------------------------------------------------------- /lib/super.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | var Gun = (typeof window !== "undefined")? window.Gun : require('../gun'); 3 | var Rad = (Gun.window||{}).Radix || require('./radix'); 4 | /// Store the subscribes 5 | Gun.subs = Rad(); 6 | function input(msg){ 7 | var at = this.as, to = this.to, peer = (msg._||empty).via; 8 | var get = msg.get, soul, key; 9 | if(!peer || !get){ return to.next(msg) } 10 | // console.log("super", msg); 11 | if(soul = get['#']){ 12 | if(key = get['.']){ 13 | 14 | } else { 15 | 16 | } 17 | if (!peer.id) {console.log('[*** WARN] no peer.id %s', soul);} 18 | var subs = Gun.subs(soul) || null; 19 | var tmp = subs ? subs.split(',') : [], p = at.opt.peers; 20 | if (subs) { 21 | Gun.obj.map(subs.split(','), function(peerid) { 22 | if (peerid in p) { tmp.push(peerid); } 23 | }); 24 | } 25 | if (tmp.indexOf(peer.id) === -1) { tmp.push(peer.id);} 26 | tmp = tmp.join(','); 27 | Gun.subs(soul, tmp); 28 | var dht = {}; 29 | dht[soul] = tmp; 30 | at.opt.mesh.say({dht:dht}, peer); 31 | } 32 | to.next(msg); 33 | } 34 | var empty = {}, u; 35 | if(Gun.window){ return } 36 | try{module.exports = input}catch(e){} 37 | }()); 38 | -------------------------------------------------------------------------------- /lib/text-encoding/index.js: -------------------------------------------------------------------------------- 1 | // This is free and unencumbered software released into the public domain. 2 | // See LICENSE.md for more information. 3 | 4 | var encoding = require("./lib/encoding.js"); 5 | 6 | module.exports = { 7 | TextEncoder: encoding.TextEncoder, 8 | TextDecoder: encoding.TextDecoder, 9 | }; 10 | -------------------------------------------------------------------------------- /lib/then.d.ts: -------------------------------------------------------------------------------- 1 | import { GunDataNode, IGunChain } from '..'; 2 | 3 | import {} from '../types/gun/IGunChain'; 4 | declare module '../types/gun/IGunChain' { 5 | export interface IGunChain { 6 | /** 7 | * Could be buggy until official! 8 | * 9 | * Note: a gun chain is not promises! You must include and call `.then()` to promisify a gun 10 | * chain! 11 | */ 12 | then(): Promise>; 13 | 14 | /** 15 | * Could be buggy until official! 16 | * 17 | * `.then()` has a cousin of `.promise()` which behaves the same way except that resolved 18 | * is an object in case you need more context or metadata 19 | */ 20 | promise(): Promise<{ 21 | put: GunDataNode; 22 | get: TKey; 23 | gun: IGunChain; 24 | }>; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /lib/then.js: -------------------------------------------------------------------------------- 1 | var Gun = (typeof window !== "undefined")? window.Gun : require('../gun'); 2 | 3 | // Returns a gun reference in a promise and then calls a callback if specified 4 | Gun.chain.promise = function(cb) { 5 | var gun = this, cb = cb || function(ctx) { return ctx }; 6 | return (new Promise(function(res, rej) { 7 | gun.once(function(data, key){ 8 | res({put: data, get: key, gun: this}); // gun reference is returned by promise 9 | }); 10 | })).then(cb); //calling callback with resolved data 11 | }; 12 | 13 | // Returns a promise for the data, key of the gun call 14 | Gun.chain.then = function(cb) { 15 | var gun = this; 16 | var p = (new Promise((res, rej)=>{ 17 | gun.once(function (data, key) { 18 | res(data, key); //call resolve when data is returned 19 | }) 20 | })) 21 | return cb ? p.then(cb) : p; 22 | }; 23 | -------------------------------------------------------------------------------- /lib/unset.d.ts: -------------------------------------------------------------------------------- 1 | import { GunSchema, GunSoul, IGunChain } from '..'; 2 | 3 | import {} from '../types/gun/IGunChain'; 4 | import { IGunChain2TNode } from '../types/utils'; 5 | declare module '../types/gun/IGunChain' { 6 | export interface IGunChain { 7 | /** 8 | * After you save some data in an unordered list, you may need to remove it 9 | */ 10 | unset< 11 | T extends Partial | GunSoul | IGunChain, 12 | K extends keyof TNode & string, 13 | V extends TNode[K] & Record 14 | >( 15 | node: IGunChain< 16 | IGunChain2TNode, 17 | IGunChain, 18 | TGunInstance, 19 | K 20 | > 21 | ): IGunChain; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /lib/unset.js: -------------------------------------------------------------------------------- 1 | var Gun = (typeof window !== "undefined")? window.Gun : require('../gun'); 2 | 3 | const rel_ = '#'; // '#' 4 | const node_ = '_'; // '_' 5 | 6 | Gun.chain.unset = function(node){ 7 | if( this && node && node[node_] && node[node_].put && node[node_].put[node_] && node[node_].put[node_][rel_] ){ 8 | this.put( { [node[node_].put[node_][rel_]]:null} ); 9 | } 10 | return this; 11 | } 12 | -------------------------------------------------------------------------------- /lib/webrtc.d.ts: -------------------------------------------------------------------------------- 1 | import {} from './webrtc' 2 | declare module './webrtc' {} 3 | -------------------------------------------------------------------------------- /sea.d.ts: -------------------------------------------------------------------------------- 1 | import { ISEA } from './types/sea/ISEA'; 2 | 3 | declare const SEA: ISEA; 4 | export default SEA; 5 | 6 | import {} from './types/sea/ISEA'; 7 | declare module './types/sea/ISEA' { 8 | export interface ISEA { 9 | window: Window 10 | } 11 | } 12 | 13 | import {} from './types/gun/IGun'; 14 | declare module './types/gun/IGun' { 15 | export interface IGun { 16 | SEA: ISEA; 17 | } 18 | } 19 | 20 | declare global { 21 | interface Window { 22 | SEA: ISEA; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /sea/aeskey.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | 3 | var shim = require('./shim'); 4 | var S = require('./settings'); 5 | var sha256hash = require('./sha256'); 6 | 7 | const importGen = async (key, salt, opt) => { 8 | //const combo = shim.Buffer.concat([shim.Buffer.from(key, 'utf8'), salt || shim.random(8)]).toString('utf8') // old 9 | opt = opt || {}; 10 | const combo = key + (salt || shim.random(8)).toString('utf8'); // new 11 | const hash = shim.Buffer.from(await sha256hash(combo), 'binary') 12 | 13 | const jwkKey = S.keyToJwk(hash) 14 | return await shim.subtle.importKey('jwk', jwkKey, {name:'AES-GCM'}, false, ['encrypt', 'decrypt']) 15 | } 16 | module.exports = importGen; 17 | 18 | }()); -------------------------------------------------------------------------------- /sea/array.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | 3 | require('./base64'); 4 | // This is Array extended to have .toString(['utf8'|'hex'|'base64']) 5 | function SeaArray() {} 6 | Object.assign(SeaArray, { from: Array.from }) 7 | SeaArray.prototype = Object.create(Array.prototype) 8 | SeaArray.prototype.toString = function(enc, start, end) { enc = enc || 'utf8'; start = start || 0; 9 | const length = this.length 10 | if (enc === 'hex') { 11 | const buf = new Uint8Array(this) 12 | return [ ...Array(((end && (end + 1)) || length) - start).keys()] 13 | .map((i) => buf[ i + start ].toString(16).padStart(2, '0')).join('') 14 | } 15 | if (enc === 'utf8') { 16 | return Array.from( 17 | { length: (end || length) - start }, 18 | (_, i) => String.fromCharCode(this[ i + start]) 19 | ).join('') 20 | } 21 | if (enc === 'base64') { 22 | return btoa(this) 23 | } 24 | } 25 | module.exports = SeaArray; 26 | 27 | }()); -------------------------------------------------------------------------------- /sea/base64.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | 3 | var u; 4 | if(u+''== typeof btoa){ 5 | if(u+'' == typeof Buffer){ 6 | try{ global.Buffer = require("buffer", 1).Buffer }catch(e){ console.log("Please `npm install buffer` or add it to your package.json !") } 7 | } 8 | global.btoa = function(data){ return Buffer.from(data, "binary").toString("base64") }; 9 | global.atob = function(data){ return Buffer.from(data, "base64").toString("binary") }; 10 | } 11 | 12 | }()); -------------------------------------------------------------------------------- /sea/https.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | 3 | var SEA = require('./root'); 4 | try{ if(SEA.window){ 5 | if(location.protocol.indexOf('s') < 0 6 | && location.host.indexOf('localhost') < 0 7 | && ! /^127\.\d+\.\d+\.\d+$/.test(location.hostname) 8 | && location.protocol.indexOf('blob:') < 0 9 | && location.protocol.indexOf('file:') < 0 10 | && location.origin != 'null'){ 11 | console.warn('HTTPS needed for WebCrypto in SEA, redirecting...'); 12 | location.protocol = 'https:'; // WebCrypto does NOT work without HTTPS! 13 | } 14 | } }catch(e){} 15 | 16 | }()); -------------------------------------------------------------------------------- /sea/recall.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | 3 | var User = require('./user'), SEA = User.SEA, Gun = User.GUN; 4 | User.prototype.recall = function(opt, cb){ 5 | var gun = this, root = gun.back(-1), tmp; 6 | opt = opt || {}; 7 | if(opt && opt.sessionStorage){ 8 | if(SEA.window){ 9 | try{ 10 | var sS = {}; 11 | sS = SEA.window.sessionStorage; // TODO: FIX BUG putting on `.is`! 12 | if(sS){ 13 | (root._).opt.remember = true; 14 | ((gun.back('user')._).opt||opt).remember = true; 15 | if(sS.recall || sS.pair) root.user().auth(JSON.parse(sS.pair), cb); // pair is more reliable than alias/pass 16 | } 17 | }catch(e){} 18 | } 19 | return gun; 20 | } 21 | /* 22 | TODO: copy mhelander's expiry code back in. 23 | Although, we should check with community, 24 | should expiry be core or a plugin? 25 | */ 26 | return gun; 27 | } 28 | 29 | }()); -------------------------------------------------------------------------------- /sea/root.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | 3 | // Security, Encryption, and Authorization: SEA.js 4 | // MANDATORY READING: https://gun.eco/explainers/data/security.html 5 | // IT IS IMPLEMENTED IN A POLYFILL/SHIM APPROACH. 6 | // THIS IS AN EARLY ALPHA! 7 | 8 | if(typeof self !== "undefined"){ module.window = self } // should be safe for at least browser/worker/nodejs, need to check other envs like RN etc. 9 | if(typeof window !== "undefined"){ module.window = window } 10 | 11 | var tmp = module.window || module, u; 12 | var SEA = tmp.SEA || {}; 13 | 14 | if(SEA.window = module.window){ SEA.window.SEA = SEA } 15 | 16 | try{ if(u+'' !== typeof MODULE){ MODULE.exports = SEA } }catch(e){} 17 | module.exports = SEA; 18 | 19 | }()); -------------------------------------------------------------------------------- /sea/sha1.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | 3 | // This internal func returns SHA-1 hashed data for KeyID generation 4 | const __shim = require('./shim') 5 | const subtle = __shim.subtle 6 | const ossl = __shim.ossl ? __shim.ossl : subtle 7 | const sha1hash = (b) => ossl.digest({name: 'SHA-1'}, new ArrayBuffer(b)) 8 | module.exports = sha1hash 9 | 10 | }()); -------------------------------------------------------------------------------- /sea/sha256.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | 3 | var shim = require('./shim'); 4 | module.exports = async function(d, o){ 5 | var t = (typeof d == 'string')? d : await shim.stringify(d); 6 | var hash = await shim.subtle.digest({name: o||'SHA-256'}, new shim.TextEncoder().encode(t)); 7 | return shim.Buffer.from(hash); 8 | } 9 | 10 | }()); -------------------------------------------------------------------------------- /sea/then.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | 3 | var u, Gun = (''+u != typeof GUN)? (GUN||{chain:{}}) : require((''+u === typeof MODULE?'.':'')+'./gun', 1); 4 | Gun.chain.then = function(cb, opt){ 5 | var gun = this, p = (new Promise(function(res, rej){ 6 | gun.once(res, opt); 7 | })); 8 | return cb? p.then(cb) : p; 9 | } 10 | 11 | }()); -------------------------------------------------------------------------------- /sea/user.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | 3 | var SEA = require('./sea'), Gun, u; 4 | if(SEA.window){ 5 | Gun = SEA.window.GUN || {chain:{}}; 6 | } else { 7 | Gun = require((u+'' == typeof MODULE?'.':'')+'./gun', 1); 8 | } 9 | SEA.GUN = Gun; 10 | 11 | function User(root){ 12 | this._ = {$: this}; 13 | } 14 | User.prototype = (function(){ function F(){}; F.prototype = Gun.chain; return new F() }()) // Object.create polyfill 15 | User.prototype.constructor = User; 16 | 17 | // let's extend the gun chain with a `user` function. 18 | // only one user can be logged in at a time, per gun instance. 19 | Gun.chain.user = function(pub){ 20 | var gun = this, root = gun.back(-1), user; 21 | if(pub){ 22 | pub = SEA.opt.pub((pub._||'')['#']) || pub; 23 | return root.get('~'+pub); 24 | } 25 | if(user = root.back('user')){ return user } 26 | var root = (root._), at = root, uuid = at.opt.uuid || lex; 27 | (at = (user = at.user = gun.chain(new User))._).opt = {}; 28 | at.opt.uuid = function(cb){ 29 | var id = uuid(), pub = root.user; 30 | if(!pub || !(pub = pub.is) || !(pub = pub.pub)){ return id } 31 | id = '~' + pub + '/' + id; 32 | if(cb && cb.call){ cb(null, id) } 33 | return id; 34 | } 35 | return user; 36 | } 37 | function lex(){ return Gun.state().toString(36).replace('.','') } 38 | Gun.User = User; 39 | User.GUN = Gun; 40 | User.SEA = Gun.SEA = SEA; 41 | module.exports = User; 42 | 43 | }()); -------------------------------------------------------------------------------- /src/ask.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | 3 | // request / response module, for asking and acking messages. 4 | require('./onto'); // depends upon onto! 5 | module.exports = function ask(cb, as){ 6 | if(!this.on){ return } 7 | var lack = (this.opt||{}).lack || 9000; 8 | if(!('function' == typeof cb)){ 9 | if(!cb){ return } 10 | var id = cb['#'] || cb, tmp = (this.tag||'')[id]; 11 | if(!tmp){ return } 12 | if(as){ 13 | tmp = this.on(id, as); 14 | clearTimeout(tmp.err); 15 | tmp.err = setTimeout(function(){ tmp.off() }, lack); 16 | } 17 | return true; 18 | } 19 | var id = (as && as['#']) || random(9); 20 | if(!cb){ return id } 21 | var to = this.on(id, cb, as); 22 | to.err = to.err || setTimeout(function(){ to.off(); 23 | to.next({err: "Error: No ACK yet.", lack: true}); 24 | }, lack); 25 | return id; 26 | } 27 | var random = String.random || function(){ return Math.random().toString(36).slice(2) } 28 | 29 | }()); -------------------------------------------------------------------------------- /src/back.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | 3 | var Gun = require('./root'); 4 | Gun.chain.back = function(n, opt){ var tmp; 5 | n = n || 1; 6 | if(-1 === n || Infinity === n){ 7 | return this._.root.$; 8 | } else 9 | if(1 === n){ 10 | return (this._.back || this._).$; 11 | } 12 | var gun = this, at = gun._; 13 | if(typeof n === 'string'){ 14 | n = n.split('.'); 15 | } 16 | if(n instanceof Array){ 17 | var i = 0, l = n.length, tmp = at; 18 | for(i; i < l; i++){ 19 | tmp = (tmp||empty)[n[i]]; 20 | } 21 | if(u !== tmp){ 22 | return opt? gun : tmp; 23 | } else 24 | if((tmp = at.back)){ 25 | return tmp.$.back(n, opt); 26 | } 27 | return; 28 | } 29 | if('function' == typeof n){ 30 | var yes, tmp = {back: at}; 31 | while((tmp = tmp.back) 32 | && u === (yes = n(tmp, opt))){} 33 | return yes; 34 | } 35 | if('number' == typeof n){ 36 | return (at.back || at).$.back(n - 1); 37 | } 38 | return this; 39 | } 40 | var empty = {}, u; 41 | 42 | }()); -------------------------------------------------------------------------------- /src/core.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | 3 | var Gun = require('./root'); 4 | require('./chain'); 5 | require('./back'); 6 | require('./put'); 7 | require('./get'); 8 | module.exports = Gun; 9 | 10 | }()); -------------------------------------------------------------------------------- /src/dup.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | 3 | require('./shim'); 4 | function Dup(opt){ 5 | var dup = {s:{}}, s = dup.s; 6 | opt = opt || {max: 999, age: 1000 * 9};//*/ 1000 * 9 * 3}; 7 | dup.check = function(id){ 8 | if(!s[id]){ return false } 9 | return dt(id); 10 | } 11 | var dt = dup.track = function(id){ 12 | var it = s[id] || (s[id] = {}); 13 | it.was = dup.now = +new Date; 14 | if(!dup.to){ dup.to = setTimeout(dup.drop, opt.age + 9) } 15 | if(dt.ed){ dt.ed(id) } 16 | return it; 17 | } 18 | dup.drop = function(age){ 19 | dup.to = null; 20 | dup.now = +new Date; 21 | var l = Object.keys(s); 22 | console.STAT && console.STAT(dup.now, +new Date - dup.now, 'dup drop keys'); // prev ~20% CPU 7% RAM 300MB // now ~25% CPU 7% RAM 500MB 23 | setTimeout.each(l, function(id){ var it = s[id]; // TODO: .keys( is slow? 24 | if(it && (age || opt.age) > (dup.now - it.was)){ return } 25 | delete s[id]; 26 | },0,99); 27 | } 28 | return dup; 29 | } 30 | module.exports = Dup; 31 | 32 | }()); -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | 3 | var Gun = require('./root'); 4 | require('./shim'); 5 | require('./onto'); 6 | require('./book'); 7 | require('./valid'); 8 | require('./state'); 9 | require('./dup'); 10 | require('./ask'); 11 | require('./core'); 12 | require('./on'); 13 | require('./map'); 14 | require('./set'); 15 | require('./mesh'); 16 | require('./websocket'); 17 | require('./localStorage'); 18 | module.exports = Gun; 19 | 20 | }()); -------------------------------------------------------------------------------- /src/onto.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | 3 | // On event emitter generic javascript utility. 4 | module.exports = function onto(tag, arg, as){ 5 | if(!tag){ return {to: onto} } 6 | var u, f = 'function' == typeof arg, tag = (this.tag || (this.tag = {}))[tag] || f && ( 7 | this.tag[tag] = {tag: tag, to: onto._ = { next: function(arg){ var tmp; 8 | if(tmp = this.to){ tmp.next(arg) } 9 | }}}); 10 | if(f){ 11 | var be = { 12 | off: onto.off || 13 | (onto.off = function(){ 14 | if(this.next === onto._.next){ return !0 } 15 | if(this === this.the.last){ 16 | this.the.last = this.back; 17 | } 18 | this.to.back = this.back; 19 | this.next = onto._.next; 20 | this.back.to = this.to; 21 | if(this.the.last === this.the){ 22 | delete this.on.tag[this.the.tag]; 23 | } 24 | }), 25 | to: onto._, 26 | next: arg, 27 | the: tag, 28 | on: this, 29 | as: as, 30 | }; 31 | (be.back = tag.last || tag).to = be; 32 | return tag.last = be; 33 | } 34 | if((tag = tag.to) && u !== arg){ tag.next(arg) } 35 | return tag; 36 | }; 37 | 38 | }()); -------------------------------------------------------------------------------- /src/polyfill/unbuild.js: -------------------------------------------------------------------------------- 1 | 2 | function USE(arg, req){ 3 | return req? require(arg) : arg.slice? USE[R(arg)] : function(mod, path){ 4 | arg(mod = {exports: {}}); 5 | USE[R(path)] = mod.exports; 6 | } 7 | function R(p){ 8 | return p.split('/').slice(-1).toString().replace('.js',''); 9 | } 10 | } 11 | if(typeof module !== "undefined"){ var MODULE = module } 12 | -------------------------------------------------------------------------------- /src/set.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | 3 | var Gun = require('./root'); 4 | Gun.chain.set = function(item, cb, opt){ 5 | var gun = this, root = gun.back(-1), soul, tmp; 6 | cb = cb || function(){}; 7 | opt = opt || {}; opt.item = opt.item || item; 8 | if(soul = ((item||'')._||'')['#']){ (item = {})['#'] = soul } // check if node, make link. 9 | if('string' == typeof (tmp = Gun.valid(item))){ return gun.get(soul = tmp).put(item, cb, opt) } // check if link 10 | if(!Gun.is(item)){ 11 | if(Object.plain(item)){ 12 | item = root.get(soul = gun.back('opt.uuid')()).put(item); 13 | } 14 | return gun.get(soul || root.back('opt.uuid')(7)).put(item, cb, opt); 15 | } 16 | gun.put(function(go){ 17 | item.get(function(soul, o, msg){ // TODO: BUG! We no longer have this option? & go error not handled? 18 | if(!soul){ return cb.call(gun, {err: Gun.log('Only a node can be linked! Not "' + msg.put + '"!')}) } 19 | (tmp = {})[soul] = {'#': soul}; go(tmp); 20 | },true); 21 | }) 22 | return item; 23 | } 24 | 25 | }()); -------------------------------------------------------------------------------- /src/state.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | 3 | require('./shim'); 4 | function State(){ 5 | var t = +new Date; 6 | if(last < t){ 7 | return N = 0, last = t + State.drift; 8 | } 9 | return last = t + ((N += 1) / D) + State.drift; 10 | } 11 | State.drift = 0; 12 | var NI = -Infinity, N = 0, D = 999, last = NI, u; // WARNING! In the future, on machines that are D times faster than 2016AD machines, you will want to increase D by another several orders of magnitude so the processing speed never out paces the decimal resolution (increasing an integer effects the state accuracy). 13 | State.is = function(n, k, o){ // convenience function to get the state on a key on a node and return it. 14 | var tmp = (k && n && n._ && n._['>']) || o; 15 | if(!tmp){ return } 16 | return ('number' == typeof (tmp = tmp[k]))? tmp : NI; 17 | } 18 | State.ify = function(n, k, s, v, soul){ // put a key's state on a node. 19 | (n = n || {})._ = n._ || {}; // safety check or init. 20 | if(soul){ n._['#'] = soul } // set a soul if specified. 21 | var tmp = n._['>'] || (n._['>'] = {}); // grab the states data. 22 | if(u !== k && k !== '_'){ 23 | if('number' == typeof s){ tmp[k] = s } // add the valid state. 24 | if(u !== v){ n[k] = v } // Note: Not its job to check for valid values! 25 | } 26 | return n; 27 | } 28 | module.exports = State; 29 | 30 | }()); -------------------------------------------------------------------------------- /src/valid.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | 3 | // Valid values are a subset of JSON: null, binary, number (!Infinity), text, 4 | // or a soul relation. Arrays need special algorithms to handle concurrency, 5 | // so they are not supported directly. Use an extension that supports them if 6 | // needed but research their problems first. 7 | module.exports = function(v){ 8 | // "deletes", nulling out keys. 9 | return v === null || 10 | "string" === typeof v || 11 | "boolean" === typeof v || 12 | // we want +/- Infinity to be, but JSON does not support it, sad face. 13 | // can you guess what v === v checks for? ;) 14 | ("number" === typeof v && v != Infinity && v != -Infinity && v === v) || 15 | (!!v && "string" == typeof v["#"] && Object.keys(v).length === 1 && v["#"]); 16 | } 17 | 18 | }()); -------------------------------------------------------------------------------- /test/abc.js: -------------------------------------------------------------------------------- 1 | var expect = global.expect = require("./expect"); 2 | require('./common'); -------------------------------------------------------------------------------- /test/bug/783.js: -------------------------------------------------------------------------------- 1 | 2 | ///// bug-783 3 | 4 | describe('Gun', function(){ 5 | var root; 6 | (function(){ 7 | var env; 8 | if(typeof global !== 'undefined'){ env = global } 9 | if(typeof window !== 'undefined'){ env = window } 10 | root = env.window? env.window : global; 11 | try{ env.window && root.localStorage && root.localStorage.clear() }catch(e){} 12 | try{ localStorage.clear() }catch(e){} 13 | try{ indexedDB.deleteDatabase('radatatest') }catch(e){} 14 | try{ require('fs').unlinkSync('data.json') }catch(e){} 15 | try{ require('../../lib/fsrm')('radatatest') }catch(e){} 16 | try{ var expect = global.expect = require("../expect") }catch(e){} 17 | 18 | //root.Gun = root.Gun || require('../gun'); 19 | if(root.Gun){ 20 | root.Gun = root.Gun; 21 | root.Gun.TESTING = true; 22 | } else { 23 | root.Gun = require('../../gun'); 24 | root.Gun.TESTING = true; 25 | Gun.serve = require('../../lib/serve'); 26 | //require('../lib/file'); 27 | require('../../lib/store'); 28 | require('../../lib/rfs'); 29 | require('../../sea.js'); 30 | } 31 | }(this)); 32 | 33 | describe('erro sea', function(){ 34 | it('verbose console.log debugging', function(done) { 35 | var gun = Gun({multicast:false, axe:false}); 36 | var ref = gun.get('test').get('1'); 37 | var vput = 'SEA{}'; 38 | ref.put(vput, function(ack, yay){ console.log('ACK: ', ack); /// must ack all 39 | ref.once(function(v,k) { console.log('SALVOU k:%s, v:', k, v); 40 | expect(v===vput).to.be(true); 41 | done(); 42 | }); 43 | }); 44 | }); 45 | } ); 46 | }); 47 | -------------------------------------------------------------------------------- /test/debug/deep-set.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /test/download-log.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Paste the log URL into here: 4 | 5 | Then right click save-as here: 6 | right click not normal click 7 | 12 | 13 | -------------------------------------------------------------------------------- /test/gun.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /test/https/ca.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICjzCCAfgCCQDubvP01FilhzANBgkqhkiG9w0BAQUFADCBizELMAkGA1UEBhMC 3 | VVMxGTAXBgNVBAgTEENhbGlmb3JuaWEtU3RhdGUxFTATBgNVBAcTDFJlZHdvb2Qg 4 | Q2l0eTEPMA0GA1UEChMGR1VOSU5DMQwwCgYDVQQLEwN3ZWIxDTALBgNVBAMTBG1h 5 | cmsxHDAaBgkqhkiG9w0BCQEWDW1hcmtAZ3VuREIuaW8wHhcNMTgwMTI5MjExMjAx 6 | WhcNMTkwMTI5MjExMjAxWjCBizELMAkGA1UEBhMCVVMxGTAXBgNVBAgTEENhbGlm 7 | b3JuaWEtU3RhdGUxFTATBgNVBAcTDFJlZHdvb2QgQ2l0eTEPMA0GA1UEChMGR1VO 8 | SU5DMQwwCgYDVQQLEwN3ZWIxDTALBgNVBAMTBG1hcmsxHDAaBgkqhkiG9w0BCQEW 9 | DW1hcmtAZ3VuREIuaW8wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMLWuNOJ 10 | 1BWGKZtSh1NPAIpfeb7l2tFq7kIFSdxXg/+sb8b8CT5+nZPd+p8PDLR/pGab5dKg 11 | gjh+Gr4ixAPgXbabLq8aWlKKHUNi5APfUii3qWAvpHTxfDzor1KwHCU0sU6PrMz0 12 | vKkG8rpCt3nKom8roWChG9NEVdm3tO9Q2SOJAgMBAAEwDQYJKoZIhvcNAQEFBQAD 13 | gYEAYbPdLZGAbs/boDECu9qxAdlEC8zTXTRQwlBbKgiNsZjJPskczbfvKLgVbcaK 14 | 0FMqzIi/OYSb15XgSu1j4WvitoZqiMr89H05w7N6Et/SnEFxAfDZc+UvlrvsKKeX 15 | /eTDcEaTl+nNEMuyX3+UzziAa0Pytdmd5tiWNm4gTMPb4AM= 16 | -----END CERTIFICATE----- 17 | -------------------------------------------------------------------------------- /test/https/ca.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIIB+DCCAWECAQAwgYsxCzAJBgNVBAYTAlVTMRkwFwYDVQQIExBDYWxpZm9ybmlh 3 | LVN0YXRlMRUwEwYDVQQHEwxSZWR3b29kIENpdHkxDzANBgNVBAoTBkdVTklOQzEM 4 | MAoGA1UECxMDd2ViMQ0wCwYDVQQDEwRtYXJrMRwwGgYJKoZIhvcNAQkBFg1tYXJr 5 | QGd1bkRCLmlvMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDC1rjTidQVhimb 6 | UodTTwCKX3m+5drRau5CBUncV4P/rG/G/Ak+fp2T3fqfDwy0f6Rmm+XSoII4fhq+ 7 | IsQD4F22my6vGlpSih1DYuQD31Iot6lgL6R08Xw86K9SsBwlNLFOj6zM9LypBvK6 8 | Qrd5yqJvK6FgoRvTRFXZt7TvUNkjiQIDAQABoCwwEgYJKoZIhvcNAQkCMQUTA2d1 9 | bjAWBgkqhkiG9w0BCQcxCRMHY29va2llczANBgkqhkiG9w0BAQUFAAOBgQBoYOzr 10 | g0wgtICI5XQTVz4uh3fZPpOUwypZO4EGOOrXixoLtMqHUo1Im+3yC8F7QVnWeBB2 11 | M3eXWCf1E4FthYlVBS1S8nkMxDuG2v1GvmxDa0ZCbG4lhNpUeL31rth7R3vtxBZI 12 | Sc4hRkqz5s/xe3VZ3TJnQYRufNq4Ve95cx7/ow== 13 | -----END CERTIFICATE REQUEST----- 14 | -------------------------------------------------------------------------------- /test/https/ca.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | Proc-Type: 4,ENCRYPTED 3 | DEK-Info: DES-EDE3-CBC,CC0029B0687E54A1 4 | 5 | ucowo8yAKtQZMhvRhi5LLPekwsZifKjnW6zEA3OBP1UiNmbppGESmbf2mbRwalic 6 | e77nC0iUdJjwSjnGcLk05fAP7SoQV1IlWbmk3xhvk/TewWZnwhelwfhYv/NNFJ4K 7 | 8oXtYi0d4KquadxmUlvXssUj2ycbmJ1QPj/xo0fu74O6BO884ssn4BCuCLh34gRQ 8 | KsEZVIuuB6PHdh5kfzaaFCLYP3rt2t3zFTZ3PpzV52YnxI+dqMcMVB1baMv7Cl4o 9 | nIap2LZwF6KzCihZx1PiMS1KxWPoylSe66vltbLX+Vu9AY4TS/+15ccpJDMI8FkK 10 | v3o0sL3Cvd6sXGHjcKehhFnzmfljJPhf0OhhZvEG0y0xjG3nJ85k4BgF4g1v3J5D 11 | RX3YTUoUeKcMATL6JFn+R38TiQL7COQSf3gsrUxkyD5md8P+I6nW5RNjwI9miVTu 12 | kAm/m4MsfEf/semzx4DHrm8Qvc01j6nsQ1zKjSVhhn5Utx8UGQgcKMz8GotH/bVY 13 | Po0Ra5d0zk6pGRD4CEjKZFvwjMyydod8N8EY92X/awwYiY3lcF1L6wyz3d11yfRT 14 | aL+yCuIhMVMU50X0DXTnfHnK59F6gsv7hosLUSV0gksQ6SJaTt9PLKyBblwTGsRa 15 | ZkhM+tBJiJ8C/AFEuCTEjI8Pp2BXW6W4J+mOMwyJzvR4Vs5S5/Qf/Y6JQAt8uRPH 16 | WTtucevP1DDxayQWwGocbtW148ZSGOVKD9V45L9CbNejilpVi4dGWZoRWd3KXYNy 17 | NSvVSCA9kWGciJGUpowxvsINzuGO5fvsKIntrhVoumPiphQPTmZFDw== 18 | -----END RSA PRIVATE KEY----- 19 | -------------------------------------------------------------------------------- /test/https/server.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICjzCCAfgCCQCghTkg/FWMvjANBgkqhkiG9w0BAQUFADCBizELMAkGA1UEBhMC 3 | VVMxGTAXBgNVBAgTEENhbGlmb3JuaWEtU3RhdGUxFTATBgNVBAcTDFJlZHdvb2Qg 4 | Q2l0eTEPMA0GA1UEChMGR1VOSU5DMQwwCgYDVQQLEwN3ZWIxDTALBgNVBAMTBG1h 5 | cmsxHDAaBgkqhkiG9w0BCQEWDW1hcmtAZ3VuREIuaW8wHhcNMTgwMTI5MjExNDE1 6 | WhcNMTkwMTI5MjExNDE1WjCBizELMAkGA1UEBhMCVVMxGTAXBgNVBAgTEENhbGlm 7 | b3JuaWEtU3RhdGUxFTATBgNVBAcTDFJlZHdvb2QgQ2l0eTEPMA0GA1UEChMGR1VO 8 | SU5DMQwwCgYDVQQLEwN3ZWIxDTALBgNVBAMTBG1hcmsxHDAaBgkqhkiG9w0BCQEW 9 | DW1hcmtAZ3VuREIuaW8wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALAQyUjI 10 | oRMInF6q1bevlxUUP/V0wo1TwoE5VG4VyEqoVzcD/idWzMdjDIQ80qUnWFE1LdBs 11 | xNntWzOi2xq+YgkMIJYVZ3uqU10m2EpKehsBpGHSwkkxNl1btiTd8nzi/cxeMtNs 12 | Pzh7VCOcdOYYcCDpGV1YVBjgbviAaW/3xielAgMBAAEwDQYJKoZIhvcNAQEFBQAD 13 | gYEAbNm8gaD4Y3/LyeGyMmaFUS0d6bxon2QybpdW9y1gzsMH1eHL/GJZg6DzG1d5 14 | 9VDV+7yym293cyvgd41UTRg2Wdq/ev6D/gPiewEc/OYQsMXWvsMGXNUDFar9W+lB 15 | 2RlwZFfdO55S26lS8RAOrhqkXz7TEprUYXi8+y1vUcXI1i8= 16 | -----END CERTIFICATE----- 17 | -------------------------------------------------------------------------------- /test/https/server.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIIB+DCCAWECAQAwgYsxCzAJBgNVBAYTAlVTMRkwFwYDVQQIExBDYWxpZm9ybmlh 3 | LVN0YXRlMRUwEwYDVQQHEwxSZWR3b29kIENpdHkxDzANBgNVBAoTBkdVTklOQzEM 4 | MAoGA1UECxMDd2ViMQ0wCwYDVQQDEwRtYXJrMRwwGgYJKoZIhvcNAQkBFg1tYXJr 5 | QGd1bkRCLmlvMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCwEMlIyKETCJxe 6 | qtW3r5cVFD/1dMKNU8KBOVRuFchKqFc3A/4nVszHYwyEPNKlJ1hRNS3QbMTZ7Vsz 7 | otsavmIJDCCWFWd7qlNdJthKSnobAaRh0sJJMTZdW7Yk3fJ84v3MXjLTbD84e1Qj 8 | nHTmGHAg6RldWFQY4G74gGlv98YnpQIDAQABoCwwEgYJKoZIhvcNAQkCMQUTA2d1 9 | bjAWBgkqhkiG9w0BCQcxCRMHY29va2llczANBgkqhkiG9w0BAQUFAAOBgQBrEA3w 10 | waExtouDsYND3oSbCD87jDMh+uRxOuRqfeAky1juGFILslBWY4kXgUrcOOV92XNf 11 | M2CUePQ136M7oTS2HOajXDu4IVJRhWKqexoQrcWQ3w7+8e75NaXh2/9wg2KqqZfv 12 | 07MlphBb8Si6M3VNTHMmxfYWT0GozfsLezjeww== 13 | -----END CERTIFICATE REQUEST----- 14 | -------------------------------------------------------------------------------- /test/https/server.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIICXQIBAAKBgQCwEMlIyKETCJxeqtW3r5cVFD/1dMKNU8KBOVRuFchKqFc3A/4n 3 | VszHYwyEPNKlJ1hRNS3QbMTZ7VszotsavmIJDCCWFWd7qlNdJthKSnobAaRh0sJJ 4 | MTZdW7Yk3fJ84v3MXjLTbD84e1QjnHTmGHAg6RldWFQY4G74gGlv98YnpQIDAQAB 5 | AoGBAJrSF/2tlp5jGwXP2WDNwd/iT5+qzY1zEv2JCSpIczjbMN4K38l99VJ7Ub1S 6 | srRRlcLLLX8ytiMgKeuNEHhC43a11nL2XdDN9YpiINWX251ynfJSF6cr7oiMbajy 7 | Jtrk9zLIjRBdA2IBZ+q6APQNWqDD/dZM5sMBZguKokKhVOcdAkEA1Vsnqjda+0c9 8 | /655PSHYOplktq4fXbumgPW8jLZ2pCY6mASupg1DoRh3FoEbzRQxfoiH25/wklOv 9 | XUb/hKFlXwJBANNBlB7byF+p3zIPIi1WLRSrM5/RJsj3SPRWePVrWx1aEt/sa+uW 10 | GfxfLzDvLvLxXboUH0FuW4FaBxeISNqPbXsCQF43s+tyKIZgrptTZAy//mnaRWR6 11 | vjU5Ycz/N7V3+iqBC00IfEut/diNIkHY3/sPWNAE4OH23ljwBbgOW1Ypo8cCQQCQ 12 | r2hX3iUUx84yhcTdkhjcAAkiWueaWiqgFZ1QUI+dwbQNoumi9zGi9Dno5Ned0gtk 13 | RyXE9WU8aUFUL6Xd8r+DAkBoU5tC+1O2knhc7WJgQjHdz4O4ixvcD5n3/2Kmm8u0 14 | rS1Q5rKi2i5jy+JKCjD6N7ojk5Xy4iRG+71324EWbsmX 15 | -----END RSA PRIVATE KEY----- 16 | -------------------------------------------------------------------------------- /test/https/server.key.passphrase: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | Proc-Type: 4,ENCRYPTED 3 | DEK-Info: DES-EDE3-CBC,8F695953B60CC993 4 | 5 | ELvHJ4C9vhAgsQTUayaAYBLWYaV/BGbltI7f5BYwnc0TDSzWIZHwd06sF43rNPOW 6 | yfsdIV24MF5mOKG4FztwufME0yIZmkoMILCZvNj5XpyXCYRIsDwdMzd9YcTpqa5Q 7 | lBU88MNHf+OFVIowAGRMGYeg5lEt6WXSS3DOhLFfdfY/A3Gseb8QLfz+ctYQrXC2 8 | tRFiN8qf/+VZ0M+auo1eK7VUSqRsf/tQLl01CBM68++SAQzTNczVaftfzHWLavj7 9 | QyNfAeVWPLfUIhZcZxFT5Y7zcvhkl7Jtts0hSBIGw0ceGYh1rBNcLT+pYWIZv9Nl 10 | CVhov4d1O6DM4ufOvXem4ywaUd+f15rkqaMHVa3ltQ+pveXgveoJZO2Zl2z4MctS 11 | olJZmU5PdFSxrajQfze4W0aBB7lF49JpmFow5ZE5xek5A+B//+cCYYbIT4GG8ep2 12 | 6HIiapH2IOgQBxtRYYtWd8FUWpR+GwshxNUvD63d2CJvYxigMP95uD40bZg1SGjp 13 | up7yqM6s9F66bEpp71Zl5rVo4+eA1u5aQ4E684QT5DWao6bf7UKiP3gFR1iK4AJi 14 | WXpQNMh39TpETb8BYcHNs6QyP0Wy04g8OKJqjJy6HgIWiwc/6qVuYl6o22+mjenH 15 | phAEFIOxTSBtPjfldkkCWQ48seDxJQIZ1jSf9c2X/e323PvSohhqjZchr751nRxk 16 | x+sU/91SDpYw/97vQDYgjOFGPXkf1s+cnaZ1wh68UNxJI3Keqsg65lyvdX4o8/Ho 17 | 0dl8V8SVZbbvYDnS3MuMoL+xXNhPj2lkALDGqvLVjwemiPSg8TBgHA== 18 | -----END RSA PRIVATE KEY----- 19 | -------------------------------------------------------------------------------- /test/https/test.js: -------------------------------------------------------------------------------- 1 | module.exports = function(port, file, cb, inject){ 2 | port = port || process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || process.argv[2] || 8765; 3 | 4 | var fs = require('fs'); 5 | var Gun = require(__dirname+'/../../'); 6 | 7 | var server = require('https').createServer({ 8 | key: fs.readFileSync(__dirname+'/server.key'), 9 | cert: fs.readFileSync(__dirname+'/server.crt'), 10 | ca: fs.readFileSync(__dirname+'/ca.crt'), 11 | requestCert: true, 12 | rejectUnauthorized: false 13 | },function(req, res){ 14 | if(Gun.serve(req, res)){ return } // filters gun requests! 15 | var file; 16 | try{file = require('fs').readFileSync(require('path').join(__dirname+'/../../examples', req.url)) 17 | }catch(e){ file = require('fs').readFileSync(require('path').join(__dirname+'/../../examples', 'index.html')) } 18 | if(inject){ 19 | file = inject(file, req, res) || file; 20 | } 21 | res.end(file); 22 | }); 23 | 24 | var gun = Gun({ 25 | file: file || 'data', 26 | web: server, 27 | localStorage: false 28 | }); 29 | 30 | server.listen(port, cb); 31 | 32 | console.log('Server started on port ' + port + ' with /gun'); 33 | } -------------------------------------------------------------------------------- /test/hub/.hubignore: -------------------------------------------------------------------------------- 1 | /whatever/aws-key.txt -------------------------------------------------------------------------------- /test/hub/hub-test.js: -------------------------------------------------------------------------------- 1 | const Gun = require('../..'); 2 | const gun = Gun(); 3 | 4 | gun.get('hub').on(data => { 5 | console.log(data) 6 | }) 7 | 8 | const hub = require('../../lib/hub'); 9 | hub.watch(__dirname, {msg: true, hubignore: true, alias:require('os').userInfo().username}) -------------------------------------------------------------------------------- /test/hub/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 |
      Hi!
      11 | 12 | -------------------------------------------------------------------------------- /test/hub/whatever/aws-key.txt: -------------------------------------------------------------------------------- 1 | I'M A SUPER SECRET KEY WHICH SHALL NOT BE LEAKED 2 | FOR YOUR OWN SAKE. -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | // Let's do all old-fashion require stuff before '@std/mjs' steps in... 4 | const Gun = require('../gun') 5 | 6 | if (process.env.SEA) { 7 | Gun.SEA = require('../sea') 8 | } 9 | require('../lib/file') 10 | 11 | const myDir = __dirname // TODO: where did __dirname go ? 12 | 13 | // From here on we're ES6 import compatible... 14 | require = require('@std/esm')(module) // eslint-disable-line no-global-assign 15 | 16 | module.exports = require('../lib/server.mjs').default(Gun, myDir) 17 | 18 | */ -------------------------------------------------------------------------------- /test/old/interface.js: -------------------------------------------------------------------------------- 1 | module.exports=require('theory') 2 | ('interface',function(a){ 3 | return ":)"; 4 | },['../deps/discrete','../deps/key/key']); 5 | root.opts.key = {host:'/deps'}; -------------------------------------------------------------------------------- /test/old/server.js: -------------------------------------------------------------------------------- 1 | module.exports=require('theory') 2 | ({name: 'echo' 3 | , state: {way:'state', flow:-1} 4 | , invincible: true 5 | , dep: ['../shots'] 6 | , init: function(a){ 7 | var echo = {}, redis, client; 8 | echo.shot = a.shots(); 9 | echo.put = function(m){ 10 | console.log('stream', m); 11 | } 12 | echo.state = function(m){ 13 | if(echo.shot.server(m,a.com.reply)){ return } 14 | m.what.body = 'module.exports = {boo: "yay"};'; 15 | m.what.type = 'js'; 16 | a.com.reply(m); 17 | }; 18 | /*echo.shot.stream.on(function(m){ 19 | console.log('stream on!', m); 20 | });*/ 21 | return echo; 22 | }}); -------------------------------------------------------------------------------- /test/old/set.js: -------------------------------------------------------------------------------- 1 | (function(){ return; 2 | var Gun = require('../gun'); 3 | var done = function(){}; 4 | 5 | var gun = Gun().get('set').set(), i = 0; 6 | gun.val(function(val){ 7 | console.log('t1', val); 8 | }).set(1).set(2).set(3).set(4) // if you set an object you'd have to do a `.back` 9 | .map().val(function(val){ // TODO! BUG? If we do gun.set it immediately calls and we get stale data. Is this wrong? 10 | console.log('t2', val, ++i); 11 | if(4 === i){ 12 | console.log("TODO? BUG! Double soul?", gun.__.graph); 13 | done() 14 | } 15 | }); 16 | 17 | return; // TODO! BUG! Causes tests to crash and burn badly. 18 | 19 | require('../lib/set'); 20 | var gun = Gun(); 21 | 22 | var list = gun.get('thoughts'); 23 | list.set('a'); 24 | list.set('b'); 25 | list.set('c'); 26 | list.set('d').val(function(val){ 27 | console.log('what', val, '\n\n'); 28 | console.log(gun.__.graph); 29 | }) 30 | return; 31 | gun.set({ 32 | name: "Mark Nadal", 33 | age: 23, 34 | type: "human" 35 | }).back.set({ 36 | name: "Timber Nadal", 37 | age: 3, 38 | type: "cat" 39 | }).back.set({ 40 | name: "Hobbes", 41 | age: 4, 42 | type: "kitten" 43 | }).back.val(function(g){ 44 | console.log("GOT", g, this.__.graph); 45 | }).map(function(val, id){ 46 | console.log("map", id, val); 47 | }); 48 | 49 | }()); -------------------------------------------------------------------------------- /test/old/shoot.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amark/gun/4b43fa7f2c085a866551ee36372daed10316354c/test/old/shoot.html -------------------------------------------------------------------------------- /test/old/shotgun.js: -------------------------------------------------------------------------------- 1 | var keys; 2 | if(process.env.LIVE || (process.env.NODE_ENV === 'production')){ 3 | // Keys are provided by environment configs on the server 4 | } else { 5 | // Keys are hosted outside this public repo folder, you must provide your own with environment variables. 6 | if((require('fs').existsSync||require('path').existsSync)(keys = __dirname + '/../../../linux/.ssh/keys-gun.js')){ 7 | keys = require(keys); 8 | } 9 | } 10 | 11 | keys = keys || {}; 12 | keys.bucket = keys.bucket || 'gunjs.herokuapp.com'; 13 | 14 | module.exports = keys || {}; -------------------------------------------------------------------------------- /test/old/timelines.txt: -------------------------------------------------------------------------------- 1 | Earth Mars 2 | thing = {} 3 | thing = {} 4 | 5 | 6 | thing.a = 'hello' 7 | 8 | thing.z = 'cool' 9 | 10 | 11 | ----> thing 12 | ----> thing.z = 'cool' 13 | thing = {a: 'hello', z: 'cool'} 14 | thing = {z: 'cool'} <---- 15 | thing.a = 'hello' <---- 16 | thing = {a: 'hello', z: 'cool'} 17 | 18 | ------------------------------------------------------------------------------------ 19 | Earth Mars 20 | thing = 5 thing = 5 21 | 22 | thing = {a: 'yay'} 23 | 24 | thing = {b: 'cool'} 25 | 26 | 27 | 22 -> thing = {a: 'yay', b: 'cool'} 28 | 29 | thing = {a: 'yay', b:'cool'} <- 24 30 | ------------------------------------------------------------------------------------ 31 | Earth Mars 32 | thing = 5 thing = 5 33 | 34 | thing = {a: 'yay'} 35 | 36 | thing = {b: 'cool'} 37 | thing = 9 38 | thing = {z: 1} 39 | thing.j = 'how?' 40 | 41 | thing.k = 'lol' 42 | thing = {z: 1, j: 'how?'} <- 36 43 | thing = {z: 1, j: 'how?', k: 'lol'} <- 41 // wrong! need to send thing when also 44 | 45 | thing.c = 20 46 | 34 -> thing = {a: 'yay', b: 'cool'} 47 | 38 -> thing = 9 48 | 39 -> thing = {z:1} 49 | 40 -> thing = {j: 'how?', z: 1} 50 | thing = {z: 1, j: 'how?'} <- 45 -------------------------------------------------------------------------------- /test/panic.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | 13 | 14 | -------------------------------------------------------------------------------- /test/panic/axe/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |

      Running AXE Tests

      10 |
      Name:
      11 |
      PID:
      12 |
      13 | 14 | -------------------------------------------------------------------------------- /test/panic/e2e/holy/gun-server.js: -------------------------------------------------------------------------------- 1 | var panic = require('panic-client'); 2 | var ports = require('./ports'); 3 | var Gun = require('gun'); 4 | var gun = new Gun({ 5 | file: 'delete-me.json' 6 | }); 7 | 8 | var http = require('http'); 9 | 10 | var server = new http.Server(gun.wsp.server); 11 | 12 | gun.wsp(server); 13 | 14 | server.listen(ports.gun); 15 | 16 | panic.server('http://localhost:' + ports.panic); -------------------------------------------------------------------------------- /test/panic/e2e/holy/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Holy grail demo 7 | 8 | 9 | 10 | 11 | 12 | 26 | 27 | -------------------------------------------------------------------------------- /test/panic/e2e/holy/ports.json: -------------------------------------------------------------------------------- 1 | { 2 | "panic": 3000, 3 | "gun": 8765 4 | } -------------------------------------------------------------------------------- /test/panic/e2e/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gun-tests-e2e", 3 | "version": "0.0.0", 4 | "description": "End to end tests for gun", 5 | "private": true, 6 | "main": "distributed.js", 7 | "devDependencies": { 8 | "panic-server": ">1.1.0", 9 | "selenium-webdriver": ">3.3.0" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/panic/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

      Running Tests.

      6 |
      7 | -------------------------------------------------------------------------------- /test/panic/infinite-scroll/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Infinite scroll example 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
      15 |
      16 | 17 | 18 |
      19 |
      20 | 21 |
      22 |
      23 | 24 |
      25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /test/panic/util/load-browser-scripts.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | /** 3 | * Loads scripts in PANIC clients 4 | * @param browsers a Panic.ClientList of browsers 5 | * @param paths an array of paths to desired .js files 6 | * @returns Promise which will resolve when all browsers have loaded all dependencies 7 | */ 8 | loadBrowserScripts: function (browsers, paths) { 9 | var promises = []; 10 | browsers.each(function (client, id) { 11 | promises.push(client.run(function (test) { 12 | test.async(); 13 | var env = test.props; 14 | var imports = env.paths || []; 15 | /** Loads a single script in the browser */ 16 | function load(src, cb) { 17 | var script = document.createElement('script'); 18 | script.onload = cb; script.src = src; 19 | document.head.appendChild(script); 20 | } 21 | /** Loads scripts in order, waiting on each to load before proceeding */ 22 | function loadAll(src, cb) { 23 | if (src.length === 0) { 24 | cb(); 25 | return; 26 | } 27 | var cur = src.shift(); 28 | // console.log('loading library:', cur); 29 | load(cur, function () { 30 | loadAll(src, cb); 31 | }); 32 | } 33 | 34 | loadAll(imports, function () { 35 | test.done(); 36 | }); 37 | }, {paths: paths})); 38 | }); 39 | return Promise.all(promises); 40 | } 41 | }; -------------------------------------------------------------------------------- /test/panic/util/open.js: -------------------------------------------------------------------------------- 1 | let _browsers = []; 2 | 3 | module.exports = { 4 | web: (count, url, options) => { 5 | if (typeof count === 'string') { 6 | options = url; 7 | url = count; 8 | count = 1; 9 | } 10 | if (!url || typeof url !== 'string') { 11 | throw new Error('Invalid URL'); 12 | } 13 | try { 14 | require('puppeteer').launch(options).then(browser => { 15 | _browsers.push(browser); 16 | Array(count).fill(0).forEach((x, i) => { 17 | console.log('Opening browser page ' + i + ' with puppeteer...'); 18 | browser.newPage().then(page => { 19 | page.on('console', msg => { 20 | if (msg.text() === 'JSHandle@object') { 21 | // FIXME: Avoid text comparison 22 | return; 23 | } 24 | console.log(`${i} [${msg.type()}]: ${msg.text()}`); 25 | }); 26 | return page.goto(url); 27 | }).then(() => { 28 | console.log('Browser page ' + i + ' open'); 29 | }); 30 | }); 31 | }); 32 | } catch (err) { 33 | console.log("PLEASE OPEN "+ url +" IN "+ count +" BROWSER(S)!"); 34 | console.warn('Consider installing puppeteer to automate browser management (npm i -g puppeteer && npm link puppeteer)'); 35 | } 36 | }, 37 | cleanup: () => { 38 | if (_browsers.length === 0) { 39 | return undefined; 40 | } 41 | console.log('Closing all puppeteer browsers...'); 42 | return Promise.all(_browsers.map(b => b.close())) 43 | .then(() => console.log('Closed all puppeteer browsers')); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /test/ptsd/memdisk.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /test/ptsd/memdisk.js: -------------------------------------------------------------------------------- 1 | var Gun = require('../../gun'); 2 | require('../../lib/memdisk'); 3 | //require('../../lib/file'); 4 | 5 | var gun = Gun(); 6 | var TOTAL = 10000000; 7 | var c = 1000, big = "big"; 8 | while(--c){big += "big"} 9 | c = 0; 10 | 11 | var to = setInterval(function(){ 12 | if(TOTAL < c){ return clearTimeout(to) } 13 | var i = 100; 14 | while(--i){ 15 | it(i); 16 | } 17 | },2); 18 | 19 | function it(i){ 20 | c++; 21 | var key = Gun.text.random(5); 22 | gun.get(key).put({data: Math.random() + big + Math.random()}); 23 | setTimeout(function(){ 24 | gun.get(key).off(); 25 | },5); 26 | if(c % 5000){ return } 27 | if(typeof process === 'undefined'){ return } 28 | //try{global.gc()}catch(e){console.log(e)} 29 | var mem = process.memoryUsage(); 30 | console.log(((mem.heapUsed / mem.heapTotal) * 100).toFixed(0) + '% memory with', Object.keys(gun._.graph).length, 'memory nodes, put', c); 31 | } -------------------------------------------------------------------------------- /test/ptsd/ptsd.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | PTSD 4 | 5 | 6 | 7 | 8 |
      9 |

      PTSD

      10 |
      11 |

      Setup code

      12 | 13 | 14 |
      15 |
      16 |

      Test cases

      17 | 18 | 19 | 20 | 21 | 22 | 23 |
      CaseResult
      24 | + Add test case 25 |
      26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /test/ptsd/radix.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | PTSD 4 | 5 | 6 | 7 | 8 |
      9 |

      PTSD

      10 |
      11 |

      Setup code

      12 | 13 | 14 |
      15 |
      16 |

      Test cases

      17 | 18 | 19 | 20 | 21 | 22 | 23 |
      CaseResult
      24 | + Add test case 25 |
      26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /test/ptsd/spam.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | window.SPAM = function(cb, opt){ 3 | opt = Gun.num.is(opt)? {each: opt} : opt || {}; 4 | opt.wait = opt.wait || 1; 5 | setInterval(burst, opt.wait); 6 | 7 | var n = Gun.time.is(), i = 0, c = 0, b = opt.burst || 10, l = opt.each || 100; 8 | var r = Gun.text.random, raw; 9 | 10 | function save(i){ 11 | if(!window.SPAM){ return } 12 | if(i > l){ 13 | return clearTimeout(t); 14 | } 15 | cb(i, i + raw + i); 16 | } 17 | function burst(){ 18 | raw = r(1000000); 19 | for(var j = 0; j <= b; j++){ 20 | save(++i); 21 | } 22 | } 23 | var t; 24 | } 25 | }()); 26 | 27 | var gun = Gun({localStorage: false, peers: 'http://localhost:8765/gun'}); 28 | var g = gun.get('test'); 29 | var room = Gun.text.random(100); 30 | var pub = Gun.text.random(1000); 31 | SPAM(function(i, v){ 32 | //console.log(Gun.state(), i);return; 33 | console.log(i); 34 | var ref = g.set({ 35 | a: v, 36 | b: i, 37 | c: room, 38 | d: pub 39 | }, function(ack){ 40 | ref.off(); 41 | }); 42 | }, 99999999999999); 43 | 44 | /* 45 | ;(function(){ 46 | $("#say").on('submit', function(){ 47 | setTimeout(function(){ 48 | $("#say").find('input').first().val(Gun.text.random(1000)); 49 | },1); 50 | }); 51 | }); 52 | */ -------------------------------------------------------------------------------- /test/ptsd/stool.css: -------------------------------------------------------------------------------- 1 | body { 2 | width: 90%; 3 | max-width: 800px; 4 | margin: 4em auto; 5 | font: 12pt Helvetia, Arial, sans-serif; 6 | } 7 | 8 | section { 9 | margin: 0 0 4em; 10 | } 11 | 12 | table { 13 | border-spacing: 0; 14 | width: 100%; 15 | } 16 | 17 | th, td { 18 | vertical-align: top; 19 | padding: 0 0 1em 0; 20 | } 21 | 22 | th { 23 | text-align: left; 24 | } 25 | 26 | th.th-result { 27 | width: 200px; 28 | } 29 | 30 | th.th-remove { 31 | width: 0; 32 | } 33 | 34 | td.inputs { 35 | padding-right: 1em; 36 | } 37 | 38 | .remove { 39 | position: absolute; 40 | margin-left: -6em; 41 | width: 5em; 42 | } 43 | 44 | input, textarea { 45 | margin: 0 0 1em 0; 46 | width: 100%; 47 | display: block; 48 | resize: vertical; 49 | } 50 | 51 | .result.running { 52 | color: #ccc; 53 | } 54 | 55 | #abort { 56 | display: none; 57 | } 58 | .running #abort { 59 | display: initial; 60 | } 61 | 62 | .running #run { 63 | display: none; 64 | } -------------------------------------------------------------------------------- /test/rad/2020and2021.js: -------------------------------------------------------------------------------- 1 | var Gun = require('../../index'); 2 | 3 | var gun = Gun({file: __dirname+'/old2020json'}); 4 | 5 | gun.get('test').once(function(data, key){ 6 | console.log(key, data); 7 | if(!data){ throw "not compatible!" } 8 | }); -------------------------------------------------------------------------------- /test/rad/book.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
        4 |
        5 | 6 | 7 | 8 |
        9 | 10 | -------------------------------------------------------------------------------- /test/rad/browser.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

        RindexedDB

        4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
        17 |
        18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /test/rad/mocha.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Gun Tests 4 | 5 | 7 | 8 | 9 | 10 | Gun Tests 11 |
        12 |
        13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 52 | 53 | -------------------------------------------------------------------------------- /test/rad/old2020json/%1C: -------------------------------------------------------------------------------- 1 | {"!":{"":1}} -------------------------------------------------------------------------------- /test/rad/parse.rad: -------------------------------------------------------------------------------- 1 | +1#"age:"+29>+1549776205172 2 | +1#"name:""Bob!>+1549776205172 3 | +1#"pet:"#XAqxAKkRa6lTsfAElEjDweqt>+1549776205172 4 | +0#"u/m 5 | +1#" 6 | +2#"alice:"#dlgw87rue6oVQhsvc3XFLrOu>+1549776205172 7 | +2#"bob:"#nuTAd2Tn4S5SiDVA7nxNBbZt>+1549776205172 8 | +1#"/p 9 | +2#"alice:"#USw3Dp7hTD7VMBLnd8dVBR4s>+1549776205200 10 | +2#"bob:"#1VwZRUw7vQ1hX8gspN1ZrHVj>+1549776205200 11 | -------------------------------------------------------------------------------- /test/radix.js: -------------------------------------------------------------------------------- 1 | var expect = global.expect = require("./expect"); 2 | 3 | var Radix = require('../lib/radix'); 4 | var _ = String.fromCharCode(29); 5 | 6 | describe('Radix', function(){ // moved to ./rad/rad.js 7 | it('read', function(){ 8 | var rad = Radix(); 9 | rad('asdf.pub', 'yum'); 10 | rad('ablah', 'cool'); 11 | rad('node/circle.bob', 'awesome'); 12 | 13 | expect(rad('asdf.')).to.be.eql({pub: {'': 'yum'}}); 14 | expect(rad('nv/foo.bar')).to.be(undefined); 15 | }); 16 | }); -------------------------------------------------------------------------------- /test/sea/sea-tmp.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /test/sea/sea.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /test/server/http.js: -------------------------------------------------------------------------------- 1 | //client.js writes data up to a listening hub.js, which relays to a server.js that reads the data. 2 | 3 | var http = require('http'); 4 | 5 | var Gun = require('../../index'); 6 | var gun = Gun({ 7 | file: 'http.json' 8 | }); 9 | 10 | 11 | var server = http.createServer(function(req, res){}); 12 | gun.wsp(server); 13 | server.listen(8765); 14 | 15 | console.log('Server started on port ' + 8765 + ' with /gun'); -------------------------------------------------------------------------------- /test/server/node-client.js: -------------------------------------------------------------------------------- 1 | var Gun = require('../../index'); 2 | 3 | var location = {host:"localhost"}; 4 | 5 | var gun = Gun( { file: 'read.json', peers: ['http://' + location.host + ':8765/gun'] }); 6 | 7 | gun.get( 'data' ).path('stuff').map(function(val,field){ console.log( field, "=", val ); } ); 8 | 9 | console.log( "done... wait forever?" ); -------------------------------------------------------------------------------- /test/server/node-write.js: -------------------------------------------------------------------------------- 1 | var Gun = require('../../index'); 2 | 3 | var location = {host:"localhost"}; 4 | 5 | var gun = Gun( { file: 'write.json', peers: ['http://' + location.host + ':8765/gun'] }); 6 | 7 | gun.get( 'data' ).path('stuff').put({a: {data: 1}, b: {data: 2}}); -------------------------------------------------------------------------------- /test/tmp/bigsync.js: -------------------------------------------------------------------------------- 1 | var Gun = require('../../'); 2 | 3 | /*var data = ''; 4 | var a = [], b = Gun.text.random(1000 * 1000 * 10), c; 5 | for(var i = 0; i <= 7; i++){ 6 | data += b; 7 | } 8 | */ 9 | data = 1; 10 | 11 | var gun = Gun('http://localhost:8765/gun'); 12 | //var gun = Gun(); 13 | 14 | setTimeout(function(){ 15 | 16 | /*console.log("READ!"); 17 | gun.get('bigsync').get('raw').on(function(a,b){ 18 | console.log('yay!', b, (a && a.slice && a.slice(0,20)) || a, a.length); 19 | }); 20 | return;*/ 21 | console.log("SEND!"); 22 | gun.get('bigsync').get('raw').put(data, function(ack){console.log(ack)}); 23 | 24 | /*var req = require('http').request({ 25 | host: 'localhost' 26 | ,port: '8080' 27 | ,method: 'POST' 28 | }, function(res){ 29 | console.log("GOT REPLY!", res); 30 | res.on('data', function(chunk){ 31 | console.log("!!!", chunk); 32 | }); 33 | res.on('error', function(err){ 34 | console.log("ERROR", err); 35 | }) 36 | }); 37 | req.write(data); 38 | req.end();*/ 39 | }, 1000); -------------------------------------------------------------------------------- /test/tmp/indexedDB.html: -------------------------------------------------------------------------------- 1 |

        RindexedDB

        2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 18 | -------------------------------------------------------------------------------- /test/tmp/mitra/client_to_server.js: -------------------------------------------------------------------------------- 1 | process.env.GUN_ENV = "false"; 2 | var Gun=require('gun') 3 | var g = new Gun({peers: ['http://localhost:4246/gun'],localStorage: false}); 4 | g.get("FOOxx").get("BARxx").once(data=>console.log("RCVD: (SHOULD NOT BE UNDEFINED!)", data)); 5 | 6 | console.log('now run ```var g = new Gun({peers: ["http://localhost:4246/gun"],localStorage: false}); g.get("FOOxx").get("BARxx").once(data=>console.log("RCVD:", data))```'); -------------------------------------------------------------------------------- /test/tmp/seanode.js: -------------------------------------------------------------------------------- 1 | var Gun = require('../../gun.js'); 2 | require('../../sea.js'); 3 | 4 | var pub = "tgEJ8TTeTN8Xi0D3oMVbZGyVVFDGT4AUoqyrUguAguU.9-yZfWtPSZ_4ILnttWy-KWvwUUyO2-dB1DHRYud-CDE"; 5 | 6 | var sig = decodeURIComponent("SEA%7B%22m%22%3A%22%5C%22hello%5C%22%22%2C%22s%22%3A%22%C2%90%C3%B1%C3%93sy%5Cu0011%C3%87%C2%A5%C2%97%C3%93%5Cu0011%C3%A1JV%C2%AA%C3%94C%C3%A3%C3%85%C2%80a%5Cu0006%C2%B6%C2%A7%C3%BE%C2%9F%C2%92%5Cu000eS%C2%90%C3%A8%C3%B1kH%7D%C2%9A%5Cb%C3%B0g%C2%B9%7F%C2%B2%C3%9F%C3%A0j%C3%9Bk%5C%22%3E%C2%B6%C2%8F%5Cu001b%C3%81%C2%8B%C2%97%C3%92%C2%AA%C3%A5%C2%B6%5D%C3%85%C2%9A%3BA%22%7D"); 7 | 8 | console.log(sig); 9 | 10 | ;(async function(){ 11 | var test = await Gun.SEA.verify(sig, pub); 12 | console.log("???", test); 13 | }()); -------------------------------------------------------------------------------- /test/tmp/space.html: -------------------------------------------------------------------------------- 1 |

        Search

        2 | 3 |
        4 | 5 |
        6 | 7 |
        8 |
          9 | 10 | Note: No data is indexed by default, you need to add some! 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "emitDeclarationOnly": true, 4 | "declaration": true, 5 | }, 6 | "include": [ 7 | // only compile the type definitions by default. 8 | // That is, ignore the files in 'examples/**' 9 | "**/*.d.ts" 10 | ], 11 | "exclude": [ 12 | // Among the type definitions, don't try to compile 13 | // the test file which implements bad types. 14 | // It implements bad types for testing purposes. 15 | "**/*.test-d.ts" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /types/gun/GunCallbackGet.d.ts: -------------------------------------------------------------------------------- 1 | import { GunDataNode, GunSchema, GunSoul } from '.'; 2 | import { GunSoul2Soul } from '../utils'; 3 | 4 | type GunMessageGet< 5 | N extends GunSchema, 6 | K extends (keyof N & string) | GunSoul2Soul>, 7 | V = K extends keyof N & string ? N[K] : N 8 | > = { 9 | /** key */ 10 | get: K; 11 | /** value */ 12 | put: GunDataNode; 13 | }; 14 | 15 | export type GunCallbackGet< 16 | N extends GunSchema, 17 | K extends (keyof N & string) | GunSoul2Soul> 18 | > = (ack: GunMessageGet) => void; 19 | -------------------------------------------------------------------------------- /types/gun/GunCallbackMap.d.ts: -------------------------------------------------------------------------------- 1 | import { GunDataNode, GunSchema } from '.'; 2 | 3 | export type GunCallbackMap< 4 | V extends N[K], 5 | K extends keyof N & string, 6 | N extends GunSchema 7 | > = (data: GunDataNode, key: K) => any; 8 | -------------------------------------------------------------------------------- /types/gun/GunCallbackOn.d.ts: -------------------------------------------------------------------------------- 1 | import { GunDataNode, GunHookMessagePut, IGunOnEvent, GunSchema } from '.'; 2 | 3 | export type GunCallbackOn = ( 4 | data: GunDataNode, 5 | key: K, 6 | message: GunHookMessagePut, 7 | event: IGunOnEvent 8 | ) => void; 9 | -------------------------------------------------------------------------------- /types/gun/GunCallbackOnce.d.ts: -------------------------------------------------------------------------------- 1 | import { GunDataNode, GunSchema } from '.'; 2 | 3 | export type GunCallbackOnce = ( 4 | data: GunDataNode, 5 | key: K 6 | ) => void; 7 | -------------------------------------------------------------------------------- /types/gun/GunCallbackPut.d.ts: -------------------------------------------------------------------------------- 1 | export type GunMessagePut = 2 | | { 3 | /** if there was an error during save */ 4 | err: string; 5 | } 6 | | { 7 | /** if there was a success message (none is required though) */ 8 | ok: { '': 1 }; 9 | }; 10 | 11 | export type GunCallbackPut = (ack: GunMessagePut) => void; 12 | -------------------------------------------------------------------------------- /types/gun/GunDataNode.d.ts: -------------------------------------------------------------------------------- 1 | import { GunSchema, GunSoul, IGunMeta } from '.'; 2 | 3 | export type GunDataNode = T extends GunSchema & object 4 | ? { 5 | [K in keyof T]: Exclude< 6 | T[K], 7 | string | number | boolean | null | undefined 8 | > extends never 9 | ? T[K] 10 | : 11 | | GunSoul< 12 | Exclude 13 | > 14 | | Exclude; 15 | } & IGunMeta 16 | : T; 17 | -------------------------------------------------------------------------------- /types/gun/GunHookCallbackBye.d.ts: -------------------------------------------------------------------------------- 1 | import { IGunHookContext, GunPeer } from '.'; 2 | 3 | export type GunHookCallbackBye = ( 4 | this: IGunHookContext, 5 | peer: GunPeer 6 | ) => void; 7 | -------------------------------------------------------------------------------- /types/gun/GunHookCallbackCreate.d.ts: -------------------------------------------------------------------------------- 1 | import { IGunHookContext, _GunRoot } from '.'; 2 | 3 | export type GunHookCallbackCreate = ( 4 | this: IGunHookContext<_GunRoot>, 5 | root: _GunRoot 6 | ) => void; 7 | -------------------------------------------------------------------------------- /types/gun/GunHookCallbackGet.d.ts: -------------------------------------------------------------------------------- 1 | import { pany, IGunHookContext, GunNodeGet, _GunRoot } from '.'; 2 | 3 | type GunHookMessageGet = { 4 | $: { _: _GunRoot }; 5 | '#': string; 6 | get: GunNodeGet; 7 | } & Partial; 8 | 9 | export type GunHookCallackGet = ( 10 | this: IGunHookContext>, 11 | message: GunHookMessageGet 12 | ) => void; 13 | -------------------------------------------------------------------------------- /types/gun/GunHookCallbackHi.d.ts: -------------------------------------------------------------------------------- 1 | import { IGunHookContext, GunPeer } from '.'; 2 | 3 | export type GunHookCallbackHi = ( 4 | this: IGunHookContext, 5 | peer: GunPeer 6 | ) => void; 7 | -------------------------------------------------------------------------------- /types/gun/GunHookCallbackIn.d.ts: -------------------------------------------------------------------------------- 1 | import { pany, IGunHookContext, GunDataNode, GunNodeGet, _GunRoot } from '.'; 2 | 3 | export type GunHookMessageIn< 4 | MessageExtension extends pany, 5 | MetaExtension extends pany 6 | > = { 7 | $: { _: _GunRoot }; 8 | '#': string; 9 | get?: GunNodeGet; 10 | put?: { [nodePath: string]: GunDataNode & { _: MetaExtension } }; 11 | } & Partial; 12 | 13 | export type GunHookCallbackIn< 14 | MessageExtension extends pany, 15 | MetaExtension extends pany 16 | > = ( 17 | this: IGunHookContext>, 18 | message: GunHookMessageIn 19 | ) => void; 20 | -------------------------------------------------------------------------------- /types/gun/GunHookCallbackOpt.d.ts: -------------------------------------------------------------------------------- 1 | import { IGunHookContext, _GunRoot } from '.'; 2 | 3 | export type GunHookCallbackOpt = (this: IGunHookContext<_GunRoot>, root: _GunRoot) => void; 4 | -------------------------------------------------------------------------------- /types/gun/GunHookCallbackOut.d.ts: -------------------------------------------------------------------------------- 1 | import { IGunHookContext, pany, GunDataNode, GunNodeGet, _GunRoot } from '.'; 2 | 3 | export type GunHookMessageOut< 4 | MessageExtension extends pany, 5 | MetaExtension extends pany 6 | > = { 7 | $: { _: _GunRoot }; 8 | '#': string; 9 | get?: GunNodeGet; 10 | put?: { [nodePath: string]: GunDataNode & { _: MetaExtension } }; 11 | } & Partial; 12 | 13 | export type GunHookCallbackOut< 14 | MessageExtension extends pany, 15 | MetaExtension extends pany 16 | > = ( 17 | this: IGunHookContext>, 18 | message: GunHookMessageOut 19 | ) => void; 20 | -------------------------------------------------------------------------------- /types/gun/GunHookCallbackPut.d.ts: -------------------------------------------------------------------------------- 1 | import { GunNodePut, IGunHookContext, _GunRoot } from '.'; 2 | 3 | type GunHookMessagePut = { 4 | $: { _: _GunRoot }; 5 | '#'?: string; 6 | put: GunNodePut; 7 | }; 8 | 9 | export type GunHookCallbackPut = ( 10 | this: IGunHookContext, 11 | message: GunHookMessagePut 12 | ) => void; 13 | -------------------------------------------------------------------------------- /types/gun/GunNodeGet.d.ts: -------------------------------------------------------------------------------- 1 | export type GunNodeGet = { 2 | /** Node path */ 3 | '#': string; 4 | /** Leaf name */ 5 | '.': string; 6 | }; 7 | -------------------------------------------------------------------------------- /types/gun/GunNodePut.d.ts: -------------------------------------------------------------------------------- 1 | import { GunNodeGet, GunValueSimple } from '.'; 2 | 3 | export type GunNodePut = GunNodeGet & { 4 | /** Leaf value */ 5 | ':': GunValueSimple; 6 | /** Leaf timestamp */ 7 | '>': number; 8 | }; 9 | -------------------------------------------------------------------------------- /types/gun/GunOptions.d.ts: -------------------------------------------------------------------------------- 1 | export type GunOptions = 2 | | Partial<{ 3 | /** Undocumented but mentioned. Write data to a JSON. */ 4 | file: string; 5 | 6 | /** Undocumented but mentioned. Create a websocket server */ 7 | web: any; 8 | 9 | /** Undocumented but mentioned. Amazon S3 */ 10 | s3: { 11 | key: string; 12 | secret: string; 13 | bucket: string; 14 | region?: string; 15 | fakes3?: any; 16 | }; 17 | 18 | /** the URLs are properties, and the value is an empty object. */ 19 | peers: string[] | Record; 20 | 21 | /** default: true, creates and persists local (nodejs) data using Radisk. */ 22 | radisk: boolean; 23 | 24 | /** default: true, persists local (browser) data to localStorage. */ 25 | localStorage: boolean; 26 | 27 | /** uuid allows you to override the default 24 random alphanumeric soul generator with your own function. */ 28 | uuid(): string; 29 | 30 | /** 31 | * allows you to pass options to a 3rd party module. Their project README will likely list the exposed options 32 | * @see https://github.com/amark/gun/wiki/Modules 33 | */ 34 | [key: string]: any; 35 | }> 36 | | string 37 | | string[]; 38 | -------------------------------------------------------------------------------- /types/gun/GunOptionsOn.d.ts: -------------------------------------------------------------------------------- 1 | export type GunOptionsOn = Partial< 2 | | { 3 | change: boolean; 4 | } 5 | | boolean 6 | >; 7 | -------------------------------------------------------------------------------- /types/gun/GunOptionsOnce.d.ts: -------------------------------------------------------------------------------- 1 | export type GunOptionsOnce = Partial<{ 2 | /** 3 | * controls the asynchronous timing 4 | */ 5 | wait: number; 6 | }>; 7 | -------------------------------------------------------------------------------- /types/gun/GunOptionsPut.d.ts: -------------------------------------------------------------------------------- 1 | export type GunOptionsPut = Partial<{ 2 | opt: { 3 | /** certificate that gives other people write permission */ cert: string; 4 | }; 5 | }>; 6 | -------------------------------------------------------------------------------- /types/gun/GunPeer.d.ts: -------------------------------------------------------------------------------- 1 | export type GunPeer = { 2 | id: string; 3 | url: string; 4 | queue: string[]; 5 | wire: null | WebSocket | RTCDataChannel; 6 | }; 7 | -------------------------------------------------------------------------------- /types/gun/GunSchema.d.ts: -------------------------------------------------------------------------------- 1 | import { GunValueSimple, IGunChain, IGunInstanceRoot } from '.'; 2 | 3 | interface IGunSchema { 4 | [key: string]: 5 | | Exclude< 6 | IGunSchema, 7 | IGunChain | IGunInstanceRoot 8 | > 9 | | GunValueSimple; 10 | } 11 | 12 | export type GunSchema = 13 | | Exclude< 14 | IGunSchema, 15 | IGunChain | IGunInstanceRoot 16 | > 17 | | GunValueSimple; 18 | -------------------------------------------------------------------------------- /types/gun/GunSoul.d.ts: -------------------------------------------------------------------------------- 1 | import { GunSchema } from '.'; 2 | export type GunSoul<_N extends GunSchema, Soul extends string = string> = { 3 | '#': Soul; 4 | }; 5 | -------------------------------------------------------------------------------- /types/gun/GunValueSimple.d.ts: -------------------------------------------------------------------------------- 1 | export type GunValueSimple = string | number | boolean | null; 2 | -------------------------------------------------------------------------------- /types/gun/IGun.d.ts: -------------------------------------------------------------------------------- 1 | import { 2 | GunOptions, 3 | IGunInstance, 4 | _GunRoot, 5 | GunHookCallbackCreate, 6 | GunHookCallbackOpt, 7 | GunSchema, 8 | IGunChain, 9 | } from '.'; 10 | 11 | export interface IGun { 12 | = any>(options?: GunOptions): IGunInstance; 13 | new = any>(options?: GunOptions): IGunInstance; 14 | 15 | /** 16 | * Returns GUN state timestamp 17 | */ 18 | state(): number; 19 | 20 | chain: IGunChain & IGunInstance; 21 | 22 | /** 23 | * Listener for a GUN instance creation 24 | */ 25 | on( 26 | event: 'create', 27 | callback: GunHookCallbackCreate 28 | ): void; 29 | 30 | /** 31 | * Listener for a GUN options update 32 | */ 33 | on( 34 | event: 'opt', 35 | callback: GunHookCallbackOpt 36 | ): void; 37 | } 38 | -------------------------------------------------------------------------------- /types/gun/IGunHookContext.d.ts: -------------------------------------------------------------------------------- 1 | export interface IGunHookContext { 2 | off: () => void; 3 | to: { 4 | next: (subject: T) => void; 5 | }; 6 | } 7 | -------------------------------------------------------------------------------- /types/gun/IGunInstance.d.ts: -------------------------------------------------------------------------------- 1 | import { IGunInstanceRoot, GunSchema } from '.'; 2 | 3 | export interface IGunInstance = any> 4 | extends IGunInstanceRoot> {} 5 | -------------------------------------------------------------------------------- /types/gun/IGunMeta.d.ts: -------------------------------------------------------------------------------- 1 | export interface IGunMeta { 2 | _: { 3 | '#': string; 4 | '>': { 5 | [key in keyof T]: number; 6 | }; 7 | }; 8 | } 9 | -------------------------------------------------------------------------------- /types/gun/IGunOnEvent.d.ts: -------------------------------------------------------------------------------- 1 | export interface IGunOnEvent { 2 | off(): void; 3 | } 4 | -------------------------------------------------------------------------------- /types/gun/LEX.d.ts: -------------------------------------------------------------------------------- 1 | export type LEX = { 2 | /** exact match */ 3 | '='?: T; 4 | /** prefix match */ 5 | '*'?: string; 6 | /** gte match */ 7 | '>'?: string; 8 | /** lte match */ 9 | '<'?: string; 10 | /** 1 for reverse */ 11 | '-'?: number; 12 | }; 13 | -------------------------------------------------------------------------------- /types/gun/LEXQuery.d.ts: -------------------------------------------------------------------------------- 1 | import { LEX } from '.'; 2 | 3 | export type LEXQuery = { '.': LEX; ':'?: number }; 4 | -------------------------------------------------------------------------------- /types/gun/_GunRoot.d.ts: -------------------------------------------------------------------------------- 1 | import { GunOptions, IGunInstanceHookHandler } from '.'; 2 | 3 | export interface _GunRoot extends IGunInstanceHookHandler { 4 | $: { _: _GunRoot }; 5 | 6 | /** 7 | * Current GUN options 8 | */ 9 | opt: GunOptions; 10 | } 11 | -------------------------------------------------------------------------------- /types/gun/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './_GunRoot'; 2 | export * from './GunCallbackGet'; 3 | export * from './GunCallbackMap'; 4 | export * from './GunCallbackOn'; 5 | export * from './GunCallbackOnce'; 6 | export * from './GunCallbackPut'; 7 | export * from './GunDataNode'; 8 | export * from './GunHookCallbackBye'; 9 | export * from './GunHookCallbackCreate'; 10 | export * from './GunHookCallbackGet'; 11 | export * from './GunHookCallbackHi'; 12 | export * from './GunHookCallbackIn'; 13 | export * from './GunHookCallbackOpt'; 14 | export * from './GunHookCallbackOut'; 15 | export * from './GunHookCallbackPut'; 16 | export * from './GunNodeGet'; 17 | export * from './GunNodePut'; 18 | export * from './GunOptions'; 19 | export * from './GunOptionsOn'; 20 | export * from './GunOptionsOnce'; 21 | export * from './GunOptionsPut'; 22 | export * from './GunPeer'; 23 | export * from './GunSoul'; 24 | export * from './GunValueSimple'; 25 | export * from './IGun'; 26 | export * from './IGunChain'; 27 | export * from './IGunHookContext'; 28 | export * from './IGunInstance'; 29 | export * from './IGunInstanceHookHandler'; 30 | export * from './IGunInstanceRoot'; 31 | export * from './IGunMeta'; 32 | export * from './IGunOnEvent'; 33 | export * from './GunSchema'; 34 | export * from './LEX'; 35 | export * from './LEXQuery'; 36 | export * from './pany'; 37 | -------------------------------------------------------------------------------- /types/gun/pany.d.ts: -------------------------------------------------------------------------------- 1 | export type pany = Partial; 2 | -------------------------------------------------------------------------------- /types/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './gun'; 2 | export * from './sea'; 3 | -------------------------------------------------------------------------------- /types/sea/GunCallbackUserAuth.d.ts: -------------------------------------------------------------------------------- 1 | import { GunUser, ISEAPair } from '..'; 2 | 3 | export type GunCallbackUserAuth = ( 4 | ack: 5 | | { 6 | ack: 2; 7 | /** ~publicKeyOfUser */ 8 | soul: string; 9 | /** ~publicKeyOfUser */ 10 | get: string; 11 | put: GunUser; 12 | sea: ISEAPair; 13 | } 14 | | { err: string } 15 | ) => void; 16 | -------------------------------------------------------------------------------- /types/sea/GunCallbackUserCreate.d.ts: -------------------------------------------------------------------------------- 1 | export type GunCallbackUserCreate = ( 2 | ack: { ok: 0; pub: string } | { err: string } 3 | ) => void; 4 | -------------------------------------------------------------------------------- /types/sea/GunHookCallbackAuth.d.ts: -------------------------------------------------------------------------------- 1 | import { GunHookMessagePut, GunUser, IGunOnEvent } from '..'; 2 | 3 | export type GunHookCallbackAuth = ( 4 | user: GunUser, 5 | message: GunHookMessagePut, 6 | event: IGunOnEvent 7 | ) => void; 8 | -------------------------------------------------------------------------------- /types/sea/GunUser.d.ts: -------------------------------------------------------------------------------- 1 | export type GunUser = { 2 | /** Username or Alias which can be used to find a user */ 3 | alias: string; 4 | // auth: string; 5 | /** public key for encryption */ 6 | epub: string; 7 | /** public key */ 8 | pub: string; 9 | }; 10 | -------------------------------------------------------------------------------- /types/sea/IGun.d.ts: -------------------------------------------------------------------------------- 1 | import { ISEA } from '.'; 2 | 3 | import {} from '../gun/IGun'; 4 | declare module '../gun/IGun' { 5 | export interface IGun { 6 | SEA: ISEA; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /types/sea/IGunInstance.d.ts: -------------------------------------------------------------------------------- 1 | import { IGunInstanceRoot, GunSchema, IGunUserInstance } from '..'; 2 | 3 | import {} from '../gun/IGunInstance'; 4 | declare module '../gun/IGunInstance' { 5 | export interface IGunInstance { 6 | user< 7 | UNode extends Record = any, 8 | UNodeInstance extends IGunUserInstance< 9 | UNode, 10 | UNodeInstance, 11 | TNode, 12 | IGunInstanceRoot> 13 | > = any 14 | >(): IGunUserInstance>>; 15 | user< 16 | UNode extends Record = any, 17 | UNodeInstance extends IGunUserInstance< 18 | UNode, 19 | UNodeInstance, 20 | TNode, 21 | IGunInstanceRoot> 22 | > = any 23 | >( 24 | publicKey: string 25 | ): IGunUserInstance>>; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /types/sea/IGunInstanceHookHandler.d.ts: -------------------------------------------------------------------------------- 1 | import { GunHookCallbackAuth } from '..'; 2 | 3 | import {} from '../gun/IGunInstanceHookHandler'; 4 | declare module '../gun/IGunInstanceHookHandler' { 5 | export interface IGunInstanceHookHandler { 6 | /** Called upon successful user authentication */ 7 | on(event: 'auth', callback: GunHookCallbackAuth): void; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /types/sea/IGunInstanceRoot.d.ts: -------------------------------------------------------------------------------- 1 | import { GunSchema, IGunUserInstance } from '..'; 2 | 3 | import {} from '../gun/IGunInstanceRoot'; 4 | declare module '../gun/IGunInstanceRoot' { 5 | export interface IGunInstanceRoot { 6 | user< 7 | UNode extends Record = any, 8 | UNodeInstance extends IGunUserInstance< 9 | UNode, 10 | UNodeInstance, 11 | TNode, 12 | TGunInstance 13 | > = any 14 | >(): IGunUserInstance; 15 | user< 16 | UNode extends Record = any, 17 | UNodeInstance extends IGunUserInstance< 18 | UNode, 19 | UNodeInstance, 20 | TNode, 21 | TGunInstance 22 | > = any 23 | >( 24 | publicKey: string 25 | ): IGunUserInstance; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /types/sea/IPolicy.d.ts: -------------------------------------------------------------------------------- 1 | import { LEX } from '..'; 2 | 3 | export interface IPolicy extends LEX { 4 | /** Path */ 5 | '#'?: LEX; 6 | /** Key */ 7 | '.'?: LEX; 8 | /** 9 | * Either Path string or Key string must 10 | * contain Certificate's Pub string 11 | */ 12 | '+'?: '*'; 13 | } 14 | -------------------------------------------------------------------------------- /types/sea/ISEAPair.d.ts: -------------------------------------------------------------------------------- 1 | export interface ISEAPair { 2 | /** private key for encryption */ 3 | epriv: string; 4 | /** public key for encryption */ 5 | epub: string; 6 | /** private key */ 7 | priv: string; 8 | /** public key */ 9 | pub: string; 10 | } 11 | -------------------------------------------------------------------------------- /types/sea/OptionsUserAuth.d.ts: -------------------------------------------------------------------------------- 1 | export type OptionsUserAuth = { change: string }; 2 | -------------------------------------------------------------------------------- /types/sea/OptionsUserRecall.d.ts: -------------------------------------------------------------------------------- 1 | export type OptionsUserRecall = { sessionStorage: boolean }; 2 | -------------------------------------------------------------------------------- /types/sea/Policy.d.ts: -------------------------------------------------------------------------------- 1 | import { IPolicy } from '.'; 2 | 3 | export type Policy = string | IPolicy | (string | IPolicy)[]; 4 | -------------------------------------------------------------------------------- /types/sea/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './GunCallbackUserAuth'; 2 | export * from './GunCallbackUserCreate'; 3 | export * from './GunHookCallbackAuth'; 4 | export * from './GunUser'; 5 | export * from './IGun'; 6 | export * from './IGunInstance'; 7 | export * from './IGunInstanceHookHandler'; 8 | export * from './IGunUserInstance'; 9 | export * from './IPolicy'; 10 | export * from './ISEA'; 11 | export * from './ISEAPair'; 12 | export * from './OptionsUserAuth'; 13 | export * from './OptionsUserRecall'; 14 | export * from './Policy'; 15 | -------------------------------------------------------------------------------- /types/test/gun-back.test-d.ts: -------------------------------------------------------------------------------- 1 | import Gun from '../..'; 2 | 3 | new Gun<{ a: { b: number; c: number } }>() 4 | .get('a') 5 | .get('b') 6 | .back() 7 | .get('c') 8 | .once((c) => c.toFixed(2)); 9 | 10 | new Gun() 11 | .get<{ b: number; c: number }>('a') 12 | .get('b') 13 | .back() 14 | .get('c') 15 | .once((c) => c.toFixed(2)); 16 | 17 | new Gun() 18 | .get('a') 19 | .back<{ a: number; b: number }>() 20 | .get('b') 21 | .once((b) => b.toFixed(2)); 22 | 23 | new Gun() 24 | .get('a') 25 | .get('b') 26 | .back<{ a: number; c: number }>(-2) 27 | .get('c') 28 | .once((c) => c.toFixed(2)); 29 | -------------------------------------------------------------------------------- /types/test/gun-get.test-d.ts: -------------------------------------------------------------------------------- 1 | import Gun from '../..'; 2 | 3 | new Gun<{ a: { b: number; c: number } }>().get('a').get('b'); 4 | 5 | new Gun().get<{ b: number; c: number }>('a').get('b'); 6 | -------------------------------------------------------------------------------- /types/test/gun-instance.test-d.ts: -------------------------------------------------------------------------------- 1 | import Gun from '../..'; 2 | 3 | new Gun(); 4 | new Gun(['http://server1.com/gun', 'http://server2.com/gun']); 5 | new Gun({ 6 | s3: { 7 | key: '', 8 | secret: '', 9 | bucket: '', 10 | }, 11 | file: 'file/path.json', 12 | uuid() { 13 | return 'xxxxxx'; 14 | }, 15 | }); 16 | -------------------------------------------------------------------------------- /types/test/gun-map.test-d.ts: -------------------------------------------------------------------------------- 1 | import Gun from '../..'; 2 | 3 | new Gun<{ users: Record }>() 4 | .get('users') 5 | .on() 6 | .map((user) => (user.name === 'Mark' ? user : undefined)); 7 | 8 | new Gun() 9 | .get>('users') 10 | .map((user) => (user.name === 'Mark' ? user : undefined)) 11 | .once((user) => console.log(user.name)); 12 | -------------------------------------------------------------------------------- /types/test/gun-on.test-d.ts: -------------------------------------------------------------------------------- 1 | import Gun from '../..'; 2 | 3 | type TOnlinable = { online: boolean }; 4 | 5 | const gun = new Gun<{ 6 | users: Record; 7 | foo: TOnlinable; 8 | home: { lights: TOnlinable }; 9 | }>(); 10 | 11 | var listenerHandler = (_value, _key, _msg, _ev) => {}; 12 | 13 | // add listener to foo 14 | gun.get('foo').on(listenerHandler, true); 15 | 16 | // remove listener to foo 17 | gun.get('foo').off(); 18 | 19 | gun 20 | .get('users') 21 | .get('username') 22 | .on(function (user) { 23 | // update in real-time 24 | if (user.online) { 25 | } else { 26 | } 27 | }); 28 | 29 | gun.get('home').get('lights').on(listenerHandler, true); 30 | 31 | new Gun() 32 | .get('home') 33 | .get('lights') 34 | .on(function (user) { 35 | // update in real-time 36 | if (user.online) { 37 | } else { 38 | } 39 | }); 40 | -------------------------------------------------------------------------------- /types/test/gun-once.test-d.ts: -------------------------------------------------------------------------------- 1 | import Gun from '../..'; 2 | 3 | const gun = new Gun<{ 4 | peer: { userID: { profile: {} } }; 5 | IoT: { temperature: number }; 6 | something: string; 7 | }>(); 8 | 9 | let view: any; 10 | 11 | gun 12 | .get('peer') 13 | .get('userID') 14 | .get('profile') 15 | .once(function (profile) { 16 | // render it, but only once. No updates. 17 | view.show.user(profile); 18 | }); 19 | 20 | gun 21 | .get('IoT') 22 | .get('temperature') 23 | .once(function (number) { 24 | view.show.temp(number); 25 | }); 26 | 27 | gun.get('something').once(function (_data, _key) { 28 | gun.put({ something: 'something' }); 29 | gun.get('something').put('something'); 30 | }); 31 | 32 | new Gun().get('something').once(function (data, _key) { 33 | gun.put({ something: data }); 34 | gun.get('something').put(data); 35 | }); 36 | -------------------------------------------------------------------------------- /types/test/gun-opt.test-d.ts: -------------------------------------------------------------------------------- 1 | import Gun from '../..'; 2 | 3 | new Gun().opt({ 4 | uuid: function () { 5 | return Math.floor(Math.random() * 4294967296).toString(); 6 | }, 7 | }); 8 | -------------------------------------------------------------------------------- /types/test/gun-put.test-d.ts: -------------------------------------------------------------------------------- 1 | //import { expectError } from 'tsd'; 2 | 3 | import Gun from '../..'; 4 | 5 | //Documentation should work 6 | 7 | type User = { name: string }; 8 | 9 | const gun = new Gun<{ user: User; user2: User }>(); 10 | gun.get('user').put({ name: '' }); 11 | gun.get('user').get('name').put(gun.get('user').get('name')); 12 | gun.get('user2').put(gun.get('user')); 13 | -------------------------------------------------------------------------------- /types/test/gun-set.test-d.ts: -------------------------------------------------------------------------------- 1 | import Gun from '../..'; 2 | 3 | type User = { name: string }; 4 | 5 | const gun = new Gun<{ users: Record; alice: User }>(); 6 | const user = gun.get('alice').put({ name: 'Alice' }); 7 | gun.get('users').set({ name: 'Bob' }); 8 | gun.get('users').set(user).get('name').put('Sally'); 9 | -------------------------------------------------------------------------------- /types/test/gun-user-auth.test-d.ts: -------------------------------------------------------------------------------- 1 | import Gun from '../..'; 2 | 3 | //Documentation should work 4 | 5 | const gun = new Gun(); 6 | gun.on('auth', (_data) => {}); 7 | 8 | gun.user().auth('a', 'b'); 9 | async () => gun.user().auth(await Gun.SEA.pair()); 10 | -------------------------------------------------------------------------------- /types/test/gun-user-leave.test-d.ts: -------------------------------------------------------------------------------- 1 | import Gun from '../..'; 2 | 3 | //Documentation should work 4 | 5 | const gun = new Gun(); 6 | 7 | gun.user().leave(); 8 | -------------------------------------------------------------------------------- /types/test/gun-user-recall.test-d.ts: -------------------------------------------------------------------------------- 1 | import Gun from '../..'; 2 | 3 | const gun = new Gun(); 4 | gun.user().recall({ sessionStorage: true }); 5 | -------------------------------------------------------------------------------- /types/test/gun-user.test-d.ts: -------------------------------------------------------------------------------- 1 | import Gun from '../..'; 2 | 3 | var gun = new Gun(); 4 | gun.user('publicKey'); 5 | -------------------------------------------------------------------------------- /types/test/sea-certify.test-d.ts: -------------------------------------------------------------------------------- 1 | import Gun from '../..'; 2 | 3 | /*Documentation example*/ 4 | async function certify() { 5 | const SEA = Gun.SEA; 6 | const gun = new Gun(); 7 | const user = gun.user(); 8 | const Alice = await SEA.pair(); 9 | const AliceHusband = await SEA.pair(); 10 | const Bob = await SEA.pair(); 11 | const Dave = await SEA.pair(); 12 | 13 | // Alice wants to allow Bob and Dave to use write to her "inbox" and "stories" UNTIL TOMORROW 14 | // On Alice's side: 15 | const certificate = await SEA.certify( 16 | [Bob.pub, Dave.pub], 17 | [{ '*': 'inbox', '+': '*' }, { '*': 'stories' }], 18 | Alice, 19 | null, 20 | { expiry: Gun.state() + 60 * 60 * 24 * 1000 } 21 | ); 22 | 23 | // Now on Bob/Dave's side, they can write to Alice's graph using gun.put: 24 | gun 25 | .get('~' + Alice.pub) 26 | .get('inbox') 27 | .put({ ['deeper' + Bob.pub]: 'hello world' }, null, { 28 | opt: { cert: certificate }, 29 | }); // {opt: {cert: certificate}} is how you use Certificate in gun.put 30 | } 31 | -------------------------------------------------------------------------------- /types/test/sea.test-d.ts: -------------------------------------------------------------------------------- 1 | import Gun from '../..'; 2 | 3 | const SEA = Gun.SEA; 4 | (async () => { 5 | const pair = await SEA.pair(); 6 | let enc = await SEA.encrypt('hello self', pair); 7 | const data = await SEA.sign(enc, pair); 8 | console.log(data); 9 | const msg = await SEA.verify(data, pair.pub); 10 | const dec = await SEA.decrypt(msg, pair); 11 | const proof = await SEA.work(dec, pair); 12 | const check = await SEA.work('hello self', pair); 13 | console.log(dec); 14 | console.log(proof === check); 15 | // now let's share private data with someone: 16 | const alice = await SEA.pair(); 17 | const bob = await SEA.pair(); 18 | enc = await SEA.encrypt('shared data', await SEA.secret(bob.epub, alice)); 19 | await SEA.decrypt(enc, await SEA.secret(alice.epub, bob)); 20 | // `.secret` is Elliptic-curve Diffie–Hellman 21 | // Bob allows Alice to write to part of his graph, he creates a certificate for Alice 22 | const certificate = await SEA.certify(alice.pub, ['^AliceOnly.*'], bob); 23 | // Alice logs in 24 | const gun = Gun(); 25 | gun.user().auth(alice); 26 | // and uses the certificate 27 | gun 28 | .get('~' + bob.pub) 29 | .get('AliceOnly') 30 | .put({ 'do-not-tell-anyone': enc }, null, { opt: { cert: certificate } }); 31 | gun 32 | .get('~' + bob.pub) 33 | .get('AliceOnly') 34 | .get('do-not-tell-anyone') 35 | .once(console.log); // return 'enc' 36 | })(); 37 | -------------------------------------------------------------------------------- /types/utils.d.ts: -------------------------------------------------------------------------------- 1 | import { GunSoul, IGunChain, IGunInstanceRoot } from '.'; 2 | 3 | export type GunSoul2TNode = T extends GunSoul 4 | ? TNode 5 | : never; 6 | 7 | export type GunSoul2Soul = T extends GunSoul 8 | ? Soul 9 | : never; 10 | 11 | export type IGunChain2TNode = T extends IGunChain< 12 | infer TNode, 13 | infer _TChainParent, 14 | infer _TNodeRoot, 15 | infer _TKey 16 | > 17 | ? TNode 18 | : never; 19 | 20 | export type IGunInstanceRoot2TGunInstance = T extends IGunInstanceRoot< 21 | infer _TNode, 22 | infer TGunInstance 23 | > 24 | ? TGunInstance 25 | : never; 26 | --------------------------------------------------------------------------------