Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/update holochain service #105

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"holo:chaperone": "npx chaperone-server --config ./chaperone.json"
},
"dependencies": {
"@holochain/client": "^0.18.0-dev.6",
"@holo-host/identicon": "^0.1.0",
"@holo-host/web-sdk": "^0.6.9-prerelease",
"@testing-library/user-event": "^13.2.1",
Expand Down
2 changes: 1 addition & 1 deletion src/components/RegisterHapp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

<script>
import Button from './Button.vue'
import { getMembraneProof } from '../utils/registration.hs'
import { getMembraneProof } from '../utils/registration.js'

export default {
name: 'RegisterHapp',
Expand Down
84 changes: 70 additions & 14 deletions src/stores/useHolochainStore.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { inspect } from 'util'
import { AdminWebsocket, AppWebsocket, generateSigningKeyPair, setSigningCredentials } from '@holochain/client'
import { AdminWebsocket, AppWebsocket } from '@holochain/client'
import { defineStore } from 'pinia'
import { presentHcSignal, listify } from '../utils'
import useIsLoadingStore from './useIsLoadingStore'
import useSignalStore from './useSignalStore'
import { kycLevel2 } from '../services/hbs'
import { hposHolochainCall } from '../services/hpos'

const __HC_LAUNCHER_ENV__ = "__HC_LAUNCHER_ENV__";
const __HC_ZOME_CALL_SIGNER__ = "__HC_ZOME_CALL_SIGNER__";
const isLauncher = () => globalThis.window && __HC_LAUNCHER_ENV__ in globalThis.window;
const getLauncherEnvironment = () => isLauncher() ? globalThis.window[__HC_LAUNCHER_ENV__] : undefined;

const HC_APP_TIMEOUT = 35_000

const makeUseHolochainStore = ({ installed_app_id, app_ws_url, hc_admin_port }) => defineStore('holochain', {
Expand All @@ -15,7 +20,10 @@ const makeUseHolochainStore = ({ installed_app_id, app_ws_url, hc_admin_port })
// These two values are subscribed to by clientStore
appInfo: null,
isReady: false,
signingCredentials: null
isLauncherEnv: false,
adminWebsocketCache: null,
signingCredentialsCache: {}, // An installed app may have multiple cells, therefore we create a map of signing credentials per cell id
happConnectionCache: {}
}),
getters: {
isAnonymous: _ => false, // for compatibility with holo
Expand All @@ -26,12 +34,52 @@ const makeUseHolochainStore = ({ installed_app_id, app_ws_url, hc_admin_port })

async initialize() {
try {
const holochainClient = await AppWebsocket.connect(
app_ws_url,
HC_APP_TIMEOUT,
signal => useSignalStore().handleSignal(presentHcSignal(signal))
)
let happConnectionExpiration = this.happConnectionCache["expiresAt"];
let happConnectionToken = this.happConnectionCache["token"];
let launcherEnv = getLauncherEnvironment();

if (!!launcherEnv) {
this.isLauncherEnv = true;
if (!launcherEnv.APP_INTERFACE_TOKEN) {
console.warn(`Failed to locate the app interface token for app in launcher env: ${launcherEnv}`);
}
if (!launcherEnv.APP_INTERFACE_PORT) {
console.warn(`Failed to locate the app interface port for app in launcher env: ${launcherEnv}`);
}
this.happConnectionCache["token"] = launcherEnv.APP_INTERFACE_TOKEN;
happConnectionToken = launcherEnv.APP_INTERFACE_TOKEN;
app_ws_url = `ws:localhost:${launcherEnv.APP_INTERFACE_PORT}`
} else if (!happConnectionToken || !happConnectionExpiration || happConnectionExpiration <= Date.now()) {
if (!this.adminWebsocketCache) {
this.adminWebsocketCache = await AdminWebsocket.connect({
url: new URL(`ws:localhost:${hc_admin_port}`),
wsClientOptions: { origin: 'ui-common-lib' },
});
}
let adminWs = this.adminWebsocketCache;
const issuedToken = await adminWs.issueAppAuthenticationToken({
installed_app_id,
expiry_seconds: 0,
});

this.happConnectionCache["expiresAt"] = issuedToken.expires_at;
this.happConnectionCache["token"] = issuedToken.token;
happConnectionToken = issuedToken.token
}

console.log("app_ws_url : ", app_ws_url)
console.log("happConnectionToken : ", happConnectionToken)

holochainClient = await AppWebsocket.connect({
url: new URL(app_ws_url),
wsClientOptions: { origin: 'ui-common-lib' },
token: happConnectionToken, // do we need this for launcher?
defaultTimeout: HC_APP_TIMEOUT,
})

console.log("holochainClient : ", happConnectionToken)

holochainClient.on("signal", useSignalStore().handleSignal(presentHcSignal(signal)));
this.client = holochainClient

holochainClient.client.socket.onclose = function(e) {
Expand Down Expand Up @@ -98,13 +146,15 @@ const makeUseHolochainStore = ({ installed_app_id, app_ws_url, hc_admin_port })
throw new Error(`Couldn't find provisioned cell with role_name ${role_name}`)
}

if( !this.signingCredentials)
{
this.setCredentials(cellId)
if (!this.isLauncherEnv) {
if(!this.signingCredentialsCache[cellId])
{
this.setCredentials(cellId)
}

await this.signingCredentialsCache[cellId]
}

await this.signingCredentials

let result = null

const cell_id = [new Uint8Array(listify(cellId[0], (_, value) => (Number(value)))), new Uint8Array(listify(cellId[1], (_, value) => (Number(value))))]
Expand All @@ -127,9 +177,15 @@ const makeUseHolochainStore = ({ installed_app_id, app_ws_url, hc_admin_port })
return result
},
setCredentials(cellId) {
this.signingCredentials = new Promise(async (resolve, reject) => {
this.signingCredentialsCache[cellId] = new Promise(async (resolve, reject) => {
try {
const adminWs = await AdminWebsocket.connect(`ws:localhost:${hc_admin_port}`)
if (!this.adminWebsocketCache) {
this.adminWebsocketCache = await AdminWebsocket.connect({
url: new URL(`ws:localhost:${hc_admin_port}`),
wsClientOptions: { origin: 'ui-common-lib' },
});
}
let adminWs = this.adminWebsocketCache;
await adminWs.authorizeSigningCredentials(cellId)
} catch(e) {
console.log(`holochainCallZome error authorizeSigningCredentials AdminWebsocket: ws:localhost:${hc_admin_port}`, e)
Expand Down
105 changes: 104 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1976,6 +1976,21 @@
resolved "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==

"@bitgo/blake2b-wasm@^3.2.3":
version "3.2.3"
resolved "https://registry.yarnpkg.com/@bitgo/blake2b-wasm/-/blake2b-wasm-3.2.3.tgz#6ae5e942f2a5fd5b3ed27103af5df0ed50adfbc9"
integrity sha512-NaurBrMaEpjfg7EdUJgW/c6byt27O6q1ZaxB5Ita10MjjYjUu0SyYF4q7JPNxpHF/lMxb0YZakOxigbDBu9Jjw==
dependencies:
nanoassert "^1.0.0"

"@bitgo/blake2b@^3.2.4":
version "3.2.4"
resolved "https://registry.yarnpkg.com/@bitgo/blake2b/-/blake2b-3.2.4.tgz#6440992affdeabc22b2de8b8f381f51b551dd513"
integrity sha512-46PEgEVPxecNJ/xczggIllSxIkFIvvbVM0OfIDdNJ5qpFHUeBCkNIiGdzC3fYZlsv7bVTdUZOj79GcFBLMYBqA==
dependencies:
"@bitgo/blake2b-wasm" "^3.2.3"
nanoassert "^2.0.0"

"@cnakazawa/watch@^1.0.3":
version "1.0.4"
resolved "https://registry.npmjs.org/@cnakazawa/watch/-/watch-1.0.4.tgz"
Expand Down Expand Up @@ -2196,6 +2211,22 @@
lodash-es "^4.17.21"
tweetnacl "^1.0.3"

"@holochain/client@^0.18.0-dev.6":
version "0.18.0-dev.9"
resolved "https://registry.yarnpkg.com/@holochain/client/-/client-0.18.0-dev.9.tgz#9055bd8cbb8fb4cd80ff0056519d240d5881e16c"
integrity sha512-cVqSf5Ggr4Z07NdmWc/gIulk4U2Hxw9qmTN+qJr3/V1EhCAaUp3CLgoD3rDEGHTUuTKc3raXGXUcterX8OJbOg==
dependencies:
"@bitgo/blake2b" "^3.2.4"
"@holochain/serialization" "^0.1.0-beta-rc.3"
"@msgpack/msgpack" "^2.8.0"
"@spartan-hc/holo-hash" "^0.7.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"

"@holochain/serialization@^0.1.0-beta-rc.3":
version "0.1.0-beta-rc.3"
resolved "https://registry.yarnpkg.com/@holochain/serialization/-/serialization-0.1.0-beta-rc.3.tgz#787a785fa48e00f2d168c6d4b45a233c4800cccb"
Expand Down Expand Up @@ -2593,7 +2624,7 @@
resolved "https://registry.npmjs.org/@msgpack/msgpack/-/msgpack-2.7.1.tgz"
integrity sha512-ApwiSL2c9ObewdOE/sqt788P1C5lomBOHyO8nUBCr4ofErBCnYQ003NtJ8lS9OQZc11ximkbmgAZJjB8y6cCdA==

"@msgpack/msgpack@^2.7.1", "@msgpack/msgpack@^2.7.2":
"@msgpack/msgpack@^2.7.1", "@msgpack/msgpack@^2.7.2", "@msgpack/msgpack@^2.8.0":
version "2.8.0"
resolved "https://registry.yarnpkg.com/@msgpack/msgpack/-/msgpack-2.8.0.tgz#4210deb771ee3912964f14a15ddfb5ff877e70b9"
integrity sha512-h9u4u/jiIRKbq25PM+zymTyW6bhTzELvOoUd+AvYriWOAKpLGnIamaET3pnHYoI5iYphAHBI4ayx0MehR+VVPQ==
Expand Down Expand Up @@ -2676,6 +2707,13 @@
resolved "https://registry.npmjs.org/@soda/get-current-script/-/get-current-script-1.0.2.tgz"
integrity sha512-T7VNNlYVM1SgQ+VsMYhnDkcGmWhQdL0bDyGm5TlQ3GBXnJscEClUUOKduWTmm2zCnvNLC1hc3JpuXjs/nFOc5w==

"@spartan-hc/holo-hash@^0.7.0":
version "0.7.0"
resolved "https://registry.yarnpkg.com/@spartan-hc/holo-hash/-/holo-hash-0.7.0.tgz#076466fd51ac9860bab6d3fdeffc4dcb1b334abd"
integrity sha512-RtA+OXiteatppEvpGQ0WvAUf+MA5TLa/C8ota5S41W0xmKQfe9IQ9n/hTFRd0tBG4eYXfnz65TDDR1q3VIVOTw==
dependencies:
"@whi/xor-digest" "^0.1.0"

"@storybook/addon-a11y@^6.5.6":
version "6.5.9"
resolved "https://registry.yarnpkg.com/@storybook/addon-a11y/-/addon-a11y-6.5.9.tgz#191fb8ea9be4feee67fd11553b98ab56ecfc1295"
Expand Down Expand Up @@ -4889,6 +4927,11 @@
sprintf-js "^1.1.2"
winston "^3.3.3"

"@whi/xor-digest@^0.1.0":
version "0.1.0"
resolved "https://registry.yarnpkg.com/@whi/xor-digest/-/xor-digest-0.1.0.tgz#217f61705ebc07bae85ad93b18de3c1f65a440e0"
integrity sha512-FKPxyYK79TIxkVHmXnyJ4IljW+5sc+HX2hxMu5+UxlN0p1vOOdwFagDOhONC4ILysm1bXhvF4cPsTGSmlTKenQ==

"@xtuc/ieee754@^1.2.0":
version "1.2.0"
resolved "https://registry.npmjs.org/@xtuc/ieee754/-/ieee754-1.2.0.tgz"
Expand Down Expand Up @@ -5453,6 +5496,15 @@ axe-core@^4.2.0:
resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.4.2.tgz#dcf7fb6dea866166c3eab33d68208afe4d5f670c"
integrity sha512-LVAaGp/wkkgYJcjmHsoKx4juT1aQvJyPcW09MLCjVTh3V2cc6PnyempiLMNH5iMdfIX/zdbjUx2KDjMLCTdPeA==

axios@^1.4.0:
version "1.7.2"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.2.tgz#b625db8a7051fbea61c35a3cbb3a1daa7b9c7621"
integrity sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==
dependencies:
follow-redirects "^1.15.6"
form-data "^4.0.0"
proxy-from-env "^1.1.0"

babel-core@^7.0.0-bridge.0:
version "7.0.0-bridge.0"
resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-7.0.0-bridge.0.tgz#95a492ddd90f9b4e9a4a1da14eb335b87b634ece"
Expand Down Expand Up @@ -8837,6 +8889,11 @@ follow-redirects@^1.0.0:
resolved "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.4.tgz"
integrity sha512-zwGkiSXC1MUJG/qmeIFH2HBJx9u0V46QGUe3YR1fXG8bXQxq7fLj0RjLZQ5nubr9qNJUZrH+xUcwXEoXNpfS+g==

follow-redirects@^1.15.6:
version "1.15.6"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.6.tgz#7f815c0cda4249c74ff09e95ef97c23b5fd0399b"
integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==

for-in@^1.0.2:
version "1.0.2"
resolved "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz"
Expand Down Expand Up @@ -8888,6 +8945,15 @@ form-data@^3.0.0:
combined-stream "^1.0.8"
mime-types "^2.1.12"

form-data@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.8"
mime-types "^2.1.12"

form-data@~2.3.2:
version "2.3.3"
resolved "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz"
Expand Down Expand Up @@ -11264,6 +11330,11 @@ js-base64@^3.7.3:
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-3.7.5.tgz#21e24cf6b886f76d6f5f165bfcd69cc55b9e3fca"
integrity sha512-3MEt5DTINKqfScXKfJFrRbxkrnk2AxPWGBL/ycjz4dK8iqiSJ06UxD8jh8xuh6p10TX4t2+7FsBYVxxQbMg+qA==

js-base64@^3.7.5:
version "3.7.7"
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-3.7.7.tgz#e51b84bf78fbf5702b9541e2cb7bfcb893b43e79"
integrity sha512-7rCnleh0z2CkXhH67J8K1Ytz0b2Y+yxTPL+/KOJoa20hfnVQ/3/T6W/KflYI4bRHRagNeXeU2bkNGI3v1oS/lw==

[email protected]:
version "1.0.7"
resolved "https://registry.npmjs.org/js-message/-/js-message-1.0.7.tgz"
Expand Down Expand Up @@ -11602,6 +11673,18 @@ levn@~0.3.0:
prelude-ls "~1.1.2"
type-check "~0.3.2"

libsodium-wrappers@^0.7.13:
version "0.7.14"
resolved "https://registry.yarnpkg.com/libsodium-wrappers/-/libsodium-wrappers-0.7.14.tgz#b21d9e8d58de686c6318a772805ee1c5d02035a5"
integrity sha512-300TtsePizhJZ7HjLmWr6hLHAgJUxIGhapSw+EwfCtDuWaEmEdGXSQv6j6qFw0bs9l4vS2NH9BtOHfXAq6h5kQ==
dependencies:
libsodium "^0.7.14"

libsodium@^0.7.14:
version "0.7.14"
resolved "https://registry.yarnpkg.com/libsodium/-/libsodium-0.7.14.tgz#d9daace70dbc36051b947d37999bb6337c364c88"
integrity sha512-/pOd7eO6oZrfORquRTC4284OUJFcMi8F3Vnc9xtRBT0teLfOUxWIItaBFF3odYjZ7nlJNwnLdUVEUFHxVyX/Sw==

lines-and-columns@^1.1.6:
version "1.1.6"
resolved "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.1.6.tgz"
Expand Down Expand Up @@ -12395,6 +12478,16 @@ nan@^2.12.1:
resolved "https://registry.yarnpkg.com/nan/-/nan-2.16.0.tgz#664f43e45460fb98faf00edca0bb0d7b8dce7916"
integrity sha512-UdAqHyFngu7TfQKsCBgAA6pWDkT8MAO7d0jyOecVhN5354xbLqdn8mV9Tat9gepAupm0bt2DbeaSC8vS52MuFA==

nanoassert@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/nanoassert/-/nanoassert-1.1.0.tgz#4f3152e09540fde28c76f44b19bbcd1d5a42478d"
integrity sha512-C40jQ3NzfkP53NsO8kEOFd79p4b9kDXQMwgiY1z8ZwrDZgUyom0AHwGegF4Dm99L+YoYhuaB0ceerUcXmqr1rQ==

nanoassert@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/nanoassert/-/nanoassert-2.0.0.tgz#a05f86de6c7a51618038a620f88878ed1e490c09"
integrity sha512-7vO7n28+aYO4J+8w96AzhmU8G+Y/xpPDJz/se19ICsqj/momRbb9mh9ZUtkoJ5X3nTnPdhEJyc0qnM6yAsHBaA==

nanoid@^3.1.23:
version "3.1.25"
resolved "https://registry.npmjs.org/nanoid/-/nanoid-3.1.25.tgz"
Expand Down Expand Up @@ -14030,6 +14123,11 @@ proxy-addr@~2.0.5:
forwarded "0.2.0"
ipaddr.js "1.9.1"

proxy-from-env@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==

prr@~1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/prr/-/prr-1.0.1.tgz"
Expand Down Expand Up @@ -17714,6 +17812,11 @@ ws@^7.4.6:
resolved "https://registry.npmjs.org/ws/-/ws-7.5.5.tgz"
integrity sha512-BAkMFcAzl8as1G/hArkxOxq3G7pjUqQ3gzYbLL0/5zNkph70e+lCoxBGnm6AW1+/aiNeV4fnKqZ8m4GZewmH2w==

ws@^8.14.2:
version "8.18.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.18.0.tgz#0d7505a6eafe2b0e712d232b42279f53bc289bbc"
integrity sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==

ws@^8.2.3:
version "8.8.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.8.0.tgz#8e71c75e2f6348dbf8d78005107297056cb77769"
Expand Down
Loading