diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e460511..9ada2ff9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added ### Fixed ### Changed +- Simplify zome call parameters. `cap_secret`, `provenance` and `payload` are optional parameters of a `CallZomeRequest`. If implicit zome call signing is used, which happens when calling a zome with a `CallZomeRequest`, `provenance` and `cap_secret` are automatically set with the authorized signing credentials. It is still possible to call a cell by its role name instead of its cell id. Alternatively to passing in a `CallZomeRequest`, `callZome` can be invoked with a signed request `CallZomeRequestSigned`, where the zome call parameters have already been serialized and signed. ### Removed ## 2024-11-21: v0.19.0-dev.4 diff --git a/docs/client.appcallzomerequest.md b/docs/client.appcallzomerequest.md deleted file mode 100644 index 9d6c7f07..00000000 --- a/docs/client.appcallzomerequest.md +++ /dev/null @@ -1,14 +0,0 @@ - - -[Home](./index.md) > [@holochain/client](./client.md) > [AppCallZomeRequest](./client.appcallzomerequest.md) - -## AppCallZomeRequest type - - -**Signature:** - -```typescript -export type AppCallZomeRequest = NonProvenanceCallZomeRequest | RoleNameCallZomeRequest | CallZomeRequest | CallZomeRequestAllParams; -``` -**References:** [NonProvenanceCallZomeRequest](./client.nonprovenancecallzomerequest.md), [RoleNameCallZomeRequest](./client.rolenamecallzomerequest.md), [CallZomeRequest](./client.callzomerequest.md), [CallZomeRequestAllParams](./client.callzomerequestallparams.md) - diff --git a/docs/client.appclient.callzome.md b/docs/client.appclient.callzome.md index b47dc9fc..15519070 100644 --- a/docs/client.appclient.callzome.md +++ b/docs/client.appclient.callzome.md @@ -7,7 +7,7 @@ **Signature:** ```typescript -callZome(args: AppCallZomeRequest, timeout?: number): Promise; +callZome(args: CallZomeRequest | RoleNameCallZomeRequest, timeout?: number): Promise; ``` ## Parameters @@ -35,7 +35,7 @@ args -[AppCallZomeRequest](./client.appcallzomerequest.md) +[CallZomeRequest](./client.callzomerequest.md) \| [RoleNameCallZomeRequest](./client.rolenamecallzomerequest.md) diff --git a/docs/client.appwebsocket.callzome.md b/docs/client.appwebsocket.callzome.md index 72ebf95d..f8b96620 100644 --- a/docs/client.appwebsocket.callzome.md +++ b/docs/client.appwebsocket.callzome.md @@ -9,7 +9,7 @@ Call a zome. **Signature:** ```typescript -callZome(request: AppCallZomeRequest, timeout?: number): Promise; +callZome(request: CallZomeRequest | RoleNameCallZomeRequest, timeout?: number): Promise; ``` ## Parameters @@ -37,7 +37,7 @@ request -[AppCallZomeRequest](./client.appcallzomerequest.md) +[CallZomeRequest](./client.callzomerequest.md) \| [RoleNameCallZomeRequest](./client.rolenamecallzomerequest.md) diff --git a/docs/client.callzomerequestallparams.cap_secret.md b/docs/client.callzomerequestallparams.cap_secret.md deleted file mode 100644 index 600f900a..00000000 --- a/docs/client.callzomerequestallparams.cap_secret.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [@holochain/client](./client.md) > [CallZomeRequestAllParams](./client.callzomerequestallparams.md) > [cap\_secret](./client.callzomerequestallparams.cap_secret.md) - -## CallZomeRequestAllParams.cap\_secret property - -**Signature:** - -```typescript -cap_secret: CapSecret | null; -``` diff --git a/docs/client.callzomerequestallparams.expires_at.md b/docs/client.callzomerequestallparams.expires_at.md deleted file mode 100644 index d7e12acc..00000000 --- a/docs/client.callzomerequestallparams.expires_at.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [@holochain/client](./client.md) > [CallZomeRequestAllParams](./client.callzomerequestallparams.md) > [expires\_at](./client.callzomerequestallparams.expires_at.md) - -## CallZomeRequestAllParams.expires\_at property - -**Signature:** - -```typescript -expires_at: number; -``` diff --git a/docs/client.callzomerequestallparams.md b/docs/client.callzomerequestallparams.md deleted file mode 100644 index 05e03f14..00000000 --- a/docs/client.callzomerequestallparams.md +++ /dev/null @@ -1,89 +0,0 @@ - - -[Home](./index.md) > [@holochain/client](./client.md) > [CallZomeRequestAllParams](./client.callzomerequestallparams.md) - -## CallZomeRequestAllParams interface - - -**Signature:** - -```typescript -export interface CallZomeRequestAllParams extends CallZomeRequest -``` -**Extends:** [CallZomeRequest](./client.callzomerequest.md) - -## Properties - - - - - -
- -Property - - - - -Modifiers - - - - -Type - - - - -Description - - -
- -[cap\_secret](./client.callzomerequestallparams.cap_secret.md) - - - - - - - -[CapSecret](./client.capsecret.md) \| null - - - - - -
- -[expires\_at](./client.callzomerequestallparams.expires_at.md) - - - - - - - -number - - - - - -
- -[nonce](./client.callzomerequestallparams.nonce.md) - - - - - - - -[Nonce256Bit](./client.nonce256bit.md) - - - - - -
diff --git a/docs/client.callzomerequestallparams.nonce.md b/docs/client.callzomerequestallparams.nonce.md deleted file mode 100644 index 7a5e761d..00000000 --- a/docs/client.callzomerequestallparams.nonce.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [@holochain/client](./client.md) > [CallZomeRequestAllParams](./client.callzomerequestallparams.md) > [nonce](./client.callzomerequestallparams.nonce.md) - -## CallZomeRequestAllParams.nonce property - -**Signature:** - -```typescript -nonce: Nonce256Bit; -``` diff --git a/docs/client.callzomerequestgeneric.md b/docs/client.callzomerequestgeneric.md index f7725c16..f9c33400 100644 --- a/docs/client.callzomerequestgeneric.md +++ b/docs/client.callzomerequestgeneric.md @@ -12,9 +12,12 @@ export type CallZomeRequestGeneric = { cell_id: CellId; zome_name: ZomeName; fn_name: FunctionName; - payload: Payload; - provenance: AgentPubKey; + provenance?: AgentPubKey; + payload?: Payload; + cap_secret?: CapSecret; + nonce?: Nonce256Bit; + expires_at?: number; }; ``` -**References:** [CellId](./client.cellid.md), [ZomeName](./client.zomename.md), [FunctionName](./client.functionname.md), [AgentPubKey](./client.agentpubkey.md) +**References:** [CellId](./client.cellid.md), [ZomeName](./client.zomename.md), [FunctionName](./client.functionname.md), [AgentPubKey](./client.agentpubkey.md), [CapSecret](./client.capsecret.md), [Nonce256Bit](./client.nonce256bit.md) diff --git a/docs/client.md b/docs/client.md index 1d24ebe0..bd20429e 100644 --- a/docs/client.md +++ b/docs/client.md @@ -591,16 +591,6 @@ Description - - - -[CallZomeRequestAllParams](./client.callzomerequestallparams.md) - - - - - - @@ -1442,16 +1432,6 @@ This type is meant to be opaque - - - -[AppCallZomeRequest](./client.appcallzomerequest.md) - - - - - - @@ -2524,16 +2504,6 @@ An internal link type index within the DNA, from 0 to 255. - - - -[NonProvenanceCallZomeRequest](./client.nonprovenancecallzomerequest.md) - - - - - - @@ -2748,16 +2718,6 @@ If the key could not be deleted from all cells, the call [RevokeAgentKeyRequest] - - - -[RoleNameCallZomeRequestSigned](./client.rolenamecallzomerequestsigned.md) - - - - - - diff --git a/docs/client.nonprovenancecallzomerequest.md b/docs/client.nonprovenancecallzomerequest.md deleted file mode 100644 index 5b723a71..00000000 --- a/docs/client.nonprovenancecallzomerequest.md +++ /dev/null @@ -1,14 +0,0 @@ - - -[Home](./index.md) > [@holochain/client](./client.md) > [NonProvenanceCallZomeRequest](./client.nonprovenancecallzomerequest.md) - -## NonProvenanceCallZomeRequest type - - -**Signature:** - -```typescript -export type NonProvenanceCallZomeRequest = Omit; -``` -**References:** [CallZomeRequest](./client.callzomerequest.md) - diff --git a/docs/client.rolenamecallzomerequest.md b/docs/client.rolenamecallzomerequest.md index db679aec..c6ebf5f4 100644 --- a/docs/client.rolenamecallzomerequest.md +++ b/docs/client.rolenamecallzomerequest.md @@ -8,9 +8,9 @@ **Signature:** ```typescript -export type RoleNameCallZomeRequest = Omit & { +export type RoleNameCallZomeRequest = Omit & { role_name: RoleName; }; ``` -**References:** [NonProvenanceCallZomeRequest](./client.nonprovenancecallzomerequest.md), [RoleName](./client.rolename.md) +**References:** [CallZomeRequest](./client.callzomerequest.md), [RoleName](./client.rolename.md) diff --git a/docs/client.rolenamecallzomerequestsigned.md b/docs/client.rolenamecallzomerequestsigned.md deleted file mode 100644 index c7b6a23d..00000000 --- a/docs/client.rolenamecallzomerequestsigned.md +++ /dev/null @@ -1,16 +0,0 @@ - - -[Home](./index.md) > [@holochain/client](./client.md) > [RoleNameCallZomeRequestSigned](./client.rolenamecallzomerequestsigned.md) - -## RoleNameCallZomeRequestSigned type - - -**Signature:** - -```typescript -export type RoleNameCallZomeRequestSigned = Omit & { - role_name: RoleName; -}; -``` -**References:** [CallZomeRequestSigned](./client.callzomerequestsigned.md), [RoleName](./client.rolename.md) - diff --git a/src/api/app/types.ts b/src/api/app/types.ts index 5bf5822a..1fe3ca8f 100644 --- a/src/api/app/types.ts +++ b/src/api/app/types.ts @@ -26,38 +26,6 @@ import { SignedActionHashed, } from "../../index.js"; -/** - * @public - */ -export type NonProvenanceCallZomeRequest = Omit; - -/** - * @public - */ -export type RoleNameCallZomeRequest = Omit< - NonProvenanceCallZomeRequest, - "cell_id" -> & { - role_name: RoleName; -}; - -/** - * @public - */ -export type RoleNameCallZomeRequestSigned = Omit< - CallZomeRequestSigned, - "cell_id" -> & { role_name: RoleName }; - -/** - * @public - */ -export type AppCallZomeRequest = - | NonProvenanceCallZomeRequest - | RoleNameCallZomeRequest - | CallZomeRequest - | CallZomeRequestAllParams; - /** * @public */ @@ -91,34 +59,35 @@ export interface AppEvents { /** * @public */ -export interface CallZomeRequestAllParams extends CallZomeRequest { - cap_secret: CapSecret | null; - nonce: Nonce256Bit; - expires_at: number; -} - +export type CallZomeRequestGeneric = { + cell_id: CellId; + zome_name: ZomeName; + fn_name: FunctionName; + provenance?: AgentPubKey; + payload?: Payload; + cap_secret?: CapSecret; + nonce?: Nonce256Bit; + expires_at?: number; +}; /** * @public */ -export interface CallZomeRequestSigned { - bytes: Uint8Array; - signature: Uint8Array; -} +export type CallZomeRequest = CallZomeRequestGeneric; /** * @public */ -export type CallZomeRequestGeneric = { - cell_id: CellId; - zome_name: ZomeName; - fn_name: FunctionName; - payload: Payload; - provenance: AgentPubKey; +export type RoleNameCallZomeRequest = Omit & { + role_name: RoleName; }; + /** * @public */ -export type CallZomeRequest = CallZomeRequestGeneric; +export interface CallZomeRequestSigned { + bytes: Uint8Array; + signature: Uint8Array; +} /** * @public @@ -526,7 +495,10 @@ export type NetworkInfoResponse = NetworkInfo[]; * @public */ export interface AppClient { - callZome(args: AppCallZomeRequest, timeout?: number): Promise; + callZome( + args: CallZomeRequest | RoleNameCallZomeRequest, + timeout?: number + ): Promise; on( eventName: Name | readonly Name[], diff --git a/src/api/app/websocket.ts b/src/api/app/websocket.ts index 4456db63..bcae6ed6 100644 --- a/src/api/app/websocket.ts +++ b/src/api/app/websocket.ts @@ -19,7 +19,6 @@ import { Transformer, } from "../common.js"; import { - AppCallZomeRequest, AppClient, AppEvents, AppNetworkInfoRequest, @@ -30,7 +29,6 @@ import { SignalCb, CallZomeRequest, CallZomeRequestSigned, - CallZomeRequestAllParams, CallZomeResponse, CallZomeResponseGeneric, CreateCloneCellRequest, @@ -54,6 +52,7 @@ import { AbandonCountersigningSessionStateResponse, PublishCountersigningSessionStateRequest, PublishCountersigningSessionStateResponse, + RoleNameCallZomeRequest, } from "./types.js"; import { getHostZomeCallSigner, @@ -363,7 +362,7 @@ export class AppWebsocket implements AppClient { * @returns The zome call's response. */ async callZome( - request: AppCallZomeRequest, + request: CallZomeRequest | RoleNameCallZomeRequest, timeout?: number ): Promise { if (!("provenance" in request)) { @@ -375,19 +374,18 @@ export class AppWebsocket implements AppClient { if ("role_name" in request && request.role_name) { const appInfo = this.cachedAppInfo || (await this.appInfo()); const cell_id = this.getCellIdFromRoleName(request.role_name, appInfo); - const zomeCallPayload: CallZomeRequest = { + request = { ...omit(request, "role_name"), - provenance: this.myPubKey, + // Some problem here with the launcher with just the `cell_id`. cell_id: [cell_id[0], cell_id[1]], }; - return this.callZomeRequester(zomeCallPayload, timeout); - } else if ("cell_id" in request && request.cell_id) { - return this.callZomeRequester(request as CallZomeRequest, timeout); + } else if (!("cell_id" in request)) { + throw new HolochainError( + "MissingRoleNameOrCellId", + "callZome requires a role_name or cell_id argument" + ); } - throw new HolochainError( - "MissingRoleNameOrCellId", - "callZome requires a role_name or cell_id argument" - ); + return this.callZomeRequester(request, timeout); } /** @@ -603,7 +601,7 @@ export const signZomeCall = async (request: CallZomeRequest) => { )}, ${encodeHashToBase64(request.cell_id[1])}]` ); } - const unsignedZomeCallPayload: CallZomeRequestAllParams = { + const zome_call_params: CallZomeRequest = { cap_secret: signingCredentialsForCell.capSecret, cell_id: request.cell_id, zome_name: request.zome_name, @@ -613,7 +611,7 @@ export const signZomeCall = async (request: CallZomeRequest) => { nonce: await randomNonce(), expires_at: getNonceExpiration(), }; - const bytes = encode(unsignedZomeCallPayload); + const bytes = encode(zome_call_params); const bytesHash = new Uint8Array(sha512.array(bytes)); await _sodium.ready; const sodium = _sodium; diff --git a/src/environments/launcher.ts b/src/environments/launcher.ts index 51e7b8a0..9eaae34f 100644 --- a/src/environments/launcher.ts +++ b/src/environments/launcher.ts @@ -1,8 +1,5 @@ import { AppAuthenticationToken, CallZomeRequest } from "../api/index.js"; -import { - CallZomeRequestSigned, - CallZomeRequestAllParams, -} from "../api/index.js"; +import { CallZomeRequestSigned } from "../api/index.js"; import { InstalledAppId } from "../types.js"; export interface LauncherEnvironment { @@ -61,7 +58,7 @@ interface CallZomeRequestSignedElectron interface CallZomeRequestUnsignedElectron extends Omit< - CallZomeRequestAllParams, + CallZomeRequest, | "cap_secret" | "cell_id" | "provenance" diff --git a/test/e2e/app-websocket.ts b/test/e2e/app-websocket.ts index 2176c7cd..5567e12b 100644 --- a/test/e2e/app-websocket.ts +++ b/test/e2e/app-websocket.ts @@ -2,15 +2,15 @@ import assert from "node:assert"; import test from "tape"; import { AdminWebsocket, - AppCallZomeRequest, AppCreateCloneCellRequest, AppEntryDef, AppWebsocket, + CallZomeRequest, CellType, CloneId, fakeAgentPubKey, - NonProvenanceCallZomeRequest, RoleName, + RoleNameCallZomeRequest, SignalCb, SignalType, } from "../../src"; @@ -116,7 +116,6 @@ test( zome_name: TEST_ZOME_NAME, fn_name: "emitter", provenance: await fakeAgentPubKey(), - payload: null, }); await signalReceivedPromise; }) @@ -196,7 +195,6 @@ test( zome_name: TEST_ZOME_NAME, fn_name: "emitter", provenance: await fakeAgentPubKey(), - payload: null, }); // signals are received before the timeout step in the JS event loop is completed @@ -230,11 +228,10 @@ test( "clone cell agent key matches base cell agent key" ); - const params: AppCallZomeRequest = { + const params: RoleNameCallZomeRequest = { role_name: cloneCell.clone_id, zome_name: TEST_ZOME_NAME, fn_name: "foo", - payload: null, }; const response = await appWs.callZome(params); t.equal( @@ -269,11 +266,10 @@ test( 2, "disabled clone cell is part of app info" ); - const params: NonProvenanceCallZomeRequest = { + const params: CallZomeRequest = { cell_id: cloneCell.cell_id, zome_name: TEST_ZOME_NAME, fn_name: "foo", - payload: null, }; try { await appWs.callZome(params);