Skip to content

Commit 2da3985

Browse files
EslaM-Xcodebuff-team
andcommitted
docs(adapter): document the snapshot fields and every refusal code
Package README gains a short usage example, the field list and the 19 refusal codes; the module header carries the same contract next to the code. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
1 parent 0dfb7dd commit 2da3985

2 files changed

Lines changed: 82 additions & 0 deletions

File tree

‎packages/agent-commerce/README.md‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,42 @@ import { createConsent, verifyExecution } from "@coreguard/agent-commerce";
336336
The MCP tools are thin wrappers over these functions; nothing is added or hidden
337337
by going through MCP.
338338

339+
## Smart-account adapter (CG-W6/1)
340+
341+
Maps one caller-supplied snapshot to the arguments of the signer-set, threshold
342+
and Soroban-authorization checks. It does not read the network, sign or decide
343+
authorization; it re-sorts the evidence and digests it so a tamper is visible.
344+
345+
```js
346+
import { fromSmartAccountSnapshot } from "@coreguard/agent-commerce/smart-account-adapter.mjs";
347+
348+
const mapped = fromSmartAccountSnapshot({
349+
network: "testnet",
350+
accountId: "C...",
351+
masterWeight: 0,
352+
thresholds: { low: 1, medium: 2, high: 3 },
353+
signers: [{ key: "G...", kind: "passkey", weight: 2 }],
354+
});
355+
// mapped.toolCalls -> 2 calls (3 when `soroban` is supplied)
356+
// mapped.snapshotDigest -> changes if a weight, kind or ledger changes
357+
```
358+
359+
Snapshot fields: `network` (`testnet` | `mainnet` | `futurenet`), `accountId`,
360+
`masterWeight`, `thresholds { low, medium, high }`, `signers[]` with
361+
`key` (or `publicKey` / `address`), optional `kind` and `weight`, optional
362+
`presentedSigners[]` (defaults to all signers), and optional `soroban` with
363+
`entry { contractId, functionName, argsDigest, signatureExpirationLedger,
364+
rootInvocation?, subInvocations? }`, `expected { contractId, functionName,
365+
argsDigest }`, `currentLedger` and optional `allowedContracts`.
366+
367+
Refusal codes (returned as `{ ok: false, error: { code, detail, field? } }`, with
368+
no `toolCalls`): `INVALID_SNAPSHOT`, `UNSUPPORTED_NETWORK`, `MISSING_ACCOUNT_ID`,
369+
`INVALID_MASTER_WEIGHT`, `INVALID_THRESHOLDS`, `THRESHOLD_ORDER`, `NO_SIGNERS`,
370+
`INVALID_SIGNER`, `MISSING_SIGNER_KEY`, `INVALID_WEIGHT`, `DUPLICATE_SIGNER`,
371+
`INVALID_PRESENTED_SIGNERS`, `INVALID_PRESENTED_SIGNER`,
372+
`UNKNOWN_PRESENTED_SIGNER`, `INVALID_LEVEL`, `INVALID_SOROBAN`,
373+
`SOROBAN_ENTRY_MISSING`, `SOROBAN_EXPECTED_MISSING`, `CURRENT_LEDGER_MISSING`.
374+
339375
## Boundaries (standing)
340376

341377
- Synthetic demo data is the caller's; nothing here contacts any commerce

‎packages/agent-commerce/smart-account-adapter.mjs‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,52 @@
1212
* never decides authorization. It only reshapes evidence the caller already
1313
* has, sorts it deterministically and digests it so a tamper is visible.
1414
* VERIFIED ≠ SAFE.
15+
*
16+
* Snapshot fields (all caller-supplied):
17+
* network "testnet" | "mainnet" | "futurenet"
18+
* accountId string, required
19+
* masterWeight non-negative integer; 0 means the master key is disabled
20+
* thresholds { low, medium, high }, non-negative integers,
21+
* low <= medium <= high and high > 0
22+
* signers[] non-empty; each { key | publicKey | address,
23+
* kind? (defaults to ed25519), weight }
24+
* presentedSigners[] optional; each { key | publicKey | address, weight? },
25+
* defaults to the full signer set with its weights.
26+
* An unknown key is a refusal, never a silent drop.
27+
* soroban optional; { entry { contractId, functionName,
28+
* argsDigest, signatureExpirationLedger,
29+
* rootInvocation?, subInvocations? },
30+
* expected { contractId, functionName, argsDigest },
31+
* currentLedger, allowedContracts? }
32+
* options.level optional "low" | "medium" | "high" (default: high)
33+
*
34+
* Result: { ok: true, spec, boundary, network, accountId, snapshotDigest,
35+
* inputs: { signers, thresholds, sorobanAuth }, toolCalls[] }
36+
* snapshotDigest covers network, account, the presented set and soroban, so a
37+
* changed weight, signer kind, presented weight or expiration ledger changes it.
38+
* toolCalls holds 2 entries, or 3 when `soroban` is supplied.
39+
*
40+
* Refusal codes (returned as { ok: false, spec, error: { code, detail, field? } },
41+
* with no toolCalls produced):
42+
* INVALID_SNAPSHOT snapshot is not an object
43+
* UNSUPPORTED_NETWORK network is not testnet/mainnet/futurenet
44+
* MISSING_ACCOUNT_ID accountId is empty
45+
* INVALID_MASTER_WEIGHT masterWeight is not a non-negative integer
46+
* INVALID_THRESHOLDS a threshold is not a non-negative integer
47+
* THRESHOLD_ORDER thresholds violate low <= medium <= high, or high <= 0
48+
* NO_SIGNERS signers is missing or empty
49+
* INVALID_SIGNER a signers[] entry is not an object
50+
* MISSING_SIGNER_KEY a signer has no key/publicKey/address
51+
* INVALID_WEIGHT a weight is not a non-negative integer
52+
* DUPLICATE_SIGNER the same key appears twice
53+
* INVALID_PRESENTED_SIGNERS presentedSigners is not an array
54+
* INVALID_PRESENTED_SIGNER a presentedSigners[] entry is not an object
55+
* UNKNOWN_PRESENTED_SIGNER a presented key is absent from the signer set
56+
* INVALID_LEVEL level is not low/medium/high
57+
* INVALID_SOROBAN soroban is present but not an object
58+
* SOROBAN_ENTRY_MISSING soroban.entry is missing
59+
* SOROBAN_EXPECTED_MISSING soroban.expected is missing
60+
* CURRENT_LEDGER_MISSING soroban.currentLedger is not a non-negative integer
1561
*/
1662

1763
import { canonicalJson, digestOf } from "./wave6.mjs";

0 commit comments

Comments
 (0)