From dc61d65e87d3903d62e3f458e5927d028c736952 Mon Sep 17 00:00:00 2001 From: Robbie Carlton Date: Tue, 11 Jun 2024 16:40:31 -0600 Subject: [PATCH 1/6] Add provideMemproofs endpoint and allowEmailPasswordAuth config --- CHANGELOG.md | 5 +++++ src/index.ts | 32 +++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2babdc0..be3000a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [unreleased] + +### Added +- provideMemproofs endpoint + ## [0.6.19-prerelease] - 2024-03-26 ### Updated diff --git a/src/index.ts b/src/index.ts index f9a5840..c75d306 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,11 @@ import Emittery from "emittery" import semverSatisfies from 'semver/functions/satisfies' -import { AppInfoResponse, AppAgentClient, AppAgentCallZomeRequest, AppCreateCloneCellRequest, CreateCloneCellResponse, AgentPubKey, AppEnableCloneCellRequest, AppDisableCloneCellRequest, EnableCloneCellResponse, DisableCloneCellResponse, AppSignal, decodeHashFromBase64, NetworkInfoResponse, AppAgentNetworkInfoRequest } from '@holochain/client' +import { + AppInfoResponse, AppAgentClient, AppAgentCallZomeRequest, AppCreateCloneCellRequest, CreateCloneCellResponse, AgentPubKey, AppEnableCloneCellRequest, + AppDisableCloneCellRequest, EnableCloneCellResponse, DisableCloneCellResponse, AppSignal, decodeHashFromBase64, NetworkInfoResponse, NetworkInfoRequest +} from '@holochain/client' -const COMPATIBLE_CHAPERONE_VERSION = '>=0.1.1 <0.3.0' +const COMPATIBLE_CHAPERONE_VERSION = '>=0.1.1 <0.3.0' // TODO: update const TESTING = (global).COMB !== undefined if (!TESTING) { @@ -96,6 +99,15 @@ class WebSdkApi implements AppAgentClient { if (authOpts.requireRegistrationCode !== undefined) { url.searchParams.set('require_registration_code', String(authOpts.requireRegistrationCode)) } + + if (authOpts.integrationTestMode !== undefined) { + url.searchParams.set('integration_test_mode', String(authOpts.integrationTestMode)) + } + + if (authOpts.allowEmailPasswordAuth !== undefined) { + url.searchParams.set('allow_email_password_auth', String(authOpts.allowEmailPasswordAuth)) + } + // INTERNAL OPTION // anonymous_allowed is barely implemented in Chaperone, and is subject to change, // so exposing this in the documentation is misleading. @@ -103,10 +115,6 @@ class WebSdkApi implements AppAgentClient { if (authOpts.anonymousAllowed !== undefined) { url.searchParams.set('anonymous_allowed', String(authOpts.anonymousAllowed)) } - - if (authOpts.integrationTestMode !== undefined) { - url.searchParams.set('integration_test_mode', String(authOpts.integrationTestMode)) - } } let child @@ -192,7 +200,7 @@ class WebSdkApi implements AppAgentClient { appInfo = (): Promise => this.#child.call('appInfo') - networkInfo = (args: AppAgentNetworkInfoRequest): Promise => this.#child.call('networkInfo', args) + networkInfo = (args: NetworkInfoRequest): Promise => this.#child.call('networkInfo', args) callZome = async (args: AppAgentCallZomeRequest): Promise => this.#child.call('callZome', args).then(unwrap) @@ -202,6 +210,8 @@ class WebSdkApi implements AppAgentClient { enableCloneCell = (args: AppEnableCloneCellRequest): Promise => this.#child.call('enableCloneCell', args).then(unwrap) + provideMemproofs = (args: ProvideMemproofsRequest): Promise => this.#child.call('provideMemproofs', args).then(unwrap) + signPayload = (args: any): Promise => this.#child.call('signPayload', args).then(unwrap) stateDump = () => this.#child.call('stateDump') @@ -269,7 +279,15 @@ export type ChaperoneState = { // DUPLICATION END +// TODO: once holochain js client is up to date with the latest holochain, we should use the types from there instead of these two ProvideMemproofs types +type ProvideMemproofsRequest = { + memproof_maps: { [key: string]: string; } +} + +type ProvideMemproofsResponse = void + type AuthFormCustomization = { + allowEmailPasswordAuth?: boolean // The name of the hosted hApp. Currently shows up as "appName Login" appName?: string // The URL of the hApp logo. Currently displayed on a white background with no `width` or `height` constraints. From ae4351efc37613525f05cf4ac35ab71badaa012f Mon Sep 17 00:00:00 2001 From: Robbie Carlton Date: Tue, 11 Jun 2024 16:41:17 -0600 Subject: [PATCH 2/6] Changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be3000a..b0faa6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] ### Added -- provideMemproofs endpoint +- `provideMemproofs` endpoint +- `allowEmailPasswordAuth` authOpts fields ## [0.6.19-prerelease] - 2024-03-26 From 811a945073738a728d915612ef9a6161cf733868 Mon Sep 17 00:00:00 2001 From: Robbie Carlton Date: Wed, 12 Jun 2024 11:22:34 -0600 Subject: [PATCH 3/6] update holochain/client --- package.json | 2 +- src/index.ts | 18 +++++++----------- yarn.lock | 26 ++++++++++---------------- 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index 45472c2..0a462f5 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ }, "dependencies": { "@holo-host/comb": "0.3.2", - "@holochain/client": "0.16.10", + "@holochain/client": "^0.18.0-dev.2", "buffer": "^6.0.3", "crypto-browserify": "^3.12.0", "semver": "^7.5.1", diff --git a/src/index.ts b/src/index.ts index c75d306..38c6019 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,10 @@ import Emittery from "emittery" import semverSatisfies from 'semver/functions/satisfies' import { - AppInfoResponse, AppAgentClient, AppAgentCallZomeRequest, AppCreateCloneCellRequest, CreateCloneCellResponse, AgentPubKey, AppEnableCloneCellRequest, - AppDisableCloneCellRequest, EnableCloneCellResponse, DisableCloneCellResponse, AppSignal, decodeHashFromBase64, NetworkInfoResponse, NetworkInfoRequest + AppInfoResponse, AppClient, AppCallZomeRequest, AppCreateCloneCellRequest, CreateCloneCellResponse, AgentPubKey, AppEnableCloneCellRequest, + AppDisableCloneCellRequest, EnableCloneCellResponse, DisableCloneCellResponse, AppSignal, decodeHashFromBase64, NetworkInfoResponse, NetworkInfoRequest, + ProvideMemproofsRequest, + ProvideMemproofsResponse } from '@holochain/client' const COMPATIBLE_CHAPERONE_VERSION = '>=0.1.1 <0.3.0' // TODO: update @@ -28,7 +30,7 @@ function checkChaperoneVersion (chaperoneVersion) { * A `WebSdkApi` is a connection to a Chaperone iframe containing Holo's client logic. * @param child - The child process connecting to Chaperone that is being monitored. */ -class WebSdkApi implements AppAgentClient { +class WebSdkApi implements AppClient { // Private constructor. Use `connect` instead. #child: any; agentState: AgentState; @@ -40,6 +42,7 @@ class WebSdkApi implements AppAgentClient { #cancellable: boolean; #emitter = new Emittery(); myPubKey: AgentPubKey; + installedAppId: string; // this is to conform with the `AppClient` interface and as never used in web-sdk constructor (child) { this.#child = child @@ -202,7 +205,7 @@ class WebSdkApi implements AppAgentClient { networkInfo = (args: NetworkInfoRequest): Promise => this.#child.call('networkInfo', args) - callZome = async (args: AppAgentCallZomeRequest): Promise => this.#child.call('callZome', args).then(unwrap) + callZome = async (args: AppCallZomeRequest): Promise => this.#child.call('callZome', args).then(unwrap) createCloneCell = (args: AppCreateCloneCellRequest): Promise => this.#child.call('createCloneCell', args).then(unwrap) @@ -279,13 +282,6 @@ export type ChaperoneState = { // DUPLICATION END -// TODO: once holochain js client is up to date with the latest holochain, we should use the types from there instead of these two ProvideMemproofs types -type ProvideMemproofsRequest = { - memproof_maps: { [key: string]: string; } -} - -type ProvideMemproofsResponse = void - type AuthFormCustomization = { allowEmailPasswordAuth?: boolean // The name of the hosted hApp. Currently shows up as "appName Login" diff --git a/yarn.lock b/yarn.lock index 9f4857e..6feaf3b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1153,15 +1153,14 @@ resolved "https://registry.yarnpkg.com/@holo-host/wasm-key-manager/-/wasm-key-manager-1.0.0.tgz#32e5365ddc4518a01c17d2aba09d11bf3a042429" integrity sha512-GTfeQ2iYvYYrIkuaF0QupWP/y8sdItwL6Tr1osyaU7eUsWtGfpZqDcTZny8KNDdnQAEEP2nDWZORA/Z3EMJa3w== -"@holochain/client@0.16.10": - version "0.16.10" - resolved "https://registry.yarnpkg.com/@holochain/client/-/client-0.16.10.tgz#7ef9019922edfea4ceda7bb8d3eaae7beddc98e3" - integrity sha512-Urgx6vXNux2XD/4+eOxou2FKwlUBu/g/BxUSZLX6wEaYWH9wDYXR5f3VToUrAhXGF5ssc08jb8jLiQZ23k62EQ== +"@holochain/client@^0.18.0-dev.2": + version "0.18.0-dev.2" + resolved "https://registry.yarnpkg.com/@holochain/client/-/client-0.18.0-dev.2.tgz#59d39060b1b258e2cebcab39b87f6fabd54ea75a" + integrity sha512-SpmGdmyRZlWg9TBoXCdqoU65xb7ScpWXYpTwnTu8Ppe43Q+KbFzgTBlpsWNJI28hIVDEWh0I9xVS4kNPKa4plw== dependencies: "@bitgo/blake2b" "^3.2.4" "@holochain/serialization" "^0.1.0-beta-rc.3" "@msgpack/msgpack" "^2.8.0" - "@tauri-apps/api" "^1.4.0" emittery "^1.0.1" isomorphic-ws "^5.0.0" js-base64 "^3.7.5" @@ -1284,11 +1283,6 @@ resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.27.8.tgz#6667fac16c436b5434a387a34dedb013198f6e6e" integrity sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA== -"@tauri-apps/api@^1.4.0": - version "1.5.3" - resolved "https://registry.yarnpkg.com/@tauri-apps/api/-/api-1.5.3.tgz#f7b362b1f30aadb0a8bbeb7ae111755c0ed33d73" - integrity sha512-zxnDjHHKjOsrIzZm6nO5Xapb/BxqUq1tc7cGkFXsFkGTsSWgCPH1D8mm0XS9weJY2OaR73I3k3S+b7eSzJDfqA== - "@tootallnate/once@2": version "2.0.0" resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-2.0.0.tgz#f544a148d3ab35801c1f633a7441fd87c2e484bf" @@ -2402,9 +2396,9 @@ elliptic@^6.5.3, elliptic@^6.5.5: minimalistic-crypto-utils "^1.0.1" emittery@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/emittery/-/emittery-1.0.1.tgz#e0cf36e2d7eef94dbd025969f642d57ae50a56cd" - integrity sha512-2ID6FdrMD9KDLldGesP6317G78K7km/kMcwItRtVFva7I/cSEOIaLpewaUb+YLXVwdAp3Ctfxh/V5zIl1sj7dQ== + version "1.0.3" + resolved "https://registry.yarnpkg.com/emittery/-/emittery-1.0.3.tgz#c9d2a9c689870f15251bb13b31c67715c26d69ac" + integrity sha512-tJdCJitoy2lrC2ldJcqN4vkqJ00lT+tOWNT1hBJjO/3FDMJa5TTIiYGCKGkn/WfCyOzUMObeohbVTj00fhiLiA== emojis-list@^3.0.0: version "3.0.0" @@ -4302,9 +4296,9 @@ ws@^8.13.0: integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA== ws@^8.14.2: - version "8.16.0" - resolved "https://registry.yarnpkg.com/ws/-/ws-8.16.0.tgz#d1cd774f36fbc07165066a60e40323eab6446fd4" - integrity sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ== + version "8.17.0" + resolved "https://registry.yarnpkg.com/ws/-/ws-8.17.0.tgz#d145d18eca2ed25aaf791a183903f7be5e295fea" + integrity sha512-uJq6108EgZMAl20KagGkzCKfMEjxmKvZHG7Tlq0Z6nOky7YF7aq4mOx6xK8TJ/i1LeK4Qus7INktacctDgY8Ow== xml-name-validator@^4.0.0: version "4.0.0" From b17e79cbe1af061b99a062ea37d2f34a2a907b93 Mon Sep 17 00:00:00 2001 From: Robbie Carlton Date: Fri, 5 Jul 2024 13:28:26 -0600 Subject: [PATCH 4/6] add awaitingMemproofs --- CHANGELOG.md | 1 + src/index.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0faa6e..bd6f89d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - `provideMemproofs` endpoint - `allowEmailPasswordAuth` authOpts fields +- `hasMemproofs` field in `AgentState` ## [0.6.19-prerelease] - 2024-03-26 diff --git a/src/index.ts b/src/index.ts index 38c6019..67b02df 100644 --- a/src/index.ts +++ b/src/index.ts @@ -265,6 +265,7 @@ export type AgentState = { isAnonymous: boolean hostUrl: string isAvailable: boolean + hasMemproofs: boolean unrecoverableError: any } From 1f1d90e0cfa39703b3bd950fc0ebc62578a1bc6e Mon Sep 17 00:00:00 2001 From: Robbie Carlton Date: Tue, 9 Jul 2024 19:02:58 -0600 Subject: [PATCH 5/6] switch direction of version passing --- CHANGELOG.md | 4 ++++ src/index.ts | 17 +++-------------- webpack.config.js | 7 +++++++ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd6f89d..65257f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `provideMemproofs` endpoint - `allowEmailPasswordAuth` authOpts fields - `hasMemproofs` field in `AgentState` +- `websdk_version` is now passed with authOpts to chaperone + +### Removed +- chaperone version check ## [0.6.19-prerelease] - 2024-03-26 diff --git a/src/index.ts b/src/index.ts index 67b02df..671090d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,4 @@ import Emittery from "emittery" -import semverSatisfies from 'semver/functions/satisfies' import { AppInfoResponse, AppClient, AppCallZomeRequest, AppCreateCloneCellRequest, CreateCloneCellResponse, AgentPubKey, AppEnableCloneCellRequest, AppDisableCloneCellRequest, EnableCloneCellResponse, DisableCloneCellResponse, AppSignal, decodeHashFromBase64, NetworkInfoResponse, NetworkInfoRequest, @@ -7,8 +6,6 @@ import { ProvideMemproofsResponse } from '@holochain/client' -const COMPATIBLE_CHAPERONE_VERSION = '>=0.1.1 <0.3.0' // TODO: update - const TESTING = (global).COMB !== undefined if (!TESTING) { if (typeof window !== "undefined") (window).COMB = require('@holo-host/comb').COMB @@ -18,14 +15,6 @@ function makeUrlAbsolute (url) { return new URL(url, window.location.href).href } -function checkChaperoneVersion (chaperoneVersion) { - const isSatisfied = semverSatisfies(chaperoneVersion, COMPATIBLE_CHAPERONE_VERSION) - - if (!isSatisfied) { - console.error(`!!!!! WARNING: you are connecting to an unsupported version of Chaperone. Expected version matching: ${COMPATIBLE_CHAPERONE_VERSION}. Actual version: ${chaperoneVersion} !!!!!`) - } -} - /** * A `WebSdkApi` is a connection to a Chaperone iframe containing Holo's client logic. * @param child - The child process connecting to Chaperone that is being monitored. @@ -79,6 +68,8 @@ class WebSdkApi implements AppClient { }: { chaperoneUrl: string, authFormCustomization?: AuthFormCustomization }) => { const url = new URL(chaperoneUrl || 'https://chaperone.holo.hosting') + url.searchParams.set('websdk_version', process.env.VERSION) + if (authOpts !== undefined) { if (authOpts.logoUrl !== undefined) { url.searchParams.set('logo_url', makeUrlAbsolute(authOpts.logoUrl)) @@ -157,12 +148,10 @@ class WebSdkApi implements AppClient { // Chaperone either returns agent_state and happ_id (success case) // or error_message - const { error_message, chaperone_state, happ_id, chaperone_version } = await child.call( + const { error_message, chaperone_state, happ_id } = await child.call( 'handshake' ) - checkChaperoneVersion(chaperone_version) - if (error_message) { webSdkApi.#iframe.style.display = 'none' throw new Error(error_message) diff --git a/webpack.config.js b/webpack.config.js index 8e361b4..3a8e229 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,3 +1,5 @@ +const PACKAGE = require('./package.json') + module.exports = { target: "web", mode: 'development', // production | development @@ -41,5 +43,10 @@ module.exports = { }, plugins: [ + new webpack.DefinePlugin({ + 'process.env':{ + 'VERSION': `'${PACKAGE.version}'`, + }, + }), ], }; From 30ff8c550d7564a89ef0475497b197fc178a6a26 Mon Sep 17 00:00:00 2001 From: Robbie Carlton Date: Tue, 9 Jul 2024 19:09:00 -0600 Subject: [PATCH 6/6] fix config --- webpack.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/webpack.config.js b/webpack.config.js index 3a8e229..e43c6b4 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,4 +1,5 @@ const PACKAGE = require('./package.json') +const webpack = require('webpack') module.exports = { target: "web",