• Stars
    star
    258
  • Rank 158,189 (Top 4 %)
  • Language
    TypeScript
  • License
    Other
  • Created over 4 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A JavaScript client for the Holochain Conductor API

Project Discord License: CAL 1.0 Integration Tests Bundling Tests Twitter Follow

Holochain Client - JavaScript

A JavaScript client for the Holochain Conductor API (works with browsers as well as Nodejs).

API Reference

Complete API reference

Installation

JS client v0.12.x is compatible with Holochain v0.1.x.

JS client v0.16.x is compatible with Holochain v0.2.x.

JS client v0.17.x is compatible with Holochain v0.3.x.

To install from NPM, run

npm install --save-exact @holochain/client

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.

Sample usage

Use AppAgentWebsocket with implicit zome call signing

import { ActionHash, AdminWebsocket, AppAgentWebsocket, CellType } from "@holochain/client";

const adminWs = await AdminWebsocket.connect({url: "ws://127.0.0.1:65000"});
const agent_key = await adminWs.generateAgentPubKey();
const role_name = "role";
const installed_app_id = "test-app";
const appInfo = await adminWs.installApp({
  agent_key,
  path: "path/to/happ/file",
  installed_app_id,
  membrane_proofs: {},
});
await adminWs.enableApp({ installed_app_id });
if (!(CellType.Provisioned in appInfo.cell_info[role_name][0])) {
  process.exit();
}
const { cell_id } = appInfo.cell_info[role_name][0][CellType.Provisioned];
await adminWs.authorizeSigningCredentials(cell_id);
await adminWs.attachAppInterface({ port: 65001 });
const appAgentWs = await AppAgentWebsocket.connect(installed_app_id, {url: "ws://127.0.0.1:65001"});

const zomeCallPayload: CallZomeRequest = {
  cell_id,
  zome_name: "zome_name",
  fn_name: "create_entry",
  provenance: agent_key,
  payload: "some_content",
};

const response: ActionHash = await appAgentWs.callZome(zomeCallPayload, 30000);

await appAgentWs.appWebsocket.client.close();
await adminWs.client.close();

Use AppWebsocket with implicit zome call signing

import { AdminWebsocket, AppWebsocket, CellType } from "@holochain/client";

const adminWs = await AdminWebsocket.connect({url: "ws://127.0.0.1:65000"});
const agent_key = await adminWs.generateAgentPubKey();
const installed_app_id = "test-app";
const appInfo = await adminWs.installApp({
  agent_key,
  path: "path/to/happ/file",
  installed_app_id,
  membrane_proofs: {},
});
await adminWs.enableApp({ installed_app_id });
if (!(CellType.Provisioned in appInfo.cell_info["role"][0])) {
  process.exit();
}
const { cell_id } = appInfo.cell_info["role"][0][CellType.Provisioned];
await adminWs.authorizeSigningCredentials(cell_id);
await adminWs.attachAppInterface({ port: 65001 });
const appWs = await AppWebsocket.connect({url: "ws://127.0.0.1:65001"});

let signalCb;
const signalReceived = new Promise<void>((resolve) => {
  signalCb = (signal) => {
    console.log("signal received", signal);
    // act on signal
    resolve();
  };
});

appWs.on("signal", signalCb);

// trigger an emit_signal
await appWs.callZome({
  cell_id,
  zome_name: "zome",
  fn_name: "emitter",
  provenance: agent_key,
  payload: null,
});
await signalReceived;

await appWs.client.close();
await adminWs.client.close();

Managing zome call signing credentials in a pure JavaScript browser application

Here is a pattern to manage signing keys for signing zome calls when running pure JavaScript web hApps in a web browser:

const cellIdB64 =
    encodeHashToBase64(cell_id[0]) + encodeHashToBase64(cell_id[1]);
// in case the zome call signing credentials are stored locally in the browser
const signingCredentialsJson = localStorage.getItem(cellIdB64);
let signingCredentials: SigningCredentials | null =
  signingCredentialsJson && JSON.parse(signingCredentialsJson);

if (!signingCredentials) {
  const [keyPair, signingKey] = generateSigningKeyPair();
  const capSecret = await admin.grantSigningKey(
    cell_id,
    { [GrantedFunctionsType.All]: null },
    signingKey
  );
  signingCredentials = {
    capSecret,
    keyPair,
    signingKey,
  };
}
setSigningCredentials(cell_id, signingCredentials);
// possibly store the zome call signing credentials locally in the browser
localStorage.setItem(cellIdB64, JSON.stringify(signingCredentials));

Running tests

You need a version (stable toolchain) of Rust available.

You need holochain and hc on your path, best to get them from nix with nix-shell.

To perform the pre-requisite DNA compilation steps, and run the Nodejs test, run:

nix-shell
./run-test.sh

Contribute

Holochain 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 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.

License

License: CAL 1.0

Copyright (C) 2020-2023, Holochain Foundation

This program is free software: you can redistribute it and/or modify it under the terms of the license provided in the LICENSE file (CAL-1.0). This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

More Repositories

1

holochain

The current, performant & industrial strength version of Holochain on Rust.
Rust
1,170
star
2

holochain-rust

DEPRECATED. The Holochain framework implemented in rust with a redux style internal state-model.
Rust
1,121
star
3

holochain-proto

Holographic storage for distributed applications -- a validating monotonic DHT "backed" by authoritative hashchains for data provenance (a Ceptr sub-project)
Go
878
star
4

launcher-tauri

Desktop launcher to install and use Holochain apps locally
Vue
262
star
5

cryptographic-autonomy-license

The Cryptographic Autonomy License is a new breed of open license that protects not just the app developers and users of the source code but also end user privacy and control of identity and data.
241
star
6

scaffolding

Scaffolding tool to quickly generate and edit holochain applications
Handlebars
220
star
7

clutter

Fully distributed twitter built on holochain
JavaScript
161
star
8

holonix-archive

NixOS && Holochain
Nix
150
star
9

holochain-ui

UI for composing Holochain experiences. First app is the Abundance of Presence chat & meeting coordination tool. Also includes Persona and Profile Management with Vault.
TypeScript
99
star
10

holochain-client-rust

A Rust client for the Holochain Conductor API
Rust
97
star
11

happ-build-tutorial

Tutorial on how to build hApp DNAs for Holochain RSM
TypeScript
96
star
12

docs-pages

The hosted static files for the Holochain developer documentation
Nunjucks
96
star
13

peer-chat-redux

Instant messaging application running on Holochain-redux in Holoscape [For chat on Holochain rsm see https://github.com/holochain/elemental-chat/]
JavaScript
90
star
14

syn

Generalized Holochain DNA and UI library for building real-time shared state hApps
TypeScript
89
star
15

elemental-chat

A chat DNA for Holochain RSM
TypeScript
81
star
16

apps

Your guide to fnding, installing, and running holochain apps
HTML
71
star
17

deepkey

A Holochain implementation of decentralized public key infrastructure
Rust
68
star
18

CRISPR-Holochain-redux

Electron app for designing and generating Zomes with UI Components
Vue
66
star
19

tx5

Holochain WebRTC P2P Communication Ecosystem
Rust
66
star
20

holoscape

A complete end-user deployment of a Holochain conductor with UI for administration and a run-time for hApp UIs
HTML
63
star
21

holochain-wasmer

Rust
61
star
22

devhub-dnas

DNAs for sharing source code and distributing compiled WASM that comprise Holochain Apps.
Rust
60
star
23

wind-tunnel

Performance testing for Holochain
Rust
60
star
24

hc-utils

A util crate for holochain-rsm
Rust
58
star
25

launcher

Desktop launcher to install and use Holochain apps locally (Electron version)
TypeScript
58
star
26

HoloWorld

Basic Hello World app for Holochain
JavaScript
57
star
27

holochat

Multi-room P2P chat (like a distributed Slack) which runs on holochain
HTML
56
star
28

holochain-nixpkgs

Nix
56
star
29

dpki

Distributed Public Key Infrastructure which runs on holochain
JavaScript
56
star
30

how

Embodment of a Holochain emegent standards process
TypeScript
55
star
31

hc-web-client-redux

RPC WebSocket client for Holochain web UIs
JavaScript
54
star
32

holochain-serialization

Abstractions to probably serialize and deserialize things properly without forgetting or doubling
Rust
49
star
33

website

jekyll website for holochain.org
HTML
48
star
34

n3h

nodejs implementation of holochain networking / p2p backend process
JavaScript
48
star
35

elemental-chat-ui

A Vue.js + Vuetify + Vuex web app for Elemental Chat DNA.
JavaScript
48
star
36

scaffold

Web-based wizard for generating scaffolding for holochain applications.
JavaScript
46
star
37

devhub-gui

A web-based UI that works with Holochain's collection of DevHub DNAs.
JavaScript
45
star
38

lib3h

The lib3h p2p communication rust library.
Rust
44
star
39

hc-zome-lib

This is a pkgs with multiple zomes that can be used in your holochain dna
Rust
43
star
40

lair

secret lair private keystore
Rust
42
star
41

sodoken

Libsodium wrapper providing tokio safe memory secure api access.
Rust
42
star
42

minersweeper

Massively Multiplayer Distributed Minesweeper on Holochain
TypeScript
41
star
43

hdk-assemblyscript

The Holochain Developer Kit for Assemblyscript
JavaScript
41
star
44

holochain-anchors

A core pattern for storing AND FINDING data in a Holochain DHT. Anchors are a predictable hash (by using known content) from which you can attach links
Rust
39
star
45

holochain-blog-theme

The Ghost theme files for blog.holochain.org
CSS
38
star
46

hcSeedBundle

Javascript SeedBundle parsing and generation library.
TypeScript
36
star
47

holochain-cmd

Developer Command Line Tools for Holochain
Rust
36
star
48

holochain-load-test

Load testing for Holochain
Python
35
star
49

influxive

Opinionated tools for working with InfluxDB from Rust
Rust
35
star
50

holochain-client-python

A Python client for the Holochain Conductor API
Python
32
star
51

ghost_actor

GhostActor makes it simple, ergonomic, and idiomatic to implement async / concurrent code using an Actor model.
Rust
32
star
52

holochain-serialization-python

Rust
31
star
53

app-store-dnas

DNAs for Holochain App discovery and download.
Rust
31
star
54

bootstrap2

Holochain bootstrap peer discovery.
Rust
31
star
55

bootstrap

Bootstrap nodes onto a network by allowing existing nodes to list themselves under a URL
TypeScript
30
star
56

tryorama

Toolset to manage Holochain conductors and facilitate test scenarios
TypeScript
30
star
57

hc-spin

CLI to run Holochain Apps in Development Mode
TypeScript
30
star
58

hc-ts-template

Typescript + React + Redux + holochain-proto starter app
JavaScript
29
star
59

integrity-template

establishing patterns for separating integrity zomes from accessor zomes for Holochain apps
Rust
29
star
60

holosqape

Qt and QML based Holochain container app
C++
28
star
61

holochain-serialization-js

A JavaScript Wasm binding of the Holochain serialization and hashing algorithm (JaWaHoSeHa)
JavaScript
28
star
62

hc-tel

holochain telemetry experiment
Rust
27
star
63

benchmarks

sample apps used to establish initial holo fuel pricing
JavaScript
26
star
64

happ-client-call-tutorial

How to call your hApp
Rust
26
star
65

HCHC

The Holochain of Holochains
JavaScript
26
star
66

cointoss

example holochain app for "trustable random initiation"
JavaScript
26
star
67

holochain-nodejs

Test Holochain apps (hApps) within a nodejs container.
Rust
25
star
68

holochain-logging

Rust
25
star
69

identity-manager

DeepKey + Personas & Profiles
TypeScript
25
star
70

portal-dna

A DNA for providing zome function access across networks
Rust
25
star
71

react-graphql-template

JavaScript
24
star
72

app-store-gui

A web-based UI that works with Holochain's collection of App Store DNAs.
JavaScript
24
star
73

web-components

Library of React Web Components for Holochain Apps
JavaScript
24
star
74

mapOnHolochain

23
star
75

dao

Holochain implementation of standard ethereum DAO (Decentralized Autonomous Organization)
JavaScript
23
star
76

hc-spin-rust-utils

Rust node add-ons for hc-spin
JavaScript
23
star
77

hdk-rust

HDK Rust HAS MOVED -> https://github.com/holochain/holochain-rust/tree/develop/hdk-rust
Rust
23
star
78

holodex

Holochain application indexing engine for distributed apps which run on holochains
JavaScript
23
star
79

hc-test-utils

A lib of testing utility crates to support testing with holochain beta releases.
Rust
23
star
80

hc-state-cli-node

JavaScript
22
star
81

soa-toolbox

soa-toolbox is a set of plugins for Miro that give special functionality
JavaScript
22
star
82

hackathon-happs

hApps developed at various hackathons and training events
Rust
22
star
83

personas-profiles-redux

Holochain-redux (deprecated) app for people to manage how other apps access their personal information.
TypeScript
22
star
84

happ-index

"The poor man's hApp store" - short term interim solution until decentralized hApp store running on Holochain is up
21
star
85

holochat-rust

An extremely simple and small P2P chat app, with chat rooms
HTML
20
star
86

tasktaskic

an example app for holochain-rust 0.0.1 developer preview
Rust
20
star
87

hc-siderun

Helper utility for initializing a cluster of holochain nodes all connecting to a local bootstrap server (and thus, to each other)
Shell
20
star
88

holochain-persistence

Abstractions for saving and retrieving data locally
Rust
20
star
89

dev-camp-tests-rust

A test-driven development way to learn Holochain!
JavaScript
20
star
90

holochain-forum-theme

The Discourse theme for forum.holochain.org
20
star
91

hcrs

nodejs scaffold generation for holochain-rust
JavaScript
20
star
92

tx3

tx3 p2p communications
Rust
19
star
93

hc-rtc-demo

Holochain webrtc PoC / demo application
19
star
94

docs-pages-redux

Developer docs for Holochain Redux (legacy)
HTML
19
star
95

vue-cli-preset-holochain

Preset for creating Vue, Vuetify, Vuex, dexie Holochain apps.
19
star
96

dna-to-openapi

given holochain dna, generate a swagger / openapi spec file
JavaScript
18
star
97

core-concepts-examples-redux

A selection of example projects to illustrate the core concepts of Holochain
Rust
18
star
98

app-spec-rust

App Spec Rust HAS MOVED into holochain-rust repository!
Rust
18
star
99

vue-cli-plugin-holochain

Vue plugin that sets up a complete Vue + Vuetify + Vuex + Dexie + Holochain app
Vue
18
star
100

hc-rtc-sig

holochain webrtc signal server / client
18
star