@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,88 @@
|
|
|
1
|
+
import type { Deployment } from "../chain/index.js";
|
|
2
|
+
import type { AccessRequest, Address, Hex } from "../protocol/index.js";
|
|
3
|
+
import { MidaAgent } from "./agent.js";
|
|
4
|
+
import type { AccessRequestInput, Grant } from "./agent.js";
|
|
5
|
+
import type { AccessRequestStore, StoredAccessRequest } from "./request-store.js";
|
|
6
|
+
/**
|
|
7
|
+
* The public endpoints the published CLI and this SDK default to — the same constants
|
|
8
|
+
* `apps/midad` uses, re-exported there so there is one definition. "off" anywhere a URL is
|
|
9
|
+
* accepted opts back into the local store or self-paid gas.
|
|
10
|
+
*/
|
|
11
|
+
export declare const HOSTED_STORAGE_URL = "https://store.midacontext.xyz";
|
|
12
|
+
export declare const HOSTED_SPONSOR_URL = "https://sponsor.midacontext.xyz";
|
|
13
|
+
/** An agent identity as `mida init` writes it, or as an integrator holds it out-of-band. */
|
|
14
|
+
export interface ConnectIdentity {
|
|
15
|
+
agentId: Hex;
|
|
16
|
+
signerPrivateKey: Hex;
|
|
17
|
+
encryptionPrivateKey: Hex | Uint8Array;
|
|
18
|
+
callbackOrigin: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The network to connect to. Every field is optional: with no `network` at all the defaults are
|
|
22
|
+
* Monad testnet's public RPC, the embedded deployment record, the hosted store and the hosted
|
|
23
|
+
* sponsor. `"off"` on `storageUrl` means "the Context API the local daemon is serving" (home
|
|
24
|
+
* mode discovers it from `api-url.json`); on `sponsorUrl` it means "this wallet pays its own gas".
|
|
25
|
+
*/
|
|
26
|
+
export interface ConnectNetwork {
|
|
27
|
+
rpcUrl?: string;
|
|
28
|
+
deployment?: Deployment;
|
|
29
|
+
storageUrl?: string;
|
|
30
|
+
sponsorUrl?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface ConnectOptions {
|
|
33
|
+
/**
|
|
34
|
+
* Home mode: the name `mida init` provisioned the agent under. The identity, the grants
|
|
35
|
+
* completed so far, the owner address and the network all load from the Mida home
|
|
36
|
+
* (`midaHome`, `$MIDA_HOME`, or `~/.mida`), and `requestAccess` files the pending request
|
|
37
|
+
* where `mida approve <name>` finds it.
|
|
38
|
+
*/
|
|
39
|
+
name?: string;
|
|
40
|
+
/** The Mida home directory. Default: `$MIDA_HOME`, then `~/.mida`. */
|
|
41
|
+
midaHome?: string;
|
|
42
|
+
/** Environment overrides; defaults to `process.env`. `MIDA_HOME`, `MONAD_TESTNET_RPC`,
|
|
43
|
+
* `MIDA_STORAGE_URL`, `MIDA_SPONSOR_URL` and `MIDA_DEPLOYMENTS_DIR` are read. */
|
|
44
|
+
env?: Record<string, string | undefined>;
|
|
45
|
+
/**
|
|
46
|
+
* Explicit mode: the identity fields directly, no home files read. `owner` is then required —
|
|
47
|
+
* it is the owner address the agent will ask about and write under.
|
|
48
|
+
*/
|
|
49
|
+
identity?: ConnectIdentity;
|
|
50
|
+
owner?: Address;
|
|
51
|
+
network?: ConnectNetwork;
|
|
52
|
+
/** Defaults to the home-backed store in home mode, in-memory otherwise. */
|
|
53
|
+
requests?: AccessRequestStore;
|
|
54
|
+
/** Completed grants from an earlier run; in home mode `grants.json` is loaded when this is omitted. */
|
|
55
|
+
grants?: readonly Grant[];
|
|
56
|
+
}
|
|
57
|
+
/** What `connectAgent` returns: the agent plus the owner it connects to. */
|
|
58
|
+
export interface ConnectedAgent {
|
|
59
|
+
agent: MidaAgent;
|
|
60
|
+
owner: Address;
|
|
61
|
+
/** Present in home mode. */
|
|
62
|
+
name?: string;
|
|
63
|
+
/** Present in home mode — the directory the connection was loaded from. */
|
|
64
|
+
midaHome?: string;
|
|
65
|
+
/**
|
|
66
|
+
* `agent.createAccessRequest` plus, in home mode, recording the request as the pending one the
|
|
67
|
+
* owner's `mida approve <name>` acts on. In explicit mode the returned request must reach the
|
|
68
|
+
* owner's approval path some other way.
|
|
69
|
+
*/
|
|
70
|
+
requestAccess(input: AccessRequestInput): Promise<AccessRequest>;
|
|
71
|
+
}
|
|
72
|
+
/** A durable request store as one folder of `<requestId>.json` files plus `.consumed` markers —
|
|
73
|
+
* the same layout the Mida home keeps under `requests/<name>/`, so `mida approve` can complete a
|
|
74
|
+
* request this store saved. */
|
|
75
|
+
export declare class FileAccessRequestStore implements AccessRequestStore {
|
|
76
|
+
#private;
|
|
77
|
+
constructor(dir: string);
|
|
78
|
+
save(request: AccessRequest): Promise<void>;
|
|
79
|
+
load(requestId: Hex): Promise<StoredAccessRequest | undefined>;
|
|
80
|
+
markConsumed(requestId: Hex): Promise<void>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Connects an agent to a Mida owner. This is the SDK's front door: it builds the chain context,
|
|
84
|
+
* the Context API client and the `MidaAgent` from the provisioned identity (home mode) or fields
|
|
85
|
+
* passed directly (explicit mode) — the pieces a consumer could never construct from the public
|
|
86
|
+
* entry alone.
|
|
87
|
+
*/
|
|
88
|
+
export declare function connectAgent(options: ConnectOptions): ConnectedAgent;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./request-store.js";
|
|
2
|
+
export * from "./agent.js";
|
|
3
|
+
export * from "./batched.js";
|
|
4
|
+
export * from "./connect.js";
|
|
5
|
+
export { PERMISSION, PROVENANCE_POLICY } from "../protocol/index.js";
|
|
6
|
+
export type { AccessRequest, Address, Hex, PurposeId } from "../protocol/index.js";
|
|
7
|
+
export type { ScopeInput } from "../grant-advisor/index.js";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AccessRequest, Hex } from "../protocol/index.js";
|
|
2
|
+
export interface StoredAccessRequest {
|
|
3
|
+
request: AccessRequest;
|
|
4
|
+
consumed: boolean;
|
|
5
|
+
}
|
|
6
|
+
/** Where `createAccessRequest` persists originals by requestId so `completeAccessRequest` can check against them (§13.3). */
|
|
7
|
+
export interface AccessRequestStore {
|
|
8
|
+
save(request: AccessRequest): Promise<void>;
|
|
9
|
+
load(requestId: Hex): Promise<StoredAccessRequest | undefined>;
|
|
10
|
+
/**
|
|
11
|
+
* Compare-and-set the consumed flag in one atomic step: rejects with REQUEST_CONSUMED when the requestId is already
|
|
12
|
+
* consumed. The check in `completeAccessRequest` is only a fast path; this guard is the real "a request completes at
|
|
13
|
+
* most once" invariant, so durable stores must keep the same atomicity (for example a conditional UPDATE).
|
|
14
|
+
*/
|
|
15
|
+
markConsumed(requestId: Hex): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* In-memory store for Project 1. A consumed entry is kept for the life of the process so a requestId can never be
|
|
19
|
+
* completed twice. Production agents persist this across restarts.
|
|
20
|
+
*/
|
|
21
|
+
export declare class MemoryAccessRequestStore implements AccessRequestStore {
|
|
22
|
+
#private;
|
|
23
|
+
save(request: AccessRequest): Promise<void>;
|
|
24
|
+
load(requestId: Hex): Promise<StoredAccessRequest | undefined>;
|
|
25
|
+
markConsumed(requestId: Hex): Promise<void>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Hex, StorageRef } from "../protocol/index.js";
|
|
2
|
+
/** §9.2 */
|
|
3
|
+
export interface ContextStorage {
|
|
4
|
+
put(blob: Uint8Array): Promise<StorageRef[]>;
|
|
5
|
+
get(hash: Hex, hints?: StorageRef[]): Promise<Uint8Array>;
|
|
6
|
+
}
|
|
7
|
+
export declare function contentHash(blob: Uint8Array): Hex;
|
|
8
|
+
/** Every get path calls this before returning bytes. */
|
|
9
|
+
export declare function verifyContent(hash: Hex, blob: Uint8Array): Uint8Array;
|
|
10
|
+
export declare class MemoryStorage implements ContextStorage {
|
|
11
|
+
#private;
|
|
12
|
+
/** Tests may pass a shared map to simulate a provider that returns the wrong bytes. */
|
|
13
|
+
constructor(blobs?: Map<Hex, Uint8Array>);
|
|
14
|
+
put(blob: Uint8Array): Promise<StorageRef[]>;
|
|
15
|
+
get(hash: Hex, _hints?: StorageRef[]): Promise<Uint8Array>;
|
|
16
|
+
}
|
|
17
|
+
export declare class FsStorage implements ContextStorage {
|
|
18
|
+
#private;
|
|
19
|
+
constructor(directory: string);
|
|
20
|
+
pathFor(hash: Hex): string;
|
|
21
|
+
put(blob: Uint8Array): Promise<StorageRef[]>;
|
|
22
|
+
get(hash: Hex, _hints?: StorageRef[]): Promise<Uint8Array>;
|
|
23
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mida-context/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Give your agent the memory a user approved: read and write it through the user's Mida.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"private": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=22"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/damli40/mida-context.git",
|
|
26
|
+
"directory": "publish/sdk"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/damli40/mida-context#readme",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/damli40/mida-context/issues"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"ai-agents",
|
|
34
|
+
"memory",
|
|
35
|
+
"sdk",
|
|
36
|
+
"mcp",
|
|
37
|
+
"monad"
|
|
38
|
+
],
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@hono/node-server": "1.19.17",
|
|
41
|
+
"@noble/ciphers": "2.4.0",
|
|
42
|
+
"@noble/curves": "2.4.0",
|
|
43
|
+
"@noble/hashes": "2.4.0",
|
|
44
|
+
"canonicalize": "4.0.0",
|
|
45
|
+
"hono": "4.13.7",
|
|
46
|
+
"ox": "1.7.4",
|
|
47
|
+
"permissionless": "0.4.1",
|
|
48
|
+
"viem": "2.56.3"
|
|
49
|
+
}
|
|
50
|
+
}
|