@mida-context/sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +26 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +7115 -0
- package/dist/types/api/app.d.ts +99 -0
- package/dist/types/api/auth-pure.d.ts +51 -0
- package/dist/types/api/auth.d.ts +17 -0
- package/dist/types/api/authorize.d.ts +24 -0
- package/dist/types/api/batch-deny.d.ts +22 -0
- package/dist/types/api/batch-routes.d.ts +69 -0
- package/dist/types/api/batch-store.d.ts +96 -0
- package/dist/types/api/batcher.d.ts +220 -0
- package/dist/types/api/browser.d.ts +14 -0
- package/dist/types/api/chain-budget.d.ts +61 -0
- package/dist/types/api/chain-views.d.ts +87 -0
- package/dist/types/api/client.d.ts +295 -0
- package/dist/types/api/deny-overlay.d.ts +81 -0
- package/dist/types/api/errors.d.ts +30 -0
- package/dist/types/api/file-stores.d.ts +7 -0
- package/dist/types/api/index.d.ts +17 -0
- package/dist/types/api/secure-fs.d.ts +12 -0
- package/dist/types/api/store.d.ts +51 -0
- package/dist/types/api/stores.d.ts +171 -0
- package/dist/types/api/verify-assertion.d.ts +22 -0
- package/dist/types/api/wire.d.ts +27 -0
- package/dist/types/chain/abis.d.ts +2125 -0
- package/dist/types/chain/browser.d.ts +20 -0
- package/dist/types/chain/deployment-fs.d.ts +15 -0
- package/dist/types/chain/deployment.d.ts +33 -0
- package/dist/types/chain/deployments.generated.d.ts +1 -0
- package/dist/types/chain/gas.d.ts +47 -0
- package/dist/types/chain/history.d.ts +52 -0
- package/dist/types/chain/index.d.ts +13 -0
- package/dist/types/chain/local.d.ts +34 -0
- package/dist/types/chain/logs.d.ts +62 -0
- package/dist/types/chain/placements.d.ts +92 -0
- package/dist/types/chain/read-scope.d.ts +66 -0
- package/dist/types/chain/registry.d.ts +16 -0
- package/dist/types/chain/sponsored.d.ts +93 -0
- package/dist/types/chain/transport.d.ts +53 -0
- package/dist/types/chain/writes.d.ts +165 -0
- package/dist/types/crypto/aead.d.ts +5 -0
- package/dist/types/crypto/bytes.d.ts +4 -0
- package/dist/types/crypto/derive.d.ts +20 -0
- package/dist/types/crypto/index.d.ts +6 -0
- package/dist/types/crypto/object.d.ts +42 -0
- package/dist/types/crypto/payload.d.ts +21 -0
- package/dist/types/crypto/wraps.d.ts +36 -0
- package/dist/types/grant-advisor/advise.d.ts +23 -0
- package/dist/types/grant-advisor/authority.d.ts +44 -0
- package/dist/types/grant-advisor/index.d.ts +5 -0
- package/dist/types/grant-advisor/manifest.d.ts +66 -0
- package/dist/types/grant-advisor/policy.d.ts +91 -0
- package/dist/types/grant-advisor/signatures.d.ts +10 -0
- package/dist/types/mida-context-sdk/daemon.d.ts +27 -0
- package/dist/types/mida-context-sdk/errors.d.ts +27 -0
- package/dist/types/mida-context-sdk/index.d.ts +5 -0
- package/dist/types/mida-context-sdk/local.d.ts +40 -0
- package/dist/types/mida-context-sdk/mida.d.ts +65 -0
- package/dist/types/mida-context-sdk/transport.d.ts +137 -0
- package/dist/types/protocol/batch.d.ts +161 -0
- package/dist/types/protocol/constants.d.ts +56 -0
- package/dist/types/protocol/errors.d.ts +15 -0
- package/dist/types/protocol/ids.d.ts +72 -0
- package/dist/types/protocol/index.d.ts +11 -0
- package/dist/types/protocol/namespaces.d.ts +15 -0
- package/dist/types/protocol/owner-link.d.ts +146 -0
- package/dist/types/protocol/typed-data.d.ts +365 -0
- package/dist/types/protocol/types.d.ts +215 -0
- package/dist/types/protocol/webauthn-assertion.d.ts +29 -0
- package/dist/types/protocol/wire.d.ts +8 -0
- package/dist/types/sdk/agent.d.ts +279 -0
- package/dist/types/sdk/batched.d.ts +68 -0
- package/dist/types/sdk/connect.d.ts +88 -0
- package/dist/types/sdk/index.d.ts +7 -0
- package/dist/types/sdk/request-store.d.ts +26 -0
- package/dist/types/storage/index.d.ts +23 -0
- package/package.json +50 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ContextInput, ContextResult, HandoffAnswer, RememberInput, RememberResult, RequestAccessResult, StatusAnswer, Transport, VerifyResult, WhatsNewAnswer } from "./transport.js";
|
|
2
|
+
import type { ContextItem } from "./transport.js";
|
|
3
|
+
/**
|
|
4
|
+
* The default transport: every call goes to the Mida service (midad) over this machine's private
|
|
5
|
+
* Unix socket, so the daemon's gates — grants, revocation, the save lanes, the verified reads —
|
|
6
|
+
* decide every answer. The SDK holds no chain keys and signs nothing itself; `requestAccess` and
|
|
7
|
+
* `verify` are the exceptions, which read the agent's own identity files from the Mida home
|
|
8
|
+
* through `@mida/sdk`, exactly as the CLI does.
|
|
9
|
+
*/
|
|
10
|
+
export declare class LocalTransport implements Transport {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(options: {
|
|
13
|
+
agent: string;
|
|
14
|
+
home: string;
|
|
15
|
+
project: string;
|
|
16
|
+
task?: string;
|
|
17
|
+
});
|
|
18
|
+
context(input: ContextInput): Promise<ContextResult>;
|
|
19
|
+
remember(input: RememberInput): Promise<RememberResult>;
|
|
20
|
+
/**
|
|
21
|
+
* Files the access request where `mida approve <agent>` looks for it — `pending-request.json`
|
|
22
|
+
* plus the request store — through the same `connectAgent` path the CLI uses. The agent cannot
|
|
23
|
+
* approve itself: approval is the owner's terminal step, and this SDK carries no approve call.
|
|
24
|
+
*/
|
|
25
|
+
requestAccess(): Promise<RequestAccessResult>;
|
|
26
|
+
/**
|
|
27
|
+
* Checks one item against the chain — not against the store or the payload. `commitment` asks
|
|
28
|
+
* whether the registry's record carries exactly this manifest; `author` whether the chain
|
|
29
|
+
* recorded this author; `grant-at-write` whether a record exists at all — the registry only
|
|
30
|
+
* anchors writes made under a live grant, so anchoring is the grant-at-write proof.
|
|
31
|
+
*/
|
|
32
|
+
verify(item: ContextItem): Promise<VerifyResult>;
|
|
33
|
+
handoff(): Promise<HandoffAnswer>;
|
|
34
|
+
whatsNew(): Promise<WhatsNewAnswer>;
|
|
35
|
+
/**
|
|
36
|
+
* `/health` plus the same `/handoff` probe `mida_status` runs per agent — the verdict line says
|
|
37
|
+
* what that probe answered, word for word the adapter's line.
|
|
38
|
+
*/
|
|
39
|
+
status(): Promise<StatusAnswer>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { ContextInput, ContextResult, HandoffAnswer, RememberInput, RememberResult, RequestAccessResult, StatusAnswer, VerifyResult, WhatsNewAnswer } from "./transport.js";
|
|
2
|
+
import type { ContextItem } from "./transport.js";
|
|
3
|
+
/** The transports this version speaks. `direct` is a named promise for phase 2. */
|
|
4
|
+
export type TransportKind = "local" | "direct";
|
|
5
|
+
export interface MidaOptions {
|
|
6
|
+
/** The agent name this app was provisioned as — the name `mida approve` signed for. */
|
|
7
|
+
agent: string;
|
|
8
|
+
/** How to reach Mida. Default and only option today is `"local"` — this machine's Mida service. */
|
|
9
|
+
transport?: TransportKind;
|
|
10
|
+
/** The folder this agent works in — what counts as "this project". Default: process.cwd(). */
|
|
11
|
+
project?: string;
|
|
12
|
+
/** The named task this agent is doing; scopes handoff()/whatsNew()/status() and the checkpoint records context() returns. */
|
|
13
|
+
task?: string;
|
|
14
|
+
/** The Mida home — the folder `mida init` made. Default: $MIDA_HOME, else ~/.mida. */
|
|
15
|
+
home?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* An app's handle on this user's Mida context. Every method asks the same question Mida itself
|
|
19
|
+
* would — the Mida service decides what this agent may see, sign and remember — so an SDK app
|
|
20
|
+
* can never see more than the grants the owner signed allow.
|
|
21
|
+
*/
|
|
22
|
+
export declare class Mida {
|
|
23
|
+
#private;
|
|
24
|
+
/** The agent name, as the owner approved it. */
|
|
25
|
+
readonly agent: string;
|
|
26
|
+
/** The project folder `context()`/handoff calls answer for. */
|
|
27
|
+
readonly project: string;
|
|
28
|
+
/** The named task this handle is doing, when one was given. */
|
|
29
|
+
readonly task: string | undefined;
|
|
30
|
+
/** Which transport this handle uses. */
|
|
31
|
+
readonly transportKind: TransportKind;
|
|
32
|
+
constructor(options: MidaOptions);
|
|
33
|
+
/**
|
|
34
|
+
* Read this user's context in the areas this agent's grants cover — most-recently-anchored
|
|
35
|
+
* first, byte-budgeted, whole records only. In `projects.current`, checkpoint records are
|
|
36
|
+
* scoped to this handle's task (the same task `handoff()` resolves); the result's
|
|
37
|
+
* `otherTasks` names the project's other active tasks without their content. Throws the
|
|
38
|
+
* refusal's code (`not-approved`, `revoked`, `rate-limited`…) when the service refuses;
|
|
39
|
+
* `service-unavailable` when midad isn't answering.
|
|
40
|
+
*/
|
|
41
|
+
context(input: ContextInput): Promise<ContextResult>;
|
|
42
|
+
/**
|
|
43
|
+
* Write one memory: a note, a finding, a decision. Always recorded as AGENT_INFERRED — the
|
|
44
|
+
* provenance is the service's to stamp, never the caller's. Returns the record's id and
|
|
45
|
+
* whether it is already anchored (`anchored`) or accepted onto the batching lane (`pending`).
|
|
46
|
+
*/
|
|
47
|
+
remember(input: RememberInput): Promise<RememberResult>;
|
|
48
|
+
/**
|
|
49
|
+
* File a request asking the owner for this agent's grants. The agent can never approve itself:
|
|
50
|
+
* approval is the owner's terminal step — `mida approve <agent>` — and nothing in this SDK
|
|
51
|
+
* performs it.
|
|
52
|
+
*/
|
|
53
|
+
requestAccess(): Promise<RequestAccessResult>;
|
|
54
|
+
/** Check one item against the chain: its commitment, its author, and the grant it was written under. */
|
|
55
|
+
verify(item: ContextItem): Promise<VerifyResult>;
|
|
56
|
+
/** The session-start text `mida_handoff` would inject for this agent and folder. */
|
|
57
|
+
handoff(): Promise<HandoffAnswer>;
|
|
58
|
+
/** What's new for this agent and folder — the same answer `mida_whats_new` gives. */
|
|
59
|
+
whatsNew(): Promise<WhatsNewAnswer>;
|
|
60
|
+
/**
|
|
61
|
+
* Is the Mida service up, and what would this agent get here — approved, revoked, or
|
|
62
|
+
* never asked. Always answers; `up: false` when midad is not answering.
|
|
63
|
+
*/
|
|
64
|
+
status(): Promise<StatusAnswer>;
|
|
65
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { ContextKind, Hex, RecordReference } from "../protocol/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* One memory record as the SDK reports it. `author` and `writtenAt` come from the chain (or the
|
|
4
|
+
* store's received stamp while a save is pending) — never from the record's own content.
|
|
5
|
+
*/
|
|
6
|
+
export interface ContextItem {
|
|
7
|
+
/** The record's contextId. */
|
|
8
|
+
id: Hex;
|
|
9
|
+
namespace: string;
|
|
10
|
+
kind: ContextKind;
|
|
11
|
+
/** The decrypted payload value — the record's content, never a whole payload envelope. */
|
|
12
|
+
content: string | Record<string, unknown>;
|
|
13
|
+
/** The author the chain recorded; `name` resolves through the home's identity files, null when unknown. */
|
|
14
|
+
author: {
|
|
15
|
+
name: string | null;
|
|
16
|
+
id: Hex;
|
|
17
|
+
};
|
|
18
|
+
/** The provenance source the chain recorded — agent writes are always "AGENT_INFERRED". */
|
|
19
|
+
source: string;
|
|
20
|
+
/** ISO-8601. Anchored records carry the chain's stamp; pending ones the store's received stamp. */
|
|
21
|
+
writtenAt: string;
|
|
22
|
+
/** "pending" = the batching lane accepted the save but Monad has not anchored it yet. */
|
|
23
|
+
state: "anchored" | "pending";
|
|
24
|
+
superseded: false;
|
|
25
|
+
references: RecordReference[];
|
|
26
|
+
/** The on-chain proof of this record: its manifestHash and the record id to verify against. */
|
|
27
|
+
proof: {
|
|
28
|
+
manifestHash: Hex;
|
|
29
|
+
recordId: Hex;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Checkpoint records only: the task the record belongs to. Workflow memory is task-scoped —
|
|
33
|
+
* `context()` returns only the resolved task's checkpoint records, so on a checkpoint item
|
|
34
|
+
* this always equals that task ("main" when the handle named none). Absent on every
|
|
35
|
+
* non-checkpoint record, which is durable memory and never task-filtered.
|
|
36
|
+
*/
|
|
37
|
+
task?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface ContextInput {
|
|
40
|
+
/** One namespace — e.g. "projects.current". With `namespaces` unset, this is the whole read. */
|
|
41
|
+
namespace?: string;
|
|
42
|
+
/** Several namespaces read together; there is no ranking, the merged order is the chain's. */
|
|
43
|
+
namespaces?: string[];
|
|
44
|
+
/** The byte budget, counted over each item's content. A single record larger than `limit` is
|
|
45
|
+
* returned alone with `overLimit` set — never hidden, never truncated. */
|
|
46
|
+
limit: number;
|
|
47
|
+
/** ISO-8601 — only items whose effective stamp is strictly newer are returned. */
|
|
48
|
+
since?: string;
|
|
49
|
+
/** A cursor from an earlier `context()` result — resumes strictly after it. */
|
|
50
|
+
cursor?: string;
|
|
51
|
+
}
|
|
52
|
+
export interface ContextResult {
|
|
53
|
+
items: ContextItem[];
|
|
54
|
+
/** Non-null while more items remain beyond this page — pass it back as `cursor`. */
|
|
55
|
+
cursor: string | null;
|
|
56
|
+
/**
|
|
57
|
+
* The project's other active tasks — name, who last saved, when — the same entries the
|
|
58
|
+
* handoff prints as "Other active tasks". Awareness only: no content, no record ids; a
|
|
59
|
+
* task's own thread is a deliberate `mida task show <name>` away. Empty when the read did
|
|
60
|
+
* not touch `projects.current` or no other task saved recently.
|
|
61
|
+
*/
|
|
62
|
+
otherTasks: {
|
|
63
|
+
name: string;
|
|
64
|
+
savedBy: string;
|
|
65
|
+
savedAt: string;
|
|
66
|
+
}[];
|
|
67
|
+
/** Set when a single record larger than `limit` was returned alone. */
|
|
68
|
+
overLimit?: true;
|
|
69
|
+
/** Set when the store's list was incomplete — the items shown verified, but the list may not be whole. */
|
|
70
|
+
partial?: true;
|
|
71
|
+
}
|
|
72
|
+
export interface RememberInput {
|
|
73
|
+
/** Required — the area the record lands in (e.g. "projects.current"). There is no `auto`. */
|
|
74
|
+
namespace: string;
|
|
75
|
+
content: string | Record<string, unknown>;
|
|
76
|
+
/** Defaults to "INFERENCE" — the record is always written as AGENT_INFERRED. */
|
|
77
|
+
kind?: ContextKind;
|
|
78
|
+
references?: RecordReference[];
|
|
79
|
+
/** An earlier record of this agent's own lineage this one replaces — the SUPERSEDE_OWN path. */
|
|
80
|
+
supersedes?: Hex;
|
|
81
|
+
}
|
|
82
|
+
export interface RememberResult {
|
|
83
|
+
id: Hex;
|
|
84
|
+
/** "anchored" on the direct lane; "pending" until the batching lane's save anchors. */
|
|
85
|
+
state: "anchored" | "pending";
|
|
86
|
+
}
|
|
87
|
+
export interface RequestAccessResult {
|
|
88
|
+
requestId: Hex;
|
|
89
|
+
/** The owner-side step nothing else can substitute for. */
|
|
90
|
+
nextStep: string;
|
|
91
|
+
}
|
|
92
|
+
export interface VerifyCheck {
|
|
93
|
+
name: "commitment" | "author" | "grant-at-write";
|
|
94
|
+
ok: boolean;
|
|
95
|
+
detail: string;
|
|
96
|
+
}
|
|
97
|
+
export interface VerifyResult {
|
|
98
|
+
valid: boolean;
|
|
99
|
+
checks: VerifyCheck[];
|
|
100
|
+
}
|
|
101
|
+
/** The session-start text `mida_handoff` would inject. Refusals throw — they never come back as text. */
|
|
102
|
+
export interface HandoffAnswer {
|
|
103
|
+
kind: "handoff" | "empty";
|
|
104
|
+
text: string;
|
|
105
|
+
}
|
|
106
|
+
export interface WhatsNewAnswer {
|
|
107
|
+
kind: "updates" | "none";
|
|
108
|
+
text: string;
|
|
109
|
+
}
|
|
110
|
+
export interface StatusAnswer {
|
|
111
|
+
/** Whether the Mida service answered at all. */
|
|
112
|
+
up: boolean;
|
|
113
|
+
/** The same lines `mida_status` prints — the service line, then this agent's verdict. */
|
|
114
|
+
text: string;
|
|
115
|
+
service?: {
|
|
116
|
+
pid: number | null;
|
|
117
|
+
startedAt: string | null;
|
|
118
|
+
queueDepth: number | null;
|
|
119
|
+
};
|
|
120
|
+
agent?: {
|
|
121
|
+
name: string;
|
|
122
|
+
verdict: "approved" | "not-approved" | "revoked" | "general-assistance" | "unknown";
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The seven calls every transport answers. `local` talks to the Mida service over this machine's
|
|
127
|
+
* private socket; `direct` arrives in phase 2 with Sign in with Mida.
|
|
128
|
+
*/
|
|
129
|
+
export interface Transport {
|
|
130
|
+
context(input: ContextInput): Promise<ContextResult>;
|
|
131
|
+
remember(input: RememberInput): Promise<RememberResult>;
|
|
132
|
+
requestAccess(): Promise<RequestAccessResult>;
|
|
133
|
+
verify(item: ContextItem): Promise<VerifyResult>;
|
|
134
|
+
handoff(): Promise<HandoffAnswer>;
|
|
135
|
+
whatsNew(): Promise<WhatsNewAnswer>;
|
|
136
|
+
status(): Promise<StatusAnswer>;
|
|
137
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import type { Address, Hex } from "./types.js";
|
|
2
|
+
/** Why the contract skipped a save (SaveRejected.reason). Mirrors BatchAnchor.sol. */
|
|
3
|
+
export declare const BATCH_REJECT: {
|
|
4
|
+
readonly BAD_SIGNER: 1;
|
|
5
|
+
readonly BAD_SHAPE: 2;
|
|
6
|
+
readonly BAD_AREA: 3;
|
|
7
|
+
readonly BAD_EPOCH: 4;
|
|
8
|
+
readonly NO_AUTHORITY: 5;
|
|
9
|
+
readonly ALREADY_ANCHORED: 6;
|
|
10
|
+
readonly STALE_PARENT: 7;
|
|
11
|
+
};
|
|
12
|
+
export type BatchRejectReason = keyof typeof BATCH_REJECT;
|
|
13
|
+
export declare const BATCH_ANCHOR_DOMAIN_NAME = "Mida Batch Anchor";
|
|
14
|
+
export declare const BATCH_SAVE_TYPES: {
|
|
15
|
+
readonly MidaBatchSaveV1: readonly [{
|
|
16
|
+
readonly name: "owner";
|
|
17
|
+
readonly type: "address";
|
|
18
|
+
}, {
|
|
19
|
+
readonly name: "namespaceId";
|
|
20
|
+
readonly type: "bytes32";
|
|
21
|
+
}, {
|
|
22
|
+
readonly name: "objectNonce";
|
|
23
|
+
readonly type: "bytes32";
|
|
24
|
+
}, {
|
|
25
|
+
readonly name: "lineageId";
|
|
26
|
+
readonly type: "bytes32";
|
|
27
|
+
}, {
|
|
28
|
+
readonly name: "parentId";
|
|
29
|
+
readonly type: "bytes32";
|
|
30
|
+
}, {
|
|
31
|
+
readonly name: "parentVersion";
|
|
32
|
+
readonly type: "uint32";
|
|
33
|
+
}, {
|
|
34
|
+
readonly name: "rootAuthor";
|
|
35
|
+
readonly type: "bytes32";
|
|
36
|
+
}, {
|
|
37
|
+
readonly name: "manifestHash";
|
|
38
|
+
readonly type: "bytes32";
|
|
39
|
+
}, {
|
|
40
|
+
readonly name: "ciphertextCommitment";
|
|
41
|
+
readonly type: "bytes32";
|
|
42
|
+
}, {
|
|
43
|
+
readonly name: "readEpoch";
|
|
44
|
+
readonly type: "uint64";
|
|
45
|
+
}, {
|
|
46
|
+
readonly name: "expiresAt";
|
|
47
|
+
readonly type: "uint64";
|
|
48
|
+
}, {
|
|
49
|
+
readonly name: "kind";
|
|
50
|
+
readonly type: "uint8";
|
|
51
|
+
}, {
|
|
52
|
+
readonly name: "provenanceSource";
|
|
53
|
+
readonly type: "uint8";
|
|
54
|
+
}];
|
|
55
|
+
};
|
|
56
|
+
/** What an agent signs for one batched save. A new lineage has lineageId = parentId = rootAuthor = 0, parentVersion = 0. */
|
|
57
|
+
export interface BatchSaveMessage {
|
|
58
|
+
owner: Address;
|
|
59
|
+
namespaceId: Hex;
|
|
60
|
+
objectNonce: Hex;
|
|
61
|
+
lineageId: Hex;
|
|
62
|
+
parentId: Hex;
|
|
63
|
+
parentVersion: number;
|
|
64
|
+
rootAuthor: Hex;
|
|
65
|
+
manifestHash: Hex;
|
|
66
|
+
ciphertextCommitment: Hex;
|
|
67
|
+
readEpoch: bigint;
|
|
68
|
+
expiresAt: bigint;
|
|
69
|
+
kind: number;
|
|
70
|
+
provenanceSource: number;
|
|
71
|
+
}
|
|
72
|
+
export declare function batchSaveTypedData(input: {
|
|
73
|
+
chainId: bigint;
|
|
74
|
+
batchAnchor: Address;
|
|
75
|
+
message: BatchSaveMessage;
|
|
76
|
+
}): {
|
|
77
|
+
domain: {
|
|
78
|
+
name: string;
|
|
79
|
+
version: string;
|
|
80
|
+
chainId: bigint;
|
|
81
|
+
verifyingContract: `0x${string}`;
|
|
82
|
+
};
|
|
83
|
+
types: {
|
|
84
|
+
readonly MidaBatchSaveV1: readonly [{
|
|
85
|
+
readonly name: "owner";
|
|
86
|
+
readonly type: "address";
|
|
87
|
+
}, {
|
|
88
|
+
readonly name: "namespaceId";
|
|
89
|
+
readonly type: "bytes32";
|
|
90
|
+
}, {
|
|
91
|
+
readonly name: "objectNonce";
|
|
92
|
+
readonly type: "bytes32";
|
|
93
|
+
}, {
|
|
94
|
+
readonly name: "lineageId";
|
|
95
|
+
readonly type: "bytes32";
|
|
96
|
+
}, {
|
|
97
|
+
readonly name: "parentId";
|
|
98
|
+
readonly type: "bytes32";
|
|
99
|
+
}, {
|
|
100
|
+
readonly name: "parentVersion";
|
|
101
|
+
readonly type: "uint32";
|
|
102
|
+
}, {
|
|
103
|
+
readonly name: "rootAuthor";
|
|
104
|
+
readonly type: "bytes32";
|
|
105
|
+
}, {
|
|
106
|
+
readonly name: "manifestHash";
|
|
107
|
+
readonly type: "bytes32";
|
|
108
|
+
}, {
|
|
109
|
+
readonly name: "ciphertextCommitment";
|
|
110
|
+
readonly type: "bytes32";
|
|
111
|
+
}, {
|
|
112
|
+
readonly name: "readEpoch";
|
|
113
|
+
readonly type: "uint64";
|
|
114
|
+
}, {
|
|
115
|
+
readonly name: "expiresAt";
|
|
116
|
+
readonly type: "uint64";
|
|
117
|
+
}, {
|
|
118
|
+
readonly name: "kind";
|
|
119
|
+
readonly type: "uint8";
|
|
120
|
+
}, {
|
|
121
|
+
readonly name: "provenanceSource";
|
|
122
|
+
readonly type: "uint8";
|
|
123
|
+
}];
|
|
124
|
+
};
|
|
125
|
+
primaryType: "MidaBatchSaveV1";
|
|
126
|
+
message: BatchSaveMessage;
|
|
127
|
+
};
|
|
128
|
+
export declare function batchSaveDigest(input: {
|
|
129
|
+
chainId: bigint;
|
|
130
|
+
batchAnchor: Address;
|
|
131
|
+
message: BatchSaveMessage;
|
|
132
|
+
}): Hex;
|
|
133
|
+
export declare const BATCH_SAVE_TYPEHASH: `0x${string}`;
|
|
134
|
+
/** The EIP-712 struct hash (not the digest); it is what the leaf binds. */
|
|
135
|
+
export declare function batchSaveStructHash(m: BatchSaveMessage): Hex;
|
|
136
|
+
export declare function batchContextId(i: {
|
|
137
|
+
chainId: bigint;
|
|
138
|
+
batchAnchor: Address;
|
|
139
|
+
owner: Address;
|
|
140
|
+
agentId: Hex;
|
|
141
|
+
namespaceId: Hex;
|
|
142
|
+
parentId: Hex;
|
|
143
|
+
objectNonce: Hex;
|
|
144
|
+
}): Hex;
|
|
145
|
+
export declare function batchLeafHash(i: {
|
|
146
|
+
contextId: Hex;
|
|
147
|
+
agentId: Hex;
|
|
148
|
+
lineageId: Hex;
|
|
149
|
+
version: number;
|
|
150
|
+
structHash: Hex;
|
|
151
|
+
}): Hex;
|
|
152
|
+
export declare function headCommit(i: {
|
|
153
|
+
contextId: Hex;
|
|
154
|
+
owner: Address;
|
|
155
|
+
namespaceId: Hex;
|
|
156
|
+
rootAuthor: Hex;
|
|
157
|
+
version: number;
|
|
158
|
+
}): Hex;
|
|
159
|
+
export declare function merkleRoot(leaves: readonly Hex[]): Hex;
|
|
160
|
+
export declare function merkleProof(leaves: readonly Hex[], index: number): Hex[];
|
|
161
|
+
export declare function verifyMerkleProof(leaf: Hex, proof: readonly Hex[], root: Hex): boolean;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export declare const PERMISSION: {
|
|
2
|
+
readonly READ: 1;
|
|
3
|
+
readonly CREATE: 2;
|
|
4
|
+
readonly SUPERSEDE_OWN: 4;
|
|
5
|
+
readonly SUPERSEDE_ANY: 8;
|
|
6
|
+
};
|
|
7
|
+
export type Permission = keyof typeof PERMISSION;
|
|
8
|
+
export declare const KNOWN_PERMISSION_BITS = 15;
|
|
9
|
+
export declare const PROVENANCE_POLICY: {
|
|
10
|
+
readonly ALLOW_INFERENCE: 1;
|
|
11
|
+
readonly ALLOW_IMPORTED: 2;
|
|
12
|
+
readonly ALLOW_EXTERNAL_ATTESTATION: 4;
|
|
13
|
+
};
|
|
14
|
+
export type ProvenancePolicy = keyof typeof PROVENANCE_POLICY;
|
|
15
|
+
export declare const KNOWN_PROVENANCE_BITS = 7;
|
|
16
|
+
export declare const RECORD_TYPE: {
|
|
17
|
+
readonly CONTEXT: 0;
|
|
18
|
+
readonly EVIDENCE: 1;
|
|
19
|
+
};
|
|
20
|
+
export type RecordType = keyof typeof RECORD_TYPE;
|
|
21
|
+
export declare const LINEAGE_POLICY: {
|
|
22
|
+
readonly STANDARD: 0;
|
|
23
|
+
readonly OWNER_CONTROLLED: 1;
|
|
24
|
+
};
|
|
25
|
+
export type LineagePolicy = keyof typeof LINEAGE_POLICY;
|
|
26
|
+
export declare const CONTEXT_KIND: {
|
|
27
|
+
readonly NONE: 0;
|
|
28
|
+
readonly FACT: 1;
|
|
29
|
+
readonly PREFERENCE: 2;
|
|
30
|
+
readonly GOAL: 3;
|
|
31
|
+
readonly DECISION: 4;
|
|
32
|
+
readonly EPISODE: 5;
|
|
33
|
+
readonly INFERENCE: 6;
|
|
34
|
+
readonly CREDENTIAL: 7;
|
|
35
|
+
readonly OPEN_LOOP: 8;
|
|
36
|
+
};
|
|
37
|
+
export type ContextKind = keyof typeof CONTEXT_KIND;
|
|
38
|
+
export declare const PROVENANCE_SOURCE: {
|
|
39
|
+
readonly NONE: 0;
|
|
40
|
+
readonly USER_ASSERTED: 1;
|
|
41
|
+
readonly USER_CONFIRMED: 2;
|
|
42
|
+
readonly AGENT_INFERRED: 3;
|
|
43
|
+
readonly IMPORTED: 4;
|
|
44
|
+
readonly EXTERNAL_ATTESTATION: 5;
|
|
45
|
+
};
|
|
46
|
+
export type ProvenanceSource = keyof typeof PROVENANCE_SOURCE;
|
|
47
|
+
export declare const RECORD_RELATION_CODE: {
|
|
48
|
+
readonly supports: 1;
|
|
49
|
+
readonly derived_from: 2;
|
|
50
|
+
readonly confirmed_from: 3;
|
|
51
|
+
};
|
|
52
|
+
export type RecordRelation = keyof typeof RECORD_RELATION_CODE;
|
|
53
|
+
export declare const POLICY_VERSION: "mida-grant-policy-v1";
|
|
54
|
+
export declare const NAMESPACE_TREE_VERSION: "mida-namespace-tree-v1";
|
|
55
|
+
export declare const CRYPTO_VERSION: "mida-crypto-v1";
|
|
56
|
+
export declare const MAX_PAYLOAD_BYTES = 65536;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** §12.6 typed failures, §14.8 advisor hard failures, then plan decision 3 implementation codes. */
|
|
2
|
+
export declare const MIDA_ERROR_CODES: readonly ["CAPABILITY_DENIED", "CAPABILITY_EXPIRED", "CAPABILITY_REVOKED", "EPOCH_ROTATION_REQUIRED", "EPOCH_STALE", "NO_EPOCH_WRAP", "WRAP_KEY_VERSION_MISMATCH", "MANIFEST_MISMATCH", "CONTENT_HASH_MISMATCH", "COMMITMENT_MISMATCH", "DECRYPT_FAILED", "INVALID_NAMESPACE", "STALE_PARENT", "EVIDENCE_IMMUTABLE", "PROVENANCE_FORBIDDEN", "ANCHOR_OWNER_ONLY", "MANIFEST_NOT_FOUND", "MANIFEST_HASH_MISMATCH", "MANIFEST_SIGNATURE_INVALID", "MANIFEST_STALE", "AGENT_ID_MISMATCH", "PURPOSE_UNKNOWN", "REQUEST_SIGNATURE_INVALID", "NAMESPACE_TREE_VERSION_UNSUPPORTED", "POLICY_VERSION_UNSUPPORTED", "INVALID_WIRE", "PAYLOAD_TOO_LARGE", "ZERO_KEY", "AUTH_INVALID", "REPLAY", "REQUEST_EXPIRED", "REQUEST_CONSUMED", "RESPONSE_MISMATCH", "NOT_FOUND", "GAS_CEILING_EXCEEDED", "OWNER_WALLET_LOW", "PARTIAL_READ", "SPONSOR_FAILED", "SPONSOR_PENDING", "SEND_TIMEOUT", "WRITE_DENIED", "CHAIN_UNAVAILABLE", "CHAIN_MISCONFIGURED", "RPC_AUTH_REJECTED", "INTERNAL_ERROR"];
|
|
3
|
+
export type MidaErrorCode = (typeof MIDA_ERROR_CODES)[number];
|
|
4
|
+
export declare class MidaError extends Error {
|
|
5
|
+
readonly code: MidaErrorCode;
|
|
6
|
+
/**
|
|
7
|
+
* GAS_CEILING_EXCEEDED only: the estimate that was refused and the ceiling it was compared
|
|
8
|
+
* against. A caller that re-sizes — the batcher shrinking a refused take — reads the numbers
|
|
9
|
+
* here rather than parsing them back out of the message text.
|
|
10
|
+
*/
|
|
11
|
+
estimate?: bigint;
|
|
12
|
+
ceiling?: bigint;
|
|
13
|
+
constructor(code: MidaErrorCode, detail?: string);
|
|
14
|
+
}
|
|
15
|
+
export declare function isMidaError(value: unknown, code?: MidaErrorCode): value is MidaError;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Address, Hex } from "viem";
|
|
2
|
+
import type { GrantScope, RecordReference, RequestedScope } from "./types.js";
|
|
3
|
+
export declare const OWNER_AUTHOR_ID: Hex;
|
|
4
|
+
export declare const hashString: (value: string) => Hex;
|
|
5
|
+
export declare const POLICY_VERSION_HASH: Hex;
|
|
6
|
+
export declare const NAMESPACE_TREE_VERSION_HASH: Hex;
|
|
7
|
+
export declare function agentId(input: {
|
|
8
|
+
chainId: bigint;
|
|
9
|
+
capabilityRegistry: Address;
|
|
10
|
+
operator: Address;
|
|
11
|
+
agentSalt: Hex;
|
|
12
|
+
}): Hex;
|
|
13
|
+
export declare function contextId(input: {
|
|
14
|
+
chainId: bigint;
|
|
15
|
+
contextRegistry: Address;
|
|
16
|
+
owner: Address;
|
|
17
|
+
authorId: Hex;
|
|
18
|
+
namespaceId: Hex;
|
|
19
|
+
objectNonce: Hex;
|
|
20
|
+
}): Hex;
|
|
21
|
+
export declare function sortScopes<T extends RequestedScope>(scopes: readonly T[]): T[];
|
|
22
|
+
export declare function assertCanonicalScopes(scopes: readonly RequestedScope[]): void;
|
|
23
|
+
/** Hashes in the order given. Call sortScopes and assertCanonicalScopes first. */
|
|
24
|
+
export declare function scopesHash(scopes: readonly RequestedScope[]): Hex;
|
|
25
|
+
export declare function capabilityId(input: {
|
|
26
|
+
owner: Address;
|
|
27
|
+
agentId: Hex;
|
|
28
|
+
grantNonce: bigint;
|
|
29
|
+
index: bigint;
|
|
30
|
+
namespaceId: Hex;
|
|
31
|
+
permissions: number;
|
|
32
|
+
provenancePolicy: number;
|
|
33
|
+
expiresAt: bigint;
|
|
34
|
+
}): Hex;
|
|
35
|
+
export declare function grantDigest(input: {
|
|
36
|
+
chainId: bigint;
|
|
37
|
+
capabilityRegistry: Address;
|
|
38
|
+
owner: Address;
|
|
39
|
+
agentId: Hex;
|
|
40
|
+
requestHash: Hex;
|
|
41
|
+
manifestHash: Hex;
|
|
42
|
+
manifestVersion: bigint;
|
|
43
|
+
finalScopes: readonly GrantScope[];
|
|
44
|
+
expiresAt: bigint;
|
|
45
|
+
grantNonce: bigint;
|
|
46
|
+
}): Hex;
|
|
47
|
+
export interface CanonicalReference {
|
|
48
|
+
relationCode: number;
|
|
49
|
+
recordId: Hex;
|
|
50
|
+
}
|
|
51
|
+
export declare function canonicalReferences(references: readonly RecordReference[]): CanonicalReference[];
|
|
52
|
+
export declare function evidenceCommitment(references: readonly RecordReference[]): Hex;
|
|
53
|
+
export declare function p256RotationDigest(input: {
|
|
54
|
+
chainId: bigint;
|
|
55
|
+
capabilityRegistry: Address;
|
|
56
|
+
owner: Address;
|
|
57
|
+
newQx: bigint;
|
|
58
|
+
newQy: bigint;
|
|
59
|
+
nonce: bigint;
|
|
60
|
+
}): Hex;
|
|
61
|
+
export declare function cancelFastRevokeDigest(input: {
|
|
62
|
+
chainId: bigint;
|
|
63
|
+
capabilityRegistry: Address;
|
|
64
|
+
owner: Address;
|
|
65
|
+
revocationIntentId: Hex;
|
|
66
|
+
apiCancellationNonce: bigint;
|
|
67
|
+
expiresAt: bigint;
|
|
68
|
+
}): Hex;
|
|
69
|
+
export declare function canonicalizeOrigin(input: string, options?: {
|
|
70
|
+
allowLocalhost?: boolean;
|
|
71
|
+
}): string;
|
|
72
|
+
export declare const originHash: (canonicalOrigin: string) => Hex;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const PROTOCOL_VERSION: "mida-protocol-v1";
|
|
2
|
+
export * from "./errors.js";
|
|
3
|
+
export * from "./constants.js";
|
|
4
|
+
export * from "./types.js";
|
|
5
|
+
export * from "./wire.js";
|
|
6
|
+
export * from "./namespaces.js";
|
|
7
|
+
export * from "./ids.js";
|
|
8
|
+
export * from "./typed-data.js";
|
|
9
|
+
export * from "./batch.js";
|
|
10
|
+
export * from "./webauthn-assertion.js";
|
|
11
|
+
export * from "./owner-link.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Hex } from "viem";
|
|
2
|
+
export type IsolationDomain = "general" | "financial" | "relationships" | "private";
|
|
3
|
+
export interface NamespaceNode {
|
|
4
|
+
name: string;
|
|
5
|
+
parent: string | null;
|
|
6
|
+
domain: IsolationDomain;
|
|
7
|
+
id: Hex;
|
|
8
|
+
}
|
|
9
|
+
export declare function namespaceId(canonicalNamespace: string): Hex;
|
|
10
|
+
export declare const NAMESPACE_TREE_V1: readonly NamespaceNode[];
|
|
11
|
+
export declare function canonicalizeNamespace(input: string): string;
|
|
12
|
+
export declare function namespaceById(id: Hex): NamespaceNode;
|
|
13
|
+
/** Depth is at most two, so descendants are exactly the direct children. */
|
|
14
|
+
export declare function expandNamespace(input: string): string[];
|
|
15
|
+
export declare function domainOf(input: string): IsolationDomain;
|