Skip to content

Commit

Permalink
fix!: simplify zome call signing (#244)
Browse files Browse the repository at this point in the history
Co-authored-by: Jost Schulte <[email protected]>
  • Loading branch information
jost-s and jost-s authored Nov 25, 2024
1 parent f1a318b commit 0be25b4
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 83 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Added
### Removed
### Changed
- Update JS client due to modified zome call signing.
### Fixed

## 2024-11-14: v0.18.0-dev.1
Expand Down
32 changes: 16 additions & 16 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 10 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"prepublishOnly": "npm run build"
},
"dependencies": {
"@holochain/client": "^0.19.0-dev.2",
"@holochain/client": "^0.19.0-dev.5",
"get-port": "^6.1.2",
"lodash": "^4.17.21",
"uuid": "^8.3.2",
Expand Down
1 change: 0 additions & 1 deletion ts/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ export const getCallableCell = (
{
...request,
cell_id: cell.cell_id,
provenance: request.provenance ?? cell.cell_id[1],
payload: request.payload ?? null,
},
timeout
Expand Down
24 changes: 8 additions & 16 deletions ts/src/trycp/conductor/conductor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -927,28 +927,20 @@ export class TryCpConductor implements IConductor {
* @param request - {@link CallZomeRequest}.
* @returns The result of the zome call.
*/
const callZome = async <T>(
request: CallZomeRequest | CallZomeRequestSigned
) => {
const callZome = async <T>(request: CallZomeRequest) => {
// authorize signing credentials
if (!getSigningCredentials(request.cell_id)) {
await this.adminWs().authorizeSigningCredentials(request.cell_id);
}

let signedRequest: CallZomeRequestSigned;
if ("signature" in request) {
signedRequest = request;
} else {
// sign zome call
const signingCredentials = getSigningCredentials(request.cell_id);
if (!signingCredentials) {
throw new Error(
`cannot sign zome call: no signing credentials have been authorized for cell ${request.cell_id}`
);
}
const signedZomeCall = await signZomeCall(request);
signedRequest = signedZomeCall;
// sign zome call
const signingCredentials = getSigningCredentials(request.cell_id);
if (!signingCredentials) {
throw new Error(
`cannot sign zome call: no signing credentials have been authorized for cell ${request.cell_id}`
);
}
const signedRequest = await signZomeCall(request);
const response = await this.callAppApi(port, {
type: "call_zome",
data: signedRequest,
Expand Down
25 changes: 1 addition & 24 deletions ts/src/trycp/trycp-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export class TryCpClient {
* @returns A promise that resolves to the {@link TryCpSuccessResponse}
*/
call(request: TryCpRequest) {
const requestDebugLog = this.getFormattedRequestLog(request);
const requestDebugLog = JSON.stringify(request);
logger.debug(`request ${requestDebugLog}\n`);

const callPromise = new Promise<TryCpSuccessResponse>((resolve, reject) => {
Expand Down Expand Up @@ -307,27 +307,4 @@ export class TryCpClient {
}
return debugLog;
}

private getFormattedRequestLog(request: TryCpRequest) {
let debugLog = cloneDeep(request);
if (
debugLog.type === "call_app_interface" &&
"data" in debugLog.message &&
debugLog.message.type === "call_zome"
) {
const messageData = debugLog.message.data as CallZomeRequestSigned;
debugLog.message.data = Object.assign(debugLog.message.data, {
cell_id: [
Buffer.from(messageData.cell_id[0]).toString("base64"),
Buffer.from(messageData.cell_id[1]).toString("base64"),
],
provenance: Buffer.from(messageData.provenance).toString("base64"),
});
}
if ("content" in request) {
// Call "save_dna" submits a DNA as binary
debugLog = Object.assign(debugLog, { content: undefined });
}
return JSON.stringify(debugLog);
}
}
12 changes: 6 additions & 6 deletions ts/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
ProvisionedCell,
RegisterDnaRequest,
RoleName,
CallZomeRequestSigned,
} from "@holochain/client";

/**
Expand Down Expand Up @@ -47,7 +48,9 @@ export type IAdminWebsocket = Omit<
*
* @public
*/
export type IAppWebsocket = Pick<AppWebsocket, "callZome">;
export type IAppWebsocket = {
callZome: <T>(request: CallZomeRequest, timeout?: number) => Promise<T>;
};

/**
* Base interface of a Tryorama conductor. Both {@link Conductor} and
Expand Down Expand Up @@ -79,11 +82,8 @@ export interface IConductor {
*/
export type CellZomeCallRequest = Omit<
CallZomeRequest,
"cap_secret" | "cell_id" | "payload" | "provenance"
> & {
provenance?: AgentPubKey;
payload?: unknown;
};
"cap_secret" | "cell_id"
>;

/**
* The function for calling a zome from a specific cell.
Expand Down
8 changes: 0 additions & 8 deletions ts/test/trycp/conductor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ test("TryCP Conductor - receive a signal", async (t) => {
const cell_id = appInfo.cell_info[ROLE_NAME][0][CellType.Provisioned].cell_id;

appWs.callZome({
cap_secret: null,
cell_id,
zome_name: "coordinator",
fn_name: "signal_loopback",
Expand Down Expand Up @@ -605,7 +604,6 @@ test("TryCP Conductor - create and read an entry using the entry zome", async (t

const entryContent = "test-content";
const createEntryHash = await appWs.callZome<EntryHash>({
cap_secret: null,
cell_id,
zome_name: "coordinator",
fn_name: "create",
Expand All @@ -620,7 +618,6 @@ test("TryCP Conductor - create and read an entry using the entry zome", async (t
);

const readEntryResponse = await appWs.callZome<typeof entryContent>({
cap_secret: null,
cell_id,
zome_name: "coordinator",
fn_name: "read",
Expand Down Expand Up @@ -755,7 +752,6 @@ test("TryCP Conductor - create and read an entry using the entry zome, 1 conduct

const entryContent = "test-content";
const createEntryHash = await appWs.callZome<EntryHash>({
cap_secret: null,
cell_id: cellId1,
zome_name: "coordinator",
fn_name: "create",
Expand All @@ -770,7 +766,6 @@ test("TryCP Conductor - create and read an entry using the entry zome, 1 conduct
);

const readEntryResponse = await appWs.callZome<typeof entryContent>({
cap_secret: null,
cell_id: cellId2,
zome_name: "coordinator",
fn_name: "read",
Expand Down Expand Up @@ -834,7 +829,6 @@ test("TryCP Conductor - clone cell management", async (t) => {
zome_name: "coordinator",
fn_name: "create",
payload: testContent,
cap_secret: null,
provenance: agentPubKey,
});

Expand All @@ -847,7 +841,6 @@ test("TryCP Conductor - clone cell management", async (t) => {
zome_name: "coordinator",
fn_name: "read",
payload: entryActionHash,
cap_secret: null,
provenance: agentPubKey,
}),
"disabled clone cell cannot be called"
Expand All @@ -867,7 +860,6 @@ test("TryCP Conductor - clone cell management", async (t) => {
zome_name: "coordinator",
fn_name: "read",
payload: entryActionHash,
cap_secret: null,
provenance: agentPubKey,
});
t.equal(readEntryResponse, testContent, "enabled clone cell can be called");
Expand Down

0 comments on commit 0be25b4

Please sign in to comment.