Skip to content
Draft
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
51 changes: 51 additions & 0 deletions bootstrap-languages/agent-language/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,57 @@ export default class ExpressionAdapterImpl implements ExpressionAdapter {

return expression
};

async addAuthorisedKey(did: string, key: string, name: string, proof: { authorising_key: string, signature: string, timestamp: string }): Promise<any> {
// Zome validates and returns updated AgentExpressionData
const updatedData = await this.#DNA.call(
DNA_ROLE,
ZOME_NAME,
"add_authorised_key",
{ did, key, name, proof }
);

// Re-sign with the agent's key and store the full expression
const signedExpression = this.#agent.createSignedExpression(updatedData);
await this.#DNA.call(
DNA_ROLE,
ZOME_NAME,
"create_agent_expression",
signedExpression
);

return signedExpression;
}
Comment on lines +27 to +46
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check for KeyAuthorisation and AddAuthorisedKeyInput structs in Rust files
echo "=== Searching for KeyAuthorisation struct ==="
fd -t f "\.rs$" bootstrap-languages/agent-language/hc-dna/zomes/agent_store_integrity/src/ | xargs rg -l "KeyAuthorisation" | head -5

echo ""
echo "=== Searching for serde rename_all in agent_store ==="
fd -t f "\.rs$" bootstrap-languages/agent-language/hc-dna/zomes/agent_store_integrity/src/ | xargs rg -B3 "KeyAuthorisation|AddAuthorisedKeyInput" | head -80

Repository: coasys/ad4m

Length of output: 720


🏁 Script executed:

#!/bin/bash
# Check the exact TS type signature in adapter.ts
echo "=== Checking proof parameter in addAuthorisedKey ==="
rg -n "addAuthorisedKey" bootstrap-languages/agent-language/adapter.ts -A5 -B1

echo ""
echo "=== Check revokeKey signature ==="
rg -n "revokeKey" bootstrap-languages/agent-language/adapter.ts -A5 -B1

Repository: coasys/ad4m

Length of output: 808


🏁 Script executed:

#!/bin/bash
# Check for any type definitions for proof in TS files
echo "=== Searching for proof type definitions ==="
fd -t f "\.ts$" bootstrap-languages/agent-language/ | xargs rg -B2 -A2 "authorising_key|authorisingKey" 2>/dev/null | head -100

Repository: coasys/ad4m

Length of output: 598


🏁 Script executed:

#!/bin/bash
# Get full KeyAuthorisation struct definition
echo "=== Full KeyAuthorisation struct ==="
rg -A15 "pub struct KeyAuthorisation" bootstrap-languages/agent-language/hc-dna/zomes/agent_store_integrity/src/lib.rs

echo ""
echo "=== Verify the call serialization method ==="
rg -n "this\.#DNA\.call" bootstrap-languages/agent-language/adapter.ts -B2 -A8 | head -50

Repository: coasys/ad4m

Length of output: 2308


🏁 Script executed:

#!/bin/bash
# Check the HolochainLanguageDelegate or DNA call implementation
echo "=== Search for DNA.call or HolochainLanguageDelegate implementation ==="
fd -t f "\.ts$" bootstrap-languages/agent-language/ | xargs rg -l "DNA.*call|HolochainLanguageDelegate" | head -10

echo ""
echo "=== Check imports and DNA definition in adapter.ts ==="
rg -n "import|#DNA|DNA_ROLE" bootstrap-languages/agent-language/adapter.ts | head -20

Repository: coasys/ad4m

Length of output: 1133


🏁 Script executed:

#!/bin/bash
# Search for any snake_case to camelCase conversion middleware
echo "=== Search for camelCase conversion ==="
fd -t f "\.ts$" bootstrap-languages/agent-language/ | xargs rg "camelCase|snakeCase|transformKeys|keysToCase" 2>/dev/null | head -20

Repository: coasys/ad4m

Length of output: 94


Serialization mismatch: proof.authorising_key uses snake_case but Rust expects camelCase.

The proof parameter declares authorising_key (snake_case), but KeyAuthorisation in the integrity zome uses #[serde(rename_all = "camelCase")], expecting the JSON key "authorisingKey". When the object is serialized, { authorising_key: "..." } becomes JSON "authorising_key", causing deserialization to fail.

Update the TS type signature to use camelCase:

🐛 Proposed fix
-  async addAuthorisedKey(did: string, key: string, name: string, proof: { authorising_key: string, signature: string, timestamp: string }): Promise<any> {
+  async addAuthorisedKey(did: string, key: string, name: string, proof: { authorisingKey: string, signature: string, timestamp: string }): Promise<any> {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async addAuthorisedKey(did: string, key: string, name: string, proof: { authorising_key: string, signature: string, timestamp: string }): Promise<any> {
// Zome validates and returns updated AgentExpressionData
const updatedData = await this.#DNA.call(
DNA_ROLE,
ZOME_NAME,
"add_authorised_key",
{ did, key, name, proof }
);
// Re-sign with the agent's key and store the full expression
const signedExpression = this.#agent.createSignedExpression(updatedData);
await this.#DNA.call(
DNA_ROLE,
ZOME_NAME,
"create_agent_expression",
signedExpression
);
return signedExpression;
}
async addAuthorisedKey(did: string, key: string, name: string, proof: { authorisingKey: string, signature: string, timestamp: string }): Promise<any> {
// Zome validates and returns updated AgentExpressionData
const updatedData = await this.#DNA.call(
DNA_ROLE,
ZOME_NAME,
"add_authorised_key",
{ did, key, name, proof }
);
// Re-sign with the agent's key and store the full expression
const signedExpression = this.#agent.createSignedExpression(updatedData);
await this.#DNA.call(
DNA_ROLE,
ZOME_NAME,
"create_agent_expression",
signedExpression
);
return signedExpression;
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bootstrap-languages/agent-language/adapter.ts` around lines 27 - 46, The
proof parameter of addAuthorisedKey currently declares authorising_key
(snake_case) but the Rust integrity zome (KeyAuthorisation with
#[serde(rename_all = "camelCase")]) expects authorisingKey; update the
TypeScript signature and any usage so the proof object uses authorisingKey
(camelCase) instead of authorising_key, and ensure the object passed into
this.#DNA.call("add_authorised_key", { did, key, name, proof }) contains
proof.authorisingKey; keep createSignedExpression usage the same but ensure the
signedExpression stores the camelCase field so Rust deserialization succeeds.


async revokeKey(did: string, key: string, revokedByKey: string, signature: string, timestamp: string, reason?: string): Promise<any> {
// Zome validates and returns updated AgentExpressionData
const updatedData = await this.#DNA.call(
DNA_ROLE,
ZOME_NAME,
"revoke_key",
{ did, key, revokedByKey, signature, timestamp, reason: reason ?? null }
);

// Re-sign with the agent's key and store the full expression
const signedExpression = this.#agent.createSignedExpression(updatedData);
await this.#DNA.call(
DNA_ROLE,
ZOME_NAME,
"create_agent_expression",
signedExpression
);

return signedExpression;
}

async isKeyValid(did: string, key: string): Promise<boolean> {
return await this.#DNA.call(
DNA_ROLE,
ZOME_NAME,
"is_key_valid",
{ did, key }
);
}
}

class Sharing implements PublicSharing {
Expand Down
27 changes: 20 additions & 7 deletions bootstrap-languages/agent-language/hc-dna/Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ tokio = { version = "1", features = ["full"] }
chrono = { version = "0.4", features = ["serde"] }
futures = "0.3"
uuid = { version = "1.0", features = ["v4"] }
ed25519-dalek = { version = "2", features = ["rand_core"] }
rand = "0.8"
bs58 = "0.5"

[dev-dependencies]
pretty_assertions = "1.4"
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@

mod utils;
mod test_agent_expression;
mod test_multi_key;
Loading