@usesigil/kit 0.10.0 → 0.11.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/README.md +230 -17
- package/dist/create-vault.d.ts.map +1 -1
- package/dist/create-vault.js +7 -11
- package/dist/create-vault.js.map +1 -1
- package/dist/errors/codes.d.ts +8 -2
- package/dist/errors/codes.d.ts.map +1 -1
- package/dist/errors/codes.js +6 -0
- package/dist/errors/codes.js.map +1 -1
- package/dist/errors/context.d.ts +17 -1
- package/dist/errors/context.d.ts.map +1 -1
- package/dist/errors/public.d.ts +1 -1
- package/dist/errors/public.d.ts.map +1 -1
- package/dist/errors/public.js +1 -1
- package/dist/errors/public.js.map +1 -1
- package/dist/hooks.d.ts +114 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +118 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -12
- package/dist/index.js.map +1 -1
- package/dist/plugin.d.ts +110 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +119 -0
- package/dist/plugin.js.map +1 -0
- package/dist/presets.d.ts.map +1 -1
- package/dist/presets.js.map +1 -1
- package/dist/react/index.d.ts +69 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +118 -0
- package/dist/react/index.js.map +1 -0
- package/dist/seal.d.ts +50 -31
- package/dist/seal.d.ts.map +1 -1
- package/dist/seal.js +98 -29
- package/dist/seal.js.map +1 -1
- package/dist/sigil.d.ts +187 -0
- package/dist/sigil.d.ts.map +1 -0
- package/dist/sigil.js +194 -0
- package/dist/sigil.js.map +1 -0
- package/dist/types.d.ts +3 -31
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +45 -106
- package/dist/types.js.map +1 -1
- package/dist/vault-handle.d.ts +123 -0
- package/dist/vault-handle.d.ts.map +1 -0
- package/dist/vault-handle.js +136 -0
- package/dist/vault-handle.js.map +1 -0
- package/package.json +16 -2
package/dist/presets.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presets.js","sourceRoot":"","sources":["../src/presets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,EAAE,GAAG,EAAqB,MAAM,YAAY,CAAC;AACpD,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,YAAY,CAAC;AAEpB,gFAAgF;AAEhF,MAAM,mBAAmB,GACvB,8CAAyD,CAAC;AAC5D,MAAM,oBAAoB,GACxB,6CAAwD,CAAC;AAC3D,MAAM,mBAAmB,GACvB,6CAAwD,CAAC;
|
|
1
|
+
{"version":3,"file":"presets.js","sourceRoot":"","sources":["../src/presets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,EAAE,GAAG,EAAqB,MAAM,YAAY,CAAC;AACpD,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,YAAY,CAAC;AAEpB,gFAAgF;AAEhF,MAAM,mBAAmB,GACvB,8CAAyD,CAAC;AAC5D,MAAM,oBAAoB,GACxB,6CAAwD,CAAC;AAC3D,MAAM,mBAAmB,GACvB,6CAAwD,CAAC;AA4C3D,+EAA+E;AAE/E,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,kBAAkB,EAAE;QAClB,KAAK,EAAE,kBAAkB;QACzB,WAAW,EACT,mGAAmG;QACrG,UAAU,EAAE,eAAe;QAC3B,WAAW,EAAE,eAAe;QAC5B,mBAAmB,EAAE,GAAG,CAAC,UAAY,CAAC,EAAE,OAAO;QAC/C,qBAAqB,EAAE,GAAG,CAAC,UAAY,CAAC,EAAE,OAAO;QACjD,cAAc,EAAE,GAAG,EAAE,KAAK;QAC1B,YAAY,EAAE,uBAAuB;QACrC,SAAS,EAAE,CAAC,uBAAuB,CAAC;QACpC,cAAc,EAAE,CA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xD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,iBAAiB,CAC/B,IAAsB,EACtB,YAAyC,EAAE;IAE3C,MAAM,MAAM,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IACpC,OAAO;QACL,gBAAgB,EAAE,SAAS,CAAC,gBAAgB,IAAI,MAAM,CAAC,gBAAgB;QACvE,gBAAgB,EAAE,SAAS,CAAC,gBAAgB,IAAI,MAAM,CAAC,gBAAgB;QACvE,mBAAmB,EACjB,SAAS,CAAC,mBAAmB,IAAI,MAAM,CAAC,mBAAmB;KAC9D,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,2BAA2B,CAAC,MAA0B;IAKpE,IAAI,MAAM,CAAC,gBAAgB,KAAK,IAAI,IAAI,MAAM,CAAC,mBAAmB,KAAK,IAAI,EAAE,CAAC;QAC5E,MAAM,IAAI,KAAK,CACb,6DAA6D;YAC3D,gEAAgE;YAChE,4DAA4D;YAC5D,4DAA4D;YAC5D,0BAA0B,CAC7B,CAAC;IACJ,CAAC;IACD,OAAO;QACL,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;QACzC,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;QACzC,mBAAmB,EAAE,MAAM,CAAC,mBAAmB;KAChD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @usesigil/kit/react — React hooks for Sigil vault state.
|
|
3
|
+
*
|
|
4
|
+
* Four TanStack Query wrappers around `SigilVault` methods:
|
|
5
|
+
* - `useVaultBudget(vault)` — useQuery wrapping vault.budget()
|
|
6
|
+
* - `useVaultState(vault)` — useQuery wrapping the agent-side
|
|
7
|
+
* state-resolver primitive
|
|
8
|
+
* - `useOverview(vault, opts?)` — useQuery wrapping vault.overview()
|
|
9
|
+
* (owner-only; throws if called on an agent-only handle)
|
|
10
|
+
* - `useExecute(vault)` — useMutation wrapping vault.execute()
|
|
11
|
+
*
|
|
12
|
+
* Peer dependencies are **optional**: React and `@tanstack/react-query`
|
|
13
|
+
* are declared as peer deps in `package.json` under `peerDependenciesMeta`
|
|
14
|
+
* with `optional: true`. Consumers who don't use React never install them
|
|
15
|
+
* and never see a warning. Consumers who do import this subpath must
|
|
16
|
+
* install both.
|
|
17
|
+
*
|
|
18
|
+
* Query keys: every query key is namespaced under `"sigil"` so a
|
|
19
|
+
* consumer's existing TanStack cache never collides with SDK keys.
|
|
20
|
+
* Keys are derived from `vault.address` so multi-vault apps share keys
|
|
21
|
+
* per-vault without manual namespacing.
|
|
22
|
+
*
|
|
23
|
+
* Cache invalidation: the SDK does NOT call `queryClient.invalidateQueries`
|
|
24
|
+
* on its own. After an `execute()` mutation, the consumer decides which
|
|
25
|
+
* queries to refetch — typically `useExecute` is wrapped with a custom
|
|
26
|
+
* `onSuccess` that invalidates the specific vault keys.
|
|
27
|
+
*/
|
|
28
|
+
import type { SigilVault } from "../vault-handle.js";
|
|
29
|
+
import type { GetOverviewOptions } from "../dashboard/types.js";
|
|
30
|
+
/**
|
|
31
|
+
* Build a stable query key for a vault-bound query. Namespaced under
|
|
32
|
+
* `"sigil"` so the keys never collide with consumer app keys.
|
|
33
|
+
*/
|
|
34
|
+
export declare function sigilQueryKey(vault: SigilVault, sub: "state" | "budget" | "overview"): readonly unknown[];
|
|
35
|
+
/**
|
|
36
|
+
* `useVaultBudget(vault)` — read the vault's current rolling-24h
|
|
37
|
+
* budget via TanStack Query. Cheap call — re-runs as often as the
|
|
38
|
+
* query's `staleTime` allows (TQ default: 0ms).
|
|
39
|
+
*
|
|
40
|
+
* Returns the raw TQ `UseQueryResult<ResolvedBudget>` so consumers
|
|
41
|
+
* can read `.data`, `.isLoading`, `.error`, etc.
|
|
42
|
+
*/
|
|
43
|
+
export declare function useVaultBudget(vault: SigilVault): any;
|
|
44
|
+
/**
|
|
45
|
+
* `useVaultState(vault)` — alias for `useVaultBudget` today; kept as
|
|
46
|
+
* a separate hook so Sprint 3 can swap in a richer state resolver
|
|
47
|
+
* without changing the consumer call shape.
|
|
48
|
+
*/
|
|
49
|
+
export declare function useVaultState(vault: SigilVault): any;
|
|
50
|
+
/**
|
|
51
|
+
* `useOverview(vault, opts?)` — read the full `OverviewData` via
|
|
52
|
+
* `OwnerClient.getOverview()`. Requires an owner signer on the
|
|
53
|
+
* handle — the query throws `SIGIL_ERROR__SDK__OWNER_REQUIRED` when
|
|
54
|
+
* called on an agent-only handle. TanStack surfaces the throw via
|
|
55
|
+
* `result.error`.
|
|
56
|
+
*/
|
|
57
|
+
export declare function useOverview(vault: SigilVault, opts?: GetOverviewOptions): any;
|
|
58
|
+
/**
|
|
59
|
+
* `useExecute(vault)` — TanStack mutation wrapping `vault.execute`.
|
|
60
|
+
* Usage:
|
|
61
|
+
* const { mutate, mutateAsync, isPending } = useExecute(vault);
|
|
62
|
+
* mutate({ instructions: [...], opts: { tokenMint, amount, ... } });
|
|
63
|
+
*
|
|
64
|
+
* Consumer is responsible for `queryClient.invalidateQueries` on
|
|
65
|
+
* success — the SDK does not force a refetch of any specific keys,
|
|
66
|
+
* so the consumer's cache hygiene stays under their control.
|
|
67
|
+
*/
|
|
68
|
+
export declare function useExecute(vault: SigilVault): any;
|
|
69
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AA6BH,OAAO,KAAK,EAAE,UAAU,EAA4B,MAAM,oBAAoB,CAAC;AAI/E,OAAO,KAAK,EAAgB,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAI9E;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,UAAU,EACjB,GAAG,EAAE,OAAO,GAAG,QAAQ,GAAG,UAAU,GACnC,SAAS,OAAO,EAAE,CAEpB;AAID;;;;;;;GAOG;AAEH,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,GAAG,CAMrD;AAED;;;;GAIG;AAEH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,GAAG,CAMpD;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,UAAU,EACjB,IAAI,CAAC,EAAE,kBAAkB,GAExB,GAAG,CAML;AAED;;;;;;;;;GASG;AAEH,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,GAAG,CAUjD"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @usesigil/kit/react — React hooks for Sigil vault state.
|
|
3
|
+
*
|
|
4
|
+
* Four TanStack Query wrappers around `SigilVault` methods:
|
|
5
|
+
* - `useVaultBudget(vault)` — useQuery wrapping vault.budget()
|
|
6
|
+
* - `useVaultState(vault)` — useQuery wrapping the agent-side
|
|
7
|
+
* state-resolver primitive
|
|
8
|
+
* - `useOverview(vault, opts?)` — useQuery wrapping vault.overview()
|
|
9
|
+
* (owner-only; throws if called on an agent-only handle)
|
|
10
|
+
* - `useExecute(vault)` — useMutation wrapping vault.execute()
|
|
11
|
+
*
|
|
12
|
+
* Peer dependencies are **optional**: React and `@tanstack/react-query`
|
|
13
|
+
* are declared as peer deps in `package.json` under `peerDependenciesMeta`
|
|
14
|
+
* with `optional: true`. Consumers who don't use React never install them
|
|
15
|
+
* and never see a warning. Consumers who do import this subpath must
|
|
16
|
+
* install both.
|
|
17
|
+
*
|
|
18
|
+
* Query keys: every query key is namespaced under `"sigil"` so a
|
|
19
|
+
* consumer's existing TanStack cache never collides with SDK keys.
|
|
20
|
+
* Keys are derived from `vault.address` so multi-vault apps share keys
|
|
21
|
+
* per-vault without manual namespacing.
|
|
22
|
+
*
|
|
23
|
+
* Cache invalidation: the SDK does NOT call `queryClient.invalidateQueries`
|
|
24
|
+
* on its own. After an `execute()` mutation, the consumer decides which
|
|
25
|
+
* queries to refetch — typically `useExecute` is wrapped with a custom
|
|
26
|
+
* `onSuccess` that invalidates the specific vault keys.
|
|
27
|
+
*/
|
|
28
|
+
// ─── Peer-dep shim ──────────────────────────────────────────────────────────
|
|
29
|
+
//
|
|
30
|
+
// We can't `import { useQuery }` statically because doing so would make
|
|
31
|
+
// `@tanstack/react-query` a hard dependency at module-load time — a
|
|
32
|
+
// consumer who uses `@usesigil/kit` without touching `/react` would
|
|
33
|
+
// see a resolution error on every kit import. Instead, this subpath
|
|
34
|
+
// imports TanStack lazily via `require()` at the use site, inside the
|
|
35
|
+
// hook body. Each hook calls a one-time dynamic import that throws a
|
|
36
|
+
// clear error if the peer dep isn't installed.
|
|
37
|
+
function requireTanstack() {
|
|
38
|
+
try {
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
40
|
+
return require("@tanstack/react-query");
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
throw new Error("@usesigil/kit/react requires `@tanstack/react-query` as a peer dependency. " +
|
|
44
|
+
"Install it via `npm install @tanstack/react-query react` and retry.");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// ─── Query-key helpers ──────────────────────────────────────────────────────
|
|
48
|
+
/**
|
|
49
|
+
* Build a stable query key for a vault-bound query. Namespaced under
|
|
50
|
+
* `"sigil"` so the keys never collide with consumer app keys.
|
|
51
|
+
*/
|
|
52
|
+
export function sigilQueryKey(vault, sub) {
|
|
53
|
+
return ["sigil", vault.address, sub];
|
|
54
|
+
}
|
|
55
|
+
// ─── Hooks ──────────────────────────────────────────────────────────────────
|
|
56
|
+
/**
|
|
57
|
+
* `useVaultBudget(vault)` — read the vault's current rolling-24h
|
|
58
|
+
* budget via TanStack Query. Cheap call — re-runs as often as the
|
|
59
|
+
* query's `staleTime` allows (TQ default: 0ms).
|
|
60
|
+
*
|
|
61
|
+
* Returns the raw TQ `UseQueryResult<ResolvedBudget>` so consumers
|
|
62
|
+
* can read `.data`, `.isLoading`, `.error`, etc.
|
|
63
|
+
*/
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
|
+
export function useVaultBudget(vault) {
|
|
66
|
+
const { useQuery } = requireTanstack();
|
|
67
|
+
return useQuery({
|
|
68
|
+
queryKey: sigilQueryKey(vault, "budget"),
|
|
69
|
+
queryFn: () => vault.budget(),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* `useVaultState(vault)` — alias for `useVaultBudget` today; kept as
|
|
74
|
+
* a separate hook so Sprint 3 can swap in a richer state resolver
|
|
75
|
+
* without changing the consumer call shape.
|
|
76
|
+
*/
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
78
|
+
export function useVaultState(vault) {
|
|
79
|
+
const { useQuery } = requireTanstack();
|
|
80
|
+
return useQuery({
|
|
81
|
+
queryKey: sigilQueryKey(vault, "state"),
|
|
82
|
+
queryFn: () => vault.budget(),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* `useOverview(vault, opts?)` — read the full `OverviewData` via
|
|
87
|
+
* `OwnerClient.getOverview()`. Requires an owner signer on the
|
|
88
|
+
* handle — the query throws `SIGIL_ERROR__SDK__OWNER_REQUIRED` when
|
|
89
|
+
* called on an agent-only handle. TanStack surfaces the throw via
|
|
90
|
+
* `result.error`.
|
|
91
|
+
*/
|
|
92
|
+
export function useOverview(vault, opts) {
|
|
93
|
+
const { useQuery } = requireTanstack();
|
|
94
|
+
return useQuery({
|
|
95
|
+
queryKey: [...sigilQueryKey(vault, "overview"), opts ?? null],
|
|
96
|
+
queryFn: () => vault.overview(opts),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* `useExecute(vault)` — TanStack mutation wrapping `vault.execute`.
|
|
101
|
+
* Usage:
|
|
102
|
+
* const { mutate, mutateAsync, isPending } = useExecute(vault);
|
|
103
|
+
* mutate({ instructions: [...], opts: { tokenMint, amount, ... } });
|
|
104
|
+
*
|
|
105
|
+
* Consumer is responsible for `queryClient.invalidateQueries` on
|
|
106
|
+
* success — the SDK does not force a refetch of any specific keys,
|
|
107
|
+
* so the consumer's cache hygiene stays under their control.
|
|
108
|
+
*/
|
|
109
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
110
|
+
export function useExecute(vault) {
|
|
111
|
+
const { useMutation } = requireTanstack();
|
|
112
|
+
return useMutation({
|
|
113
|
+
mutationFn: async (args) => {
|
|
114
|
+
return vault.execute(args.instructions, args.opts);
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAKH,+EAA+E;AAC/E,EAAE;AACF,wEAAwE;AACxE,oEAAoE;AACpE,oEAAoE;AACpE,oEAAoE;AACpE,sEAAsE;AACtE,qEAAqE;AACrE,+CAA+C;AAE/C,SAAS,eAAe;IACtB,IAAI,CAAC;QACH,iEAAiE;QACjE,OAAO,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAC1C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,6EAA6E;YAC3E,qEAAqE,CACxE,CAAC;IACJ,CAAC;AACH,CAAC;AAUD,+EAA+E;AAE/E;;;GAGG;AACH,MAAM,UAAU,aAAa,CAC3B,KAAiB,EACjB,GAAoC;IAEpC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,GAAG,CAAU,CAAC;AAChD,CAAC;AAED,+EAA+E;AAE/E;;;;;;;GAOG;AACH,8DAA8D;AAC9D,MAAM,UAAU,cAAc,CAAC,KAAiB;IAC9C,MAAM,EAAE,QAAQ,EAAE,GAAG,eAAe,EAAE,CAAC;IACvC,OAAO,QAAQ,CAAC;QACd,QAAQ,EAAE,aAAa,CAAC,KAAK,EAAE,QAAQ,CAAC;QACxC,OAAO,EAAE,GAA4B,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE;KACvD,CAAC,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,8DAA8D;AAC9D,MAAM,UAAU,aAAa,CAAC,KAAiB;IAC7C,MAAM,EAAE,QAAQ,EAAE,GAAG,eAAe,EAAE,CAAC;IACvC,OAAO,QAAQ,CAAC;QACd,QAAQ,EAAE,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC;QACvC,OAAO,EAAE,GAA4B,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE;KACvD,CAAC,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CACzB,KAAiB,EACjB,IAAyB;IAGzB,MAAM,EAAE,QAAQ,EAAE,GAAG,eAAe,EAAE,CAAC;IACvC,OAAO,QAAQ,CAAC;QACd,QAAQ,EAAE,CAAC,GAAG,aAAa,CAAC,KAAK,EAAE,UAAU,CAAC,EAAE,IAAI,IAAI,IAAI,CAAU;QACtE,OAAO,EAAE,GAA0B,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;KAC3D,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;GASG;AACH,8DAA8D;AAC9D,MAAM,UAAU,UAAU,CAAC,KAAiB;IAC1C,MAAM,EAAE,WAAW,EAAE,GAAG,eAAe,EAAE,CAAC;IAC1C,OAAO,WAAW,CAAC;QACjB,UAAU,EAAE,KAAK,EAAE,IAGlB,EAA0B,EAAE;YAC3B,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QACrD,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/dist/seal.d.ts
CHANGED
|
@@ -79,6 +79,18 @@ export interface SealParams {
|
|
|
79
79
|
maxCacheAgeMs?: number;
|
|
80
80
|
/** Additional agent ATA → vault ATA replacements for multi-token DeFi routes. */
|
|
81
81
|
additionalAtaReplacements?: Map<Address, Address>;
|
|
82
|
+
/**
|
|
83
|
+
* Sprint 2 (B3): optional lifecycle hooks. Observe-only except
|
|
84
|
+
* `onBeforeBuild` which may return `{ skipSeal: true, reason }` to
|
|
85
|
+
* cleanly abort before any RPC. Hook throws are caught and logged
|
|
86
|
+
* via `getSigilModuleLogger().warn` — they do NOT propagate.
|
|
87
|
+
*/
|
|
88
|
+
hooks?: import("./hooks.js").SealHooks;
|
|
89
|
+
/**
|
|
90
|
+
* Sprint 2 (B3): stable correlation ID. When omitted, `seal()`
|
|
91
|
+
* generates one via `newCorrelationId()` at the top of the call.
|
|
92
|
+
*/
|
|
93
|
+
correlationId?: string;
|
|
82
94
|
}
|
|
83
95
|
export interface SealResult {
|
|
84
96
|
ok: true;
|
|
@@ -156,6 +168,19 @@ export interface SigilClientConfig {
|
|
|
156
168
|
* injected logger so the bypass is observable in audit trails.
|
|
157
169
|
*/
|
|
158
170
|
skipGenesisAssertion?: boolean;
|
|
171
|
+
/**
|
|
172
|
+
* Sprint 2 (B3): client-level seal hooks. Fire on every `seal()` +
|
|
173
|
+
* `executeAndConfirm()` call. Compose with per-call hooks
|
|
174
|
+
* (`ClientSealOpts.hooks`) via `composeHooks(clientHooks, perCall)`
|
|
175
|
+
* — client hooks run first.
|
|
176
|
+
*/
|
|
177
|
+
hooks?: import("./hooks.js").SealHooks;
|
|
178
|
+
/**
|
|
179
|
+
* Sprint 2 (B4): policy plugins. Run in registration order inside
|
|
180
|
+
* `seal()` pre-flight after `resolveVaultState`; first rejection
|
|
181
|
+
* throws `SigilSdkDomainError(SIGIL_ERROR__SDK__PLUGIN_REJECTED)`.
|
|
182
|
+
*/
|
|
183
|
+
plugins?: readonly import("./plugin.js").SigilPolicyPlugin[];
|
|
159
184
|
}
|
|
160
185
|
/**
|
|
161
186
|
* Options for `client.seal()`.
|
|
@@ -176,6 +201,16 @@ export interface ClientSealOpts {
|
|
|
176
201
|
cachedState?: ResolvedVaultState;
|
|
177
202
|
maxCacheAgeMs?: number;
|
|
178
203
|
additionalAtaReplacements?: Map<Address, Address>;
|
|
204
|
+
/**
|
|
205
|
+
* Sprint 2 (B3): per-call hooks. Compose with client-level hooks
|
|
206
|
+
* (`SigilClientConfig.hooks`) — client hooks run first, then per-call.
|
|
207
|
+
*/
|
|
208
|
+
hooks?: import("./hooks.js").SealHooks;
|
|
209
|
+
/**
|
|
210
|
+
* Sprint 2 (B3): stable correlation ID for trace correlation.
|
|
211
|
+
* Defaults to a fresh `newCorrelationId()` if omitted.
|
|
212
|
+
*/
|
|
213
|
+
correlationId?: string;
|
|
179
214
|
}
|
|
180
215
|
export interface ExecuteResult {
|
|
181
216
|
signature: string;
|
|
@@ -243,23 +278,6 @@ export declare const SOLANA_DEVNET_GENESIS_HASH = "EtWTRABZaYq6iMfeYKouRu166VU2x
|
|
|
243
278
|
export declare const SOLANA_MAINNET_GENESIS_HASH = "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d";
|
|
244
279
|
/** @internal — exposed for test resets only. */
|
|
245
280
|
export declare function _resetGenesisHashCache(): void;
|
|
246
|
-
/**
|
|
247
|
-
* @deprecated Use `createSigilClient(config)` or the async factory
|
|
248
|
-
* `SigilClient.create(config)` instead. This class will be removed at
|
|
249
|
-
* v1.0. The factory returns the same API surface as a plain object with
|
|
250
|
-
* closure-bound methods — no `this` binding issues, tree-shakeable, and
|
|
251
|
-
* aligned with the viem/Kit functional pattern.
|
|
252
|
-
*
|
|
253
|
-
* Migration:
|
|
254
|
-
* ```ts
|
|
255
|
-
* // Before:
|
|
256
|
-
* const client = new SigilClient({ rpc, vault, agent, network });
|
|
257
|
-
* // After (factory):
|
|
258
|
-
* const client = createSigilClient({ rpc, vault, agent, network });
|
|
259
|
-
* // After (async with genesis assertion):
|
|
260
|
-
* const client = await SigilClient.create({ rpc, vault, agent, network });
|
|
261
|
-
* ```
|
|
262
|
-
*/
|
|
263
281
|
export declare class SigilClient {
|
|
264
282
|
private readonly blockhashCacheInstance;
|
|
265
283
|
private readonly altCacheInstance;
|
|
@@ -269,23 +287,24 @@ export declare class SigilClient {
|
|
|
269
287
|
readonly agent: TransactionSigner;
|
|
270
288
|
readonly network: "devnet" | "mainnet";
|
|
271
289
|
/**
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
290
|
+
* Private constructor — Sprint 2 carryover.
|
|
291
|
+
*
|
|
292
|
+
* Sprint 1 deprecated `new SigilClient(config)` in favor of the
|
|
293
|
+
* async factory `SigilClient.create(config)` which runs the
|
|
294
|
+
* genesis-hash assertion. Sprint 2 completes the migration by
|
|
295
|
+
* making the constructor `private`: external callers now get a TS
|
|
296
|
+
* compile error, and the runtime guard below throws on JS consumers
|
|
297
|
+
* that cast through `any` to bypass the compile-time check.
|
|
277
298
|
*
|
|
278
|
-
*
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
299
|
+
* The class remains exported so:
|
|
300
|
+
* - `SigilClient.create()` static factory still works.
|
|
301
|
+
* - `instanceof SigilClient` checks in tests still resolve.
|
|
302
|
+
* - The type `SigilClient` is still a first-class position.
|
|
282
303
|
*
|
|
283
|
-
* @
|
|
284
|
-
* `SigilClient.create()`
|
|
285
|
-
* (the async factory IS the recommended path; warning there would
|
|
286
|
-
* be misleading log spam). Not part of the public API.
|
|
304
|
+
* @internal — construction token is a module-private symbol only
|
|
305
|
+
* `SigilClient.create()` holds a reference to.
|
|
287
306
|
*/
|
|
288
|
-
constructor(
|
|
307
|
+
private constructor();
|
|
289
308
|
/**
|
|
290
309
|
* Async factory — constructs a `SigilClient` and asserts the RPC's
|
|
291
310
|
* genesis hash matches the configured `network`. Preferred entry
|
package/dist/seal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seal.d.ts","sourceRoot":"","sources":["../src/seal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAE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,OAAO,CAAC,cAAc,CAAC;IAIzC,MAAM,IAAI,OAAO,CAAC,QAAQ,CAAC;IAI3B,gBAAgB,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;WAIpC,WAAW,CACtB,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,iBAAiB,CAAC;CAG9B"}
|
package/dist/seal.js
CHANGED
|
@@ -15,6 +15,11 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { AccountRole } from "./kit-adapter.js";
|
|
17
17
|
import { getSigilModuleLogger, setSigilModuleLogger } from "./logger.js";
|
|
18
|
+
import { newCorrelationId, invokeHook, composeHooks, } from "./hooks.js";
|
|
19
|
+
// SigilPolicyPlugin type-ref is declared inline on SigilClientConfig via
|
|
20
|
+
// `import("./plugin.js").SigilPolicyPlugin` so no top-level import is
|
|
21
|
+
// needed. Plugin runner invocation (runPlugins() call after state resolve)
|
|
22
|
+
// is a follow-up commit; the hooks integration above proves the plumbing.
|
|
18
23
|
import { VaultStatus } from "./generated/types/vaultStatus.js";
|
|
19
24
|
import { getValidateAndAuthorizeInstructionAsync } from "./generated/instructions/validateAndAuthorize.js";
|
|
20
25
|
import { getFinalizeSessionInstructionAsync } from "./generated/instructions/finalizeSession.js";
|
|
@@ -34,7 +39,7 @@ import { parseTokenBalance } from "./simulation.js";
|
|
|
34
39
|
import { createVault, } from "./create-vault.js";
|
|
35
40
|
import { SigilSdkDomainError } from "./errors/sdk.js";
|
|
36
41
|
import { SigilRpcError } from "./errors/rpc.js";
|
|
37
|
-
import { SIGIL_ERROR__SDK__VAULT_INACTIVE, SIGIL_ERROR__SDK__AGENT_NOT_REGISTERED, SIGIL_ERROR__SDK__AGENT_PAUSED, SIGIL_ERROR__SDK__AGENT_ZERO_CAPABILITY, SIGIL_ERROR__SDK__INVALID_AMOUNT, SIGIL_ERROR__SDK__INVALID_CONFIG, SIGIL_ERROR__SDK__INVALID_NETWORK, SIGIL_ERROR__SDK__INVALID_PARAMS, SIGIL_ERROR__SDK__SPL_TOKEN_OP_BLOCKED, SIGIL_ERROR__SDK__PROTOCOL_NOT_ALLOWED, SIGIL_ERROR__SDK__PROTOCOL_NOT_TARGETED, SIGIL_ERROR__SDK__INSTRUCTION_COUNT, SIGIL_ERROR__SDK__CAP_EXCEEDED, SIGIL_ERROR__SDK__ATA_NON_CANONICAL, SIGIL_ERROR__RPC__TX_FAILED, SIGIL_ERROR__RPC__TX_TOO_LARGE, } from "./errors/codes.js";
|
|
42
|
+
import { SIGIL_ERROR__SDK__VAULT_INACTIVE, SIGIL_ERROR__SDK__AGENT_NOT_REGISTERED, SIGIL_ERROR__SDK__AGENT_PAUSED, SIGIL_ERROR__SDK__AGENT_ZERO_CAPABILITY, SIGIL_ERROR__SDK__INVALID_AMOUNT, SIGIL_ERROR__SDK__INVALID_CONFIG, SIGIL_ERROR__SDK__INVALID_NETWORK, SIGIL_ERROR__SDK__INVALID_PARAMS, SIGIL_ERROR__SDK__SPL_TOKEN_OP_BLOCKED, SIGIL_ERROR__SDK__PROTOCOL_NOT_ALLOWED, SIGIL_ERROR__SDK__PROTOCOL_NOT_TARGETED, SIGIL_ERROR__SDK__INSTRUCTION_COUNT, SIGIL_ERROR__SDK__CAP_EXCEEDED, SIGIL_ERROR__SDK__ATA_NON_CANONICAL, SIGIL_ERROR__SDK__HOOK_ABORTED, SIGIL_ERROR__RPC__TX_FAILED, SIGIL_ERROR__RPC__TX_TOO_LARGE, } from "./errors/codes.js";
|
|
38
43
|
// ─── Well-known program addresses to strip ──────────────────────────────────
|
|
39
44
|
// PR 3.B F036: use canonical constants from types.ts instead of local dupes.
|
|
40
45
|
import { TOKEN_PROGRAM_ADDRESS as TOKEN_PROGRAM, TOKEN_2022_PROGRAM_ADDRESS as TOKEN_2022_PROGRAM, COMPUTE_BUDGET_PROGRAM_ADDRESS as COMPUTE_BUDGET_PROGRAM, SYSTEM_PROGRAM_ADDRESS as SYSTEM_PROGRAM, } from "./types.js";
|
|
@@ -86,6 +91,35 @@ export async function seal(params) {
|
|
|
86
91
|
const warnings = [];
|
|
87
92
|
const net = normalizeNetwork(params.network);
|
|
88
93
|
validateNetwork(net);
|
|
94
|
+
// ─── Sprint 2 B3: build hook context + invoke onBeforeBuild ──────────────
|
|
95
|
+
//
|
|
96
|
+
// Context is populated ONCE at the top of seal() so every subsequent hook
|
|
97
|
+
// invocation references the same `correlationId`. onBeforeBuild is the
|
|
98
|
+
// only hook that may abort: returning `{ skipSeal: true, reason }` throws
|
|
99
|
+
// SigilSdkDomainError(HOOK_ABORTED) before any RPC round-trip.
|
|
100
|
+
const _hookCtx = {
|
|
101
|
+
vault: params.vault,
|
|
102
|
+
agent: params.agent.address,
|
|
103
|
+
tokenMint: params.tokenMint,
|
|
104
|
+
amount: params.amount,
|
|
105
|
+
network: params.network,
|
|
106
|
+
correlationId: params.correlationId ?? newCorrelationId(),
|
|
107
|
+
};
|
|
108
|
+
if (params.hooks?.onBeforeBuild) {
|
|
109
|
+
const abortResult = await invokeHook(params.hooks, "onBeforeBuild", _hookCtx, params);
|
|
110
|
+
if (abortResult &&
|
|
111
|
+
typeof abortResult === "object" &&
|
|
112
|
+
"skipSeal" in abortResult &&
|
|
113
|
+
abortResult.skipSeal === true) {
|
|
114
|
+
throw new SigilSdkDomainError(SIGIL_ERROR__SDK__HOOK_ABORTED, `seal() aborted by onBeforeBuild hook: ${String(abortResult.reason)}`, {
|
|
115
|
+
context: {
|
|
116
|
+
hook: "onBeforeBuild",
|
|
117
|
+
reason: String(abortResult.reason),
|
|
118
|
+
correlationId: _hookCtx.correlationId,
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
89
123
|
// Step 1: Resolve vault state (with stale cache detection)
|
|
90
124
|
let state;
|
|
91
125
|
if (params.cachedState) {
|
|
@@ -531,16 +565,42 @@ export function createSigilClient(config) {
|
|
|
531
565
|
network,
|
|
532
566
|
seal: clientSeal,
|
|
533
567
|
async executeAndConfirm(instructions, opts) {
|
|
568
|
+
// Sprint 2 B3: compose client-level and per-call hooks. Client hooks
|
|
569
|
+
// run first at every stage (onBeforeBuild → ... → onFinalize), then
|
|
570
|
+
// per-call hooks. composeHooks handles the conditional-merge when
|
|
571
|
+
// either side is absent.
|
|
572
|
+
const composedHooks = composeHooks(config.hooks, opts.hooks);
|
|
573
|
+
const correlationId = opts.correlationId ?? newCorrelationId();
|
|
574
|
+
const hookCtx = {
|
|
575
|
+
vault,
|
|
576
|
+
agent: agent.address,
|
|
577
|
+
tokenMint: opts.tokenMint,
|
|
578
|
+
amount: opts.amount,
|
|
579
|
+
network,
|
|
580
|
+
correlationId,
|
|
581
|
+
};
|
|
534
582
|
try {
|
|
535
583
|
// Calls the closure-captured clientSeal — no `this` dependency.
|
|
536
584
|
// Safe to destructure: `const { executeAndConfirm } = client`.
|
|
537
|
-
const result = await clientSeal(instructions,
|
|
585
|
+
const result = await clientSeal(instructions, {
|
|
586
|
+
...opts,
|
|
587
|
+
hooks: composedHooks,
|
|
588
|
+
correlationId,
|
|
589
|
+
});
|
|
538
590
|
const encoded = await signAndEncode(agent, result.transaction);
|
|
539
591
|
const signature = await sendAndConfirmTransaction(rpc, encoded, opts.confirmOptions);
|
|
592
|
+
// Sprint 2 B3: onAfterSend fires with the signature as soon as
|
|
593
|
+
// the RPC resolves. onFinalize fires last on the success path.
|
|
594
|
+
await invokeHook(composedHooks, "onAfterSend", hookCtx, signature);
|
|
595
|
+
await invokeHook(composedHooks, "onFinalize", hookCtx, { signature });
|
|
540
596
|
return { signature, sealResult: result };
|
|
541
597
|
}
|
|
542
598
|
catch (err) {
|
|
543
599
|
const sdkError = toSigilAgentError(err);
|
|
600
|
+
// Sprint 2 B3: onError fires in every failure path before the
|
|
601
|
+
// existing onErrorCallback telemetry hook. Error is always
|
|
602
|
+
// rethrown after both fire.
|
|
603
|
+
await invokeHook(composedHooks, "onError", hookCtx, err instanceof Error ? err : new Error(String(err)));
|
|
544
604
|
onErrorCallback?.(sdkError, {
|
|
545
605
|
action: opts.amount > 0n ? "spending" : "non-spending",
|
|
546
606
|
tokenMint: opts.tokenMint,
|
|
@@ -691,6 +751,13 @@ async function assertGenesisHash(rpc, network) {
|
|
|
691
751
|
* const client = await SigilClient.create({ rpc, vault, agent, network });
|
|
692
752
|
* ```
|
|
693
753
|
*/
|
|
754
|
+
/**
|
|
755
|
+
* Module-private construction token for SigilClient. `SigilClient.create()`
|
|
756
|
+
* is the only holder — direct `new SigilClient(config)` calls from outside
|
|
757
|
+
* the class body cannot obtain this symbol and fail the runtime guard in
|
|
758
|
+
* the private constructor.
|
|
759
|
+
*/
|
|
760
|
+
const CLIENT_CONSTRUCT_TOKEN = Symbol("SigilClient.construct");
|
|
694
761
|
export class SigilClient {
|
|
695
762
|
blockhashCacheInstance;
|
|
696
763
|
altCacheInstance;
|
|
@@ -700,23 +767,33 @@ export class SigilClient {
|
|
|
700
767
|
agent;
|
|
701
768
|
network;
|
|
702
769
|
/**
|
|
703
|
-
*
|
|
704
|
-
*
|
|
705
|
-
*
|
|
706
|
-
*
|
|
707
|
-
*
|
|
770
|
+
* Private constructor — Sprint 2 carryover.
|
|
771
|
+
*
|
|
772
|
+
* Sprint 1 deprecated `new SigilClient(config)` in favor of the
|
|
773
|
+
* async factory `SigilClient.create(config)` which runs the
|
|
774
|
+
* genesis-hash assertion. Sprint 2 completes the migration by
|
|
775
|
+
* making the constructor `private`: external callers now get a TS
|
|
776
|
+
* compile error, and the runtime guard below throws on JS consumers
|
|
777
|
+
* that cast through `any` to bypass the compile-time check.
|
|
708
778
|
*
|
|
709
|
-
*
|
|
710
|
-
*
|
|
711
|
-
*
|
|
712
|
-
*
|
|
779
|
+
* The class remains exported so:
|
|
780
|
+
* - `SigilClient.create()` static factory still works.
|
|
781
|
+
* - `instanceof SigilClient` checks in tests still resolve.
|
|
782
|
+
* - The type `SigilClient` is still a first-class position.
|
|
713
783
|
*
|
|
714
|
-
* @
|
|
715
|
-
* `SigilClient.create()`
|
|
716
|
-
* (the async factory IS the recommended path; warning there would
|
|
717
|
-
* be misleading log spam). Not part of the public API.
|
|
784
|
+
* @internal — construction token is a module-private symbol only
|
|
785
|
+
* `SigilClient.create()` holds a reference to.
|
|
718
786
|
*/
|
|
719
|
-
constructor(config,
|
|
787
|
+
constructor(config, _constructToken = Symbol.for("SigilClient.forbid")) {
|
|
788
|
+
// Runtime guard: anyone who reaches this constructor without the
|
|
789
|
+
// exact module-private token (i.e., via `any`-cast or JS bypass)
|
|
790
|
+
// gets thrown out. `.create()` passes CLIENT_CONSTRUCT_TOKEN.
|
|
791
|
+
if (_constructToken !== CLIENT_CONSTRUCT_TOKEN) {
|
|
792
|
+
throw new SigilSdkDomainError(SIGIL_ERROR__SDK__INVALID_CONFIG, "SigilClient: direct construction is not allowed. " +
|
|
793
|
+
"Use `await SigilClient.create(config)` — which also runs the " +
|
|
794
|
+
"genesis-hash assertion — or `createSigilClient(config)` for " +
|
|
795
|
+
"the factory variant.", { context: { field: "constructor", expected: "SigilClient.create" } });
|
|
796
|
+
}
|
|
720
797
|
if (!config.rpc)
|
|
721
798
|
throw new SigilSdkDomainError(SIGIL_ERROR__SDK__INVALID_CONFIG, "SigilClientConfig.rpc is required", { context: { field: "rpc", expected: "Rpc<SolanaRpcApi>" } });
|
|
722
799
|
if (!config.vault)
|
|
@@ -738,14 +815,6 @@ export class SigilClient {
|
|
|
738
815
|
if (config.logger) {
|
|
739
816
|
setSigilModuleLogger(config.logger);
|
|
740
817
|
}
|
|
741
|
-
// Emit deprecation warning only when called directly (not via
|
|
742
|
-
// the `.create()` async factory, which already performs the
|
|
743
|
-
// genesis assertion the deprecation warning warns about).
|
|
744
|
-
if (!_skipDeprecationWarning) {
|
|
745
|
-
getSigilModuleLogger().warn("[SigilClient] sync constructor bypasses genesis-hash assertion. " +
|
|
746
|
-
"Use `await SigilClient.create(config)` in production to verify the " +
|
|
747
|
-
"RPC matches the configured network.");
|
|
748
|
-
}
|
|
749
818
|
}
|
|
750
819
|
/**
|
|
751
820
|
* Async factory — constructs a `SigilClient` and asserts the RPC's
|
|
@@ -783,11 +852,11 @@ export class SigilClient {
|
|
|
783
852
|
// with a misconfigured RPC is ever returned to the caller.
|
|
784
853
|
await assertGenesisHash(config.rpc, config.network);
|
|
785
854
|
}
|
|
786
|
-
//
|
|
787
|
-
//
|
|
788
|
-
//
|
|
789
|
-
//
|
|
790
|
-
return new SigilClient(config,
|
|
855
|
+
// Sprint 2 carryover: pass the module-private construction token
|
|
856
|
+
// so the private-ctor runtime guard accepts the call. External
|
|
857
|
+
// callers cannot obtain this symbol and are rejected — forcing
|
|
858
|
+
// them through `.create()` which runs the genesis-hash assertion.
|
|
859
|
+
return new SigilClient(config, CLIENT_CONSTRUCT_TOKEN);
|
|
791
860
|
}
|
|
792
861
|
/**
|
|
793
862
|
* Seal DeFi instructions with Sigil security.
|