{"_id":"@culturehacklabs/holochain-client","name":"@culturehacklabs/holochain-client","dist-tags":{"latest":"0.17.2"},"versions":{"0.17.2":{"name":"@culturehacklabs/holochain-client","version":"0.17.2","description":"A JavaScript client for the Holochain Conductor API","author":{"name":"Holochain Foundation","email":"info@holochain.org","url":"https://holochain.org"},"license":"CAL-1.0","repository":{"type":"git","url":"git+https://github.com/arkologystudio/holochain-client-js.git"},"keywords":["holochain","client","conductor api"],"bugs":{"url":"https://github.com/arkologystudio/holochain-client-js/issues"},"homepage":"https://github.com/arkologystudio/holochain-client-js#readme","engines":{"node":">=18.0.0 || >=20.0.0"},"main":"lib/index.js","module":"lib/index.js","type":"module","exports":{".":"./lib/index.js"},"types":"lib/index.d.ts","scripts":{"lint":"eslint --fix --ext .ts src test .eslintrc.cjs","format":"prettier --write \"src/**/*.ts\" \"test/**/*.ts\"","test:app-agent":"RUST_LOG=error RUST_BACKTRACE=1 tsx test/e2e/app-websocket.ts","test:utils":"RUST_LOG=error RUST_BACKTRACE=1 tsx test/e2e/utils.ts","test":"RUST_LOG=error RUST_BACKTRACE=1 tsx test/index.ts","build:lib":"rimraf ./lib && tsc -p tsconfig.build.json","build:docs":"api-extractor run --local && api-documenter markdown -i docs/temp -o docs","build":"npm run build:lib && npm run build:docs","prepublishOnly":"npm run lint && npm run build"},"dependencies":{"@bitgo/blake2b":"^3.2.4","@holochain/serialization":"^0.1.0-beta-rc.3","@msgpack/msgpack":"^2.8.0","emittery":"^1.0.1","isomorphic-ws":"^5.0.0","js-base64":"^3.7.5","libsodium-wrappers":"^0.7.13","lodash-es":"^4.17.21","ws":"^8.14.2"},"devDependencies":{"@microsoft/api-documenter":"^7.21.7","@microsoft/api-extractor":"^7.34.4","@types/libsodium-wrappers":"^0.7.11","@types/lodash-es":"^4.17.6","@types/tape":"^4.13.2","@types/ws":"^8.5.5","@typescript-eslint/eslint-plugin":"^5.62.0","@typescript-eslint/parser":"^5.62.0","eslint":"^8.49.0","eslint-config-prettier":"^8.10.0","eslint-plugin-prettier":"^4.2.1","eslint-plugin-tsdoc":"^0.2.17","js-yaml":"^3.14.1","prettier":"^2.8.8","rimraf":"^3.0.2","tape":"^5.6.6","tsx":"^4.7.2","typescript":"^4.9.5"},"gitHead":"3ad3cf2525b7ceaeac99b27a62fd6ada86da2efc","_id":"@culturehacklabs/holochain-client@0.17.2","_nodeVersion":"18.17.0","_npmVersion":"9.6.7","dist":{"integrity":"sha512-XSj59ay2Sjj2hyGEvEi2Y+Q0cixksAMfm6rYLa3akhmMIBYjed2v1wcuElwV8thc3FkIWCY0a+Tf9teRJt6eVA==","shasum":"8ad5a34736f553641d58b28a1d59834da43886da","tarball":"https://registry.npmjs.org/@culturehacklabs/holochain-client/-/holochain-client-0.17.2.tgz","fileCount":54,"unpackedSize":126049,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCHsVDKjATYXTSET38LeCInVV1FNRBj50uvAkLvJzSQZgIhAMeuHAFm+fyyCbv58F0mlFSPb+aI9FhkISNl/Vu5GqIi"}]},"_npmUser":{"name":"checoelho","email":"checoelho@gmail.com"},"directories":{},"maintainers":[{"name":"cristinacarlylemitchell","email":"cristinacarlylemitchell@gmail.com"},{"name":"zunaidvalodia","email":"zunaid.valodia@gmail.com"},{"name":"theoht","email":"theohenrythesen@gmail.com"},{"name":"checoelho","email":"checoelho@gmail.com"},{"name":"rosseyre","email":"rosseyre@gmail.com"},{"name":"erikhartin","email":"erik@sans.email"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/holochain-client_0.17.2_1721594215013_0.25977149079058637"},"_hasShrinkwrap":false}},"time":{"created":"2024-07-21T20:36:54.893Z","0.17.2":"2024-07-21T20:36:55.205Z","modified":"2024-07-21T20:36:55.657Z"},"maintainers":[{"name":"cristinacarlylemitchell","email":"cristinacarlylemitchell@gmail.com"},{"name":"zunaidvalodia","email":"zunaid.valodia@gmail.com"},{"name":"theoht","email":"theohenrythesen@gmail.com"},{"name":"checoelho","email":"checoelho@gmail.com"},{"name":"rosseyre","email":"rosseyre@gmail.com"},{"name":"erikhartin","email":"erik@sans.email"}],"description":"A JavaScript client for the Holochain Conductor API","homepage":"https://github.com/arkologystudio/holochain-client-js#readme","keywords":["holochain","client","conductor api"],"repository":{"type":"git","url":"git+https://github.com/arkologystudio/holochain-client-js.git"},"author":{"name":"Holochain Foundation","email":"info@holochain.org","url":"https://holochain.org"},"bugs":{"url":"https://github.com/arkologystudio/holochain-client-js/issues"},"license":"CAL-1.0","readme":"[![Project](https://img.shields.io/badge/Project-Holochain-blue.svg?style=flat-square)](http://holochain.org/)\n[![Discord](https://img.shields.io/badge/Discord-DEV.HC-blue.svg?style=flat-square)](https://discord.gg/k55DS5dmPH)\n[![License: CAL 1.0](https://img.shields.io/badge/License-CAL%201.0-blue.svg)](https://github.com/holochain/cryptographic-autonomy-license)\n![Integration Tests](https://github.com/holochain/holochain-client-js/actions/workflows/integration-test.yml/badge.svg?branch=main)\n![Bundling Tests](https://github.com/holochain/holochain-client-js/actions/workflows/bundling-test.yml/badge.svg?branch=main)\n[![Twitter Follow](https://img.shields.io/twitter/follow/holochain.svg?style=social&label=Follow)](https://twitter.com/holochain)\n\n# Holochain Client - JavaScript\n\nA JavaScript client for the Holochain Conductor API (works with browsers as well as Nodejs).\n\n## API Reference\n\n[Complete API reference](./docs/client.md)\n\n## Installation\n\n**JS client v0.17.x** is compatible with **Holochain v0.3.x**.\n\n**JS client v0.16.x** is compatible with **Holochain v0.2.x**.\n\nTo install from NPM, run\n```bash\nnpm install --save-exact @holochain/client\n```\n\n> This code is under beta development and you may wish to lock to an exact version of the library for that reason, as shown in the above command.\n\n## Sample usage\n\n### Use AppAgentWebsocket with implicit zome call signing\n```typescript\nimport { ActionHash, AdminWebsocket, AppAgentWebsocket, CellType } from \"@holochain/client\";\n\nconst adminWs = await AdminWebsocket.connect({url: \"ws://127.0.0.1:65000\"});\nconst agent_key = await adminWs.generateAgentPubKey();\nconst role_name = \"role\";\nconst installed_app_id = \"test-app\";\nconst appInfo = await adminWs.installApp({\n  agent_key,\n  path: \"path/to/happ/file\",\n  installed_app_id,\n  membrane_proofs: {},\n});\nawait adminWs.enableApp({ installed_app_id });\nif (!(CellType.Provisioned in appInfo.cell_info[role_name][0])) {\n  process.exit();\n}\nconst { cell_id } = appInfo.cell_info[role_name][0][CellType.Provisioned];\nawait adminWs.authorizeSigningCredentials(cell_id);\nawait adminWs.attachAppInterface({ port: 65001 });\nconst appAgentWs = await AppAgentWebsocket.connect(installed_app_id, {url: \"ws://127.0.0.1:65001\"});\n\nconst zomeCallPayload: CallZomeRequest = {\n  cell_id,\n  zome_name: \"zome_name\",\n  fn_name: \"create_entry\",\n  provenance: agent_key,\n  payload: \"some_content\",\n};\n\nconst response: ActionHash = await appAgentWs.callZome(zomeCallPayload, 30000);\n\nawait appAgentWs.appWebsocket.client.close();\nawait adminWs.client.close();\n```\n\n### Use AppWebsocket with implicit zome call signing\n```typescript\nimport { AdminWebsocket, AppWebsocket, CellType } from \"@holochain/client\";\n\nconst adminWs = await AdminWebsocket.connect({url: \"ws://127.0.0.1:65000\"});\nconst agent_key = await adminWs.generateAgentPubKey();\nconst installed_app_id = \"test-app\";\nconst appInfo = await adminWs.installApp({\n  agent_key,\n  path: \"path/to/happ/file\",\n  installed_app_id,\n  membrane_proofs: {},\n});\nawait adminWs.enableApp({ installed_app_id });\nif (!(CellType.Provisioned in appInfo.cell_info[\"role\"][0])) {\n  process.exit();\n}\nconst { cell_id } = appInfo.cell_info[\"role\"][0][CellType.Provisioned];\nawait adminWs.authorizeSigningCredentials(cell_id);\nawait adminWs.attachAppInterface({ port: 65001 });\nconst appWs = await AppWebsocket.connect({url: \"ws://127.0.0.1:65001\"});\n\nlet signalCb;\nconst signalReceived = new Promise<void>((resolve) => {\n  signalCb = (signal) => {\n    console.log(\"signal received\", signal);\n    // act on signal\n    resolve();\n  };\n});\n\nappWs.on(\"signal\", signalCb);\n\n// trigger an emit_signal\nawait appWs.callZome({\n  cell_id,\n  zome_name: \"zome\",\n  fn_name: \"emitter\",\n  provenance: agent_key,\n  payload: null,\n});\nawait signalReceived;\n\nawait appWs.client.close();\nawait adminWs.client.close();\n```\n\n### Managing zome call signing credentials in a pure JavaScript browser application\n\nHere is a pattern to manage signing keys for signing zome calls when running pure JavaScript web hApps in a web browser:\n```typescript\nconst cellIdB64 =\n    encodeHashToBase64(cell_id[0]) + encodeHashToBase64(cell_id[1]);\n// in case the zome call signing credentials are stored locally in the browser\nconst signingCredentialsJson = localStorage.getItem(cellIdB64);\nlet signingCredentials: SigningCredentials | null =\n  signingCredentialsJson && JSON.parse(signingCredentialsJson);\n\nif (!signingCredentials) {\n  const [keyPair, signingKey] = generateSigningKeyPair();\n  const capSecret = await admin.grantSigningKey(\n    cell_id,\n    { [GrantedFunctionsType.All]: null },\n    signingKey\n  );\n  signingCredentials = {\n    capSecret,\n    keyPair,\n    signingKey,\n  };\n}\nsetSigningCredentials(cell_id, signingCredentials);\n// possibly store the zome call signing credentials locally in the browser\nlocalStorage.setItem(cellIdB64, JSON.stringify(signingCredentials));\n```\n\n## Running tests\n\nYou need a version (`stable` toolchain) of Rust available.\n\nYou need `holochain` and `hc` on your path, best to get them from nix with `nix-shell`.\n\nTo perform the pre-requisite DNA compilation steps, and run the Nodejs test, run:\n```bash\nnix-shell\n./run-test.sh\n```\n\n## Contribute\n\nHolochain is an open source project.  We welcome all sorts of participation and are actively working on increasing surface area to accept it.  Please see our [contribution guidelines](/CONTRIBUTING.md) for our general practices and protocols on participating in the community, as well as specific expectations around things like code formatting, testing practices, continuous integration, etc.\n\n* Connect with us on [Discord](https://discord.gg/k55DS5dmPH)\n\n## License\n\n [![License: CAL 1.0](https://img.shields.io/badge/License-CAL%201.0-blue.svg)](https://github.com/holochain/cryptographic-autonomy-license)\n\nCopyright (C) 2020-2023, Holochain Foundation\n\nThis program is free software: you can redistribute it and/or modify it under the terms of the license\nprovided in the LICENSE file (CAL-1.0).  This program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR\nPURPOSE.\n","readmeFilename":"README.md"}