From 7f5a0366f3392833d676e23ac05cfbc07ac259cd Mon Sep 17 00:00:00 2001 From: Jost Schulte <28270981+jost-s@users.noreply.github.com> Date: Thu, 21 Nov 2024 12:55:02 -0600 Subject: [PATCH] fix(app-ws): bring back cap_secret as zome call param (#296) Co-authored-by: Jost Schulte --- docs/client.appcallzomerequest.md | 4 +- ...nt.callzomerequestallparams.cap_secret.md} | 4 +- ...nt.callzomerequestallparams.expires_at.md} | 4 +- ....md => client.callzomerequestallparams.md} | 12 +++--- ... client.callzomerequestallparams.nonce.md} | 4 +- docs/client.md | 2 +- src/api/app/types.ts | 5 ++- src/api/app/websocket.ts | 4 +- src/environments/launcher.ts | 7 +++- test/e2e/app-websocket.ts | 3 +- test/e2e/index.ts | 39 +++++++++++++++++++ 11 files changed, 65 insertions(+), 23 deletions(-) rename docs/{client.callzomerequestparams.cap_secret.md => client.callzomerequestallparams.cap_secret.md} (52%) rename docs/{client.callzomerequestparams.expires_at.md => client.callzomerequestallparams.expires_at.md} (51%) rename docs/{client.callzomerequestparams.md => client.callzomerequestallparams.md} (60%) rename docs/{client.callzomerequestparams.nonce.md => client.callzomerequestallparams.nonce.md} (53%) diff --git a/docs/client.appcallzomerequest.md b/docs/client.appcallzomerequest.md index be64897d..9d6c7f07 100644 --- a/docs/client.appcallzomerequest.md +++ b/docs/client.appcallzomerequest.md @@ -8,7 +8,7 @@ **Signature:** ```typescript -export type AppCallZomeRequest = NonProvenanceCallZomeRequest | RoleNameCallZomeRequest | CallZomeRequest; +export type AppCallZomeRequest = NonProvenanceCallZomeRequest | RoleNameCallZomeRequest | CallZomeRequest | CallZomeRequestAllParams; ``` -**References:** [NonProvenanceCallZomeRequest](./client.nonprovenancecallzomerequest.md), [RoleNameCallZomeRequest](./client.rolenamecallzomerequest.md), [CallZomeRequest](./client.callzomerequest.md) +**References:** [NonProvenanceCallZomeRequest](./client.nonprovenancecallzomerequest.md), [RoleNameCallZomeRequest](./client.rolenamecallzomerequest.md), [CallZomeRequest](./client.callzomerequest.md), [CallZomeRequestAllParams](./client.callzomerequestallparams.md) diff --git a/docs/client.callzomerequestparams.cap_secret.md b/docs/client.callzomerequestallparams.cap_secret.md similarity index 52% rename from docs/client.callzomerequestparams.cap_secret.md rename to docs/client.callzomerequestallparams.cap_secret.md index 8bc8b6e0..600f900a 100644 --- a/docs/client.callzomerequestparams.cap_secret.md +++ b/docs/client.callzomerequestallparams.cap_secret.md @@ -1,8 +1,8 @@ -[Home](./index.md) > [@holochain/client](./client.md) > [CallZomeRequestParams](./client.callzomerequestparams.md) > [cap\_secret](./client.callzomerequestparams.cap_secret.md) +[Home](./index.md) > [@holochain/client](./client.md) > [CallZomeRequestAllParams](./client.callzomerequestallparams.md) > [cap\_secret](./client.callzomerequestallparams.cap_secret.md) -## CallZomeRequestParams.cap\_secret property +## CallZomeRequestAllParams.cap\_secret property **Signature:** diff --git a/docs/client.callzomerequestparams.expires_at.md b/docs/client.callzomerequestallparams.expires_at.md similarity index 51% rename from docs/client.callzomerequestparams.expires_at.md rename to docs/client.callzomerequestallparams.expires_at.md index 8b469cf6..d7e12acc 100644 --- a/docs/client.callzomerequestparams.expires_at.md +++ b/docs/client.callzomerequestallparams.expires_at.md @@ -1,8 +1,8 @@ -[Home](./index.md) > [@holochain/client](./client.md) > [CallZomeRequestParams](./client.callzomerequestparams.md) > [expires\_at](./client.callzomerequestparams.expires_at.md) +[Home](./index.md) > [@holochain/client](./client.md) > [CallZomeRequestAllParams](./client.callzomerequestallparams.md) > [expires\_at](./client.callzomerequestallparams.expires_at.md) -## CallZomeRequestParams.expires\_at property +## CallZomeRequestAllParams.expires\_at property **Signature:** diff --git a/docs/client.callzomerequestparams.md b/docs/client.callzomerequestallparams.md similarity index 60% rename from docs/client.callzomerequestparams.md rename to docs/client.callzomerequestallparams.md index 4222eb87..05e03f14 100644 --- a/docs/client.callzomerequestparams.md +++ b/docs/client.callzomerequestallparams.md @@ -1,14 +1,14 @@ -[Home](./index.md) > [@holochain/client](./client.md) > [CallZomeRequestParams](./client.callzomerequestparams.md) +[Home](./index.md) > [@holochain/client](./client.md) > [CallZomeRequestAllParams](./client.callzomerequestallparams.md) -## CallZomeRequestParams interface +## CallZomeRequestAllParams interface **Signature:** ```typescript -export interface CallZomeRequestParams extends CallZomeRequest +export interface CallZomeRequestAllParams extends CallZomeRequest ``` **Extends:** [CallZomeRequest](./client.callzomerequest.md) @@ -37,7 +37,7 @@ Description -[cap\_secret](./client.callzomerequestparams.cap_secret.md) +[cap\_secret](./client.callzomerequestallparams.cap_secret.md) @@ -54,7 +54,7 @@ Description -[expires\_at](./client.callzomerequestparams.expires_at.md) +[expires\_at](./client.callzomerequestallparams.expires_at.md) @@ -71,7 +71,7 @@ number -[nonce](./client.callzomerequestparams.nonce.md) +[nonce](./client.callzomerequestallparams.nonce.md) diff --git a/docs/client.callzomerequestparams.nonce.md b/docs/client.callzomerequestallparams.nonce.md similarity index 53% rename from docs/client.callzomerequestparams.nonce.md rename to docs/client.callzomerequestallparams.nonce.md index 64617cd6..7a5e761d 100644 --- a/docs/client.callzomerequestparams.nonce.md +++ b/docs/client.callzomerequestallparams.nonce.md @@ -1,8 +1,8 @@ -[Home](./index.md) > [@holochain/client](./client.md) > [CallZomeRequestParams](./client.callzomerequestparams.md) > [nonce](./client.callzomerequestparams.nonce.md) +[Home](./index.md) > [@holochain/client](./client.md) > [CallZomeRequestAllParams](./client.callzomerequestallparams.md) > [nonce](./client.callzomerequestallparams.nonce.md) -## CallZomeRequestParams.nonce property +## CallZomeRequestAllParams.nonce property **Signature:** diff --git a/docs/client.md b/docs/client.md index 272053aa..1d24ebe0 100644 --- a/docs/client.md +++ b/docs/client.md @@ -594,7 +594,7 @@ Description -[CallZomeRequestParams](./client.callzomerequestparams.md) +[CallZomeRequestAllParams](./client.callzomerequestallparams.md) diff --git a/src/api/app/types.ts b/src/api/app/types.ts index 54706fc9..5bf5822a 100644 --- a/src/api/app/types.ts +++ b/src/api/app/types.ts @@ -55,7 +55,8 @@ export type RoleNameCallZomeRequestSigned = Omit< export type AppCallZomeRequest = | NonProvenanceCallZomeRequest | RoleNameCallZomeRequest - | CallZomeRequest; + | CallZomeRequest + | CallZomeRequestAllParams; /** * @public @@ -90,7 +91,7 @@ export interface AppEvents { /** * @public */ -export interface CallZomeRequestParams extends CallZomeRequest { +export interface CallZomeRequestAllParams extends CallZomeRequest { cap_secret: CapSecret | null; nonce: Nonce256Bit; expires_at: number; diff --git a/src/api/app/websocket.ts b/src/api/app/websocket.ts index eca32319..4456db63 100644 --- a/src/api/app/websocket.ts +++ b/src/api/app/websocket.ts @@ -30,7 +30,7 @@ import { SignalCb, CallZomeRequest, CallZomeRequestSigned, - CallZomeRequestParams, + CallZomeRequestAllParams, CallZomeResponse, CallZomeResponseGeneric, CreateCloneCellRequest, @@ -603,7 +603,7 @@ export const signZomeCall = async (request: CallZomeRequest) => { )}, ${encodeHashToBase64(request.cell_id[1])}]` ); } - const unsignedZomeCallPayload: CallZomeRequestParams = { + const unsignedZomeCallPayload: CallZomeRequestAllParams = { cap_secret: signingCredentialsForCell.capSecret, cell_id: request.cell_id, zome_name: request.zome_name, diff --git a/src/environments/launcher.ts b/src/environments/launcher.ts index 4a3d780c..51e7b8a0 100644 --- a/src/environments/launcher.ts +++ b/src/environments/launcher.ts @@ -1,5 +1,8 @@ import { AppAuthenticationToken, CallZomeRequest } from "../api/index.js"; -import { CallZomeRequestSigned, CallZomeRequestParams } from "../api/index.js"; +import { + CallZomeRequestSigned, + CallZomeRequestAllParams, +} from "../api/index.js"; import { InstalledAppId } from "../types.js"; export interface LauncherEnvironment { @@ -58,7 +61,7 @@ interface CallZomeRequestSignedElectron interface CallZomeRequestUnsignedElectron extends Omit< - CallZomeRequestParams, + CallZomeRequestAllParams, | "cap_secret" | "cell_id" | "provenance" diff --git a/test/e2e/app-websocket.ts b/test/e2e/app-websocket.ts index 794e6faa..2176c7cd 100644 --- a/test/e2e/app-websocket.ts +++ b/test/e2e/app-websocket.ts @@ -3,10 +3,9 @@ import test from "tape"; import { AdminWebsocket, AppCallZomeRequest, - AppWebsocket, AppCreateCloneCellRequest, AppEntryDef, - AppSignal, + AppWebsocket, CellType, CloneId, fakeAgentPubKey, diff --git a/test/e2e/index.ts b/test/e2e/index.ts index 5c4fdcc8..309c1b12 100644 --- a/test/e2e/index.ts +++ b/test/e2e/index.ts @@ -29,6 +29,10 @@ import { SignalType, Signal, isSameCell, + CallZomeRequestAllParams, + getSigningCredentials, + randomNonce, + getNonceExpiration, } from "../../src"; import { FIXTURE_PATH, @@ -402,6 +406,41 @@ test( }) ); +test( + "can call a zome function with different sets of params", + withConductor(ADMIN_PORT, async (t) => { + const { cell_id, client, admin } = await installAppAndDna(ADMIN_PORT); + await admin.authorizeSigningCredentials(cell_id); + + const request: CallZomeRequest = { + cell_id, + zome_name: TEST_ZOME_NAME, + fn_name: "foo", + provenance: cell_id[1], + payload: null, + }; + let response = await client.callZome(request, 30000); + t.equal(response, "foo", "zome can be called with all parameters"); + + const cap_secret = getSigningCredentials(cell_id)?.capSecret; + assert(cap_secret); + + const zomeCallPayload: CallZomeRequestAllParams = { + cell_id, + zome_name: TEST_ZOME_NAME, + fn_name: "foo", + provenance: cell_id[1], + payload: null, + cap_secret, + nonce: await randomNonce(), + expires_at: getNonceExpiration(), + }; + + response = await client.callZome(zomeCallPayload, 30000); + t.equal(response, "foo", "zome can be called with all parameters"); + }) +); + test( "can call attachAppInterface without specific port", withConductor(ADMIN_PORT, async (t) => {