@agenticprimitives/delegated-signer 0.0.0-alpha.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Agentic Trust Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # @agenticprimitives/delegated-signer
2
+
3
+ Generic **named delegated-signer resolution** (spec 276). Compose the trust primitives into one
4
+ answer: _"give me a signer for the named identity X, authorized by delegation chain Y."_
5
+
6
+ ```ts
7
+ import { resolveDelegatedSigner } from '@agenticprimitives/delegated-signer';
8
+
9
+ const resolved = await resolveDelegatedSigner({
10
+ name: 'acme', // opaque label — resolved by your injected client
11
+ signer: kmsBackend, // a KmsAccountBackend from @agenticprimitives/key-custody
12
+ delegationChain: [root, leaf], // Delegation[] from @agenticprimitives/delegation
13
+ resolveName: async (n) => nameClient.resolve(n), // agent-naming (injected)
14
+ verifyAccount: async (sa) => accountClient.isValid(sa), // agent-account (injected)
15
+ chainId: 8453,
16
+ delegationManager: '0x…',
17
+ });
18
+
19
+ const sig = await resolved.sign(digest); // 0x-hex (r,s,v) signature by resolved.signerAddress
20
+ ```
21
+
22
+ It verifies the name resolves, the account is valid, and the delegation chain is rooted at the named
23
+ Smart Agent, link-by-link authority-bound, and terminates at the signer key — fail-closed throughout
24
+ (ADR-0013). Naming and account access are **injected** so the package stays vertical-agnostic and a
25
+ pure leaf in the dependency graph (ADR-0021). On-chain ERC-1271 signature verification of each link is
26
+ `delegation.verifyAuthorization`'s job; inject it upstream if you need it.
@@ -0,0 +1,38 @@
1
+ import { type Address, type Hex } from 'viem';
2
+ import { type Delegation } from '@agenticprimitives/delegation';
3
+ import type { KmsAccountBackend } from '@agenticprimitives/key-custody';
4
+ export declare const PACKAGE_NAME = "@agenticprimitives/delegated-signer";
5
+ export declare const PACKAGE_STATUS: "w1-foundational";
6
+ export declare const SPEC_REF = "specs/276-kms-consumer-surface.md";
7
+ /** Resolve a name (label) to its Smart Agent address, or `null` if it doesn't resolve.
8
+ * Injected so the package never hardcodes a registry / TLD (ADR-0021). */
9
+ export type NameResolver = (name: string) => Promise<Address | null>;
10
+ /** Confirm a Smart Agent is a valid, deployed account. Injected (agent-account client). */
11
+ export type AccountVerifier = (sa: Address) => Promise<boolean>;
12
+ export interface ResolveDelegatedSignerOpts {
13
+ /** The name (label) of the delegating identity — opaque; resolved by `resolveName`. */
14
+ name: string;
15
+ /** The operational signing backend (e.g. a KMS per-subject signer from key-custody). */
16
+ signer: KmsAccountBackend;
17
+ /** The delegation chain: `[root, …, leaf]`. Root authorized by the named SA; leaf delegates to the signer. */
18
+ delegationChain: Delegation[];
19
+ /** Injected agent-naming resolver. */
20
+ resolveName: NameResolver;
21
+ /** Injected agent-account validity check. */
22
+ verifyAccount: AccountVerifier;
23
+ /** Chain id + DelegationManager address — required to recompute each link's authority hash. */
24
+ chainId: number;
25
+ delegationManager: Address;
26
+ }
27
+ export interface ResolvedDelegatedSigner {
28
+ /** The operational signing key's EVM address (the chain's leaf delegate). */
29
+ signerAddress: Address;
30
+ /** The named identity's canonical Smart Agent (the chain's root delegator). */
31
+ delegatorAgent: Address;
32
+ /** Sign a 32-byte digest with the resolved signer; returns a 0x-hex `(r,s,v)` signature. */
33
+ sign(digest: Uint8Array): Promise<Hex>;
34
+ }
35
+ /** Resolve + verify a delegated signer for a named identity. Throws (fail-closed) on any
36
+ * unresolved name, invalid account, or broken/mis-rooted/mis-terminated delegation chain. */
37
+ export declare function resolveDelegatedSigner(opts: ResolveDelegatedSignerOpts): Promise<ResolvedDelegatedSigner>;
38
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAc,KAAK,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,MAAM,CAAC;AAC1D,OAAO,EAAE,KAAK,UAAU,EAAkC,MAAM,+BAA+B,CAAC;AAChG,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAExE,eAAO,MAAM,YAAY,wCAAwC,CAAC;AAClE,eAAO,MAAM,cAAc,EAAG,iBAA0B,CAAC;AACzD,eAAO,MAAM,QAAQ,sCAAsC,CAAC;AAE5D;2EAC2E;AAC3E,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;AAErE,2FAA2F;AAC3F,MAAM,MAAM,eAAe,GAAG,CAAC,EAAE,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAEhE,MAAM,WAAW,0BAA0B;IACzC,uFAAuF;IACvF,IAAI,EAAE,MAAM,CAAC;IACb,wFAAwF;IACxF,MAAM,EAAE,iBAAiB,CAAC;IAC1B,8GAA8G;IAC9G,eAAe,EAAE,UAAU,EAAE,CAAC;IAC9B,sCAAsC;IACtC,WAAW,EAAE,YAAY,CAAC;IAC1B,6CAA6C;IAC7C,aAAa,EAAE,eAAe,CAAC;IAC/B,+FAA+F;IAC/F,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,uBAAuB;IACtC,6EAA6E;IAC7E,aAAa,EAAE,OAAO,CAAC;IACvB,+EAA+E;IAC/E,cAAc,EAAE,OAAO,CAAC;IACxB,4FAA4F;IAC5F,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;CACxC;AAMD;8FAC8F;AAC9F,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,0BAA0B,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAqD/G"}
package/dist/index.js ADDED
@@ -0,0 +1,78 @@
1
+ // @agenticprimitives/delegated-signer — generic named delegated-signer resolution (spec 276 KCS-D6).
2
+ //
3
+ // Composes the four trust primitives into one answer to: "give me a signer for
4
+ // the NAMED identity X, authorized by delegation chain Y."
5
+ // • agent-naming → resolve the name to a Smart Agent (INJECTED `resolveName`)
6
+ // • agent-account → confirm that SA is a valid/deployed account (INJECTED `verifyAccount`)
7
+ // • delegation → verify the chain links the named SA to the signer key
8
+ // • key-custody → the operational signing key (e.g. a KMS per-subject signer)
9
+ //
10
+ // This is the GENERIC core that an app's bespoke trust-context orchestration
11
+ // (e.g. an external `trust-context.ts`) reduces to. It is vertical-agnostic: no
12
+ // TLD, registry, or product names. naming + account reach the network through
13
+ // INJECTED clients so the package stays a pure, unit-testable leaf (ADR-0021).
14
+ //
15
+ // SCOPE: this verifies name resolution, account validity, and the delegation
16
+ // chain's AUTHORITY LINKAGE (each link cryptographically binds its parent via
17
+ // the EIP-712 delegation hash, rooted at the named SA, terminating at the
18
+ // signer key). On-chain ERC-1271 signature verification of each link is a
19
+ // separate concern (`delegation.verifyAuthorization`); inject it upstream if
20
+ // you need it. Fail-closed throughout (ADR-0013).
21
+ import { bytesToHex } from 'viem';
22
+ import { hashDelegation, ROOT_AUTHORITY } from '@agenticprimitives/delegation';
23
+ export const PACKAGE_NAME = '@agenticprimitives/delegated-signer';
24
+ export const PACKAGE_STATUS = 'w1-foundational';
25
+ export const SPEC_REF = 'specs/276-kms-consumer-surface.md';
26
+ function eqAddr(a, b) {
27
+ return a.toLowerCase() === b.toLowerCase();
28
+ }
29
+ /** Resolve + verify a delegated signer for a named identity. Throws (fail-closed) on any
30
+ * unresolved name, invalid account, or broken/mis-rooted/mis-terminated delegation chain. */
31
+ export async function resolveDelegatedSigner(opts) {
32
+ const { name, signer, delegationChain, resolveName, verifyAccount, chainId, delegationManager } = opts;
33
+ if (delegationChain.length === 0) {
34
+ throw new Error('resolveDelegatedSigner: delegationChain is empty');
35
+ }
36
+ const delegatorAgent = await resolveName(name);
37
+ if (!delegatorAgent) {
38
+ throw new Error(`resolveDelegatedSigner: name "${name}" did not resolve to a Smart Agent`);
39
+ }
40
+ if (!(await verifyAccount(delegatorAgent))) {
41
+ throw new Error(`resolveDelegatedSigner: ${delegatorAgent} is not a valid/deployed account`);
42
+ }
43
+ const signerAddress = await signer.getSignerAddress();
44
+ // Root link: must be a ROOT delegation issued BY the named SA.
45
+ const root = delegationChain[0];
46
+ if (!eqAddr(root.authority, ROOT_AUTHORITY)) {
47
+ throw new Error('resolveDelegatedSigner: chain[0] is not a root delegation (authority != ROOT_AUTHORITY)');
48
+ }
49
+ if (!eqAddr(root.delegator, delegatorAgent)) {
50
+ throw new Error('resolveDelegatedSigner: root delegator does not match the named agent');
51
+ }
52
+ // Continuity: each link is authorized by the previous (authority == hash(prev)) and continues it
53
+ // (delegator == prev.delegate). This is the cryptographic chain binding.
54
+ for (let i = 1; i < delegationChain.length; i++) {
55
+ const prev = delegationChain[i - 1];
56
+ const cur = delegationChain[i];
57
+ if (!eqAddr(cur.delegator, prev.delegate)) {
58
+ throw new Error(`resolveDelegatedSigner: chain[${i}].delegator != chain[${i - 1}].delegate`);
59
+ }
60
+ if (!eqAddr(cur.authority, hashDelegation(prev, chainId, delegationManager))) {
61
+ throw new Error(`resolveDelegatedSigner: chain[${i}].authority does not bind chain[${i - 1}]`);
62
+ }
63
+ }
64
+ // The chain MUST terminate at THIS signer key — otherwise the chain authorizes someone else.
65
+ const leaf = delegationChain[delegationChain.length - 1];
66
+ if (!eqAddr(leaf.delegate, signerAddress)) {
67
+ throw new Error('resolveDelegatedSigner: chain leaf delegate != signer address');
68
+ }
69
+ return {
70
+ signerAddress,
71
+ delegatorAgent,
72
+ async sign(digest) {
73
+ const { signature } = await signer.signA2AAction({ digest });
74
+ return bytesToHex(signature);
75
+ },
76
+ };
77
+ }
78
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,EAAE;AACF,+EAA+E;AAC/E,2DAA2D;AAC3D,kFAAkF;AAClF,8FAA8F;AAC9F,6EAA6E;AAC7E,mFAAmF;AACnF,EAAE;AACF,6EAA6E;AAC7E,gFAAgF;AAChF,8EAA8E;AAC9E,+EAA+E;AAC/E,EAAE;AACF,6EAA6E;AAC7E,8EAA8E;AAC9E,0EAA0E;AAC1E,0EAA0E;AAC1E,6EAA6E;AAC7E,kDAAkD;AAElD,OAAO,EAAE,UAAU,EAA0B,MAAM,MAAM,CAAC;AAC1D,OAAO,EAAmB,cAAc,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAGhG,MAAM,CAAC,MAAM,YAAY,GAAG,qCAAqC,CAAC;AAClE,MAAM,CAAC,MAAM,cAAc,GAAG,iBAA0B,CAAC;AACzD,MAAM,CAAC,MAAM,QAAQ,GAAG,mCAAmC,CAAC;AAkC5D,SAAS,MAAM,CAAC,CAAS,EAAE,CAAS;IAClC,OAAO,CAAC,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC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AAG,eAAe,CAAC,CAAC,GAAG,CAAC,CAAE,CAAC;QACrC,MAAM,GAAG,GAAG,eAAe,CAAC,CAAC,CAAE,CAAC;QAChC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC1C,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,wBAAwB,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAC/F,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC,EAAE,CAAC;YAC7E,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,mCAAmC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACjG,CAAC;IACH,CAAC;IAED,6FAA6F;IAC7F,MAAM,IAAI,GAAG,eAAe,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC;IAC1D,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,aAAa,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;IACnF,CAAC;IAED,OAAO;QACL,aAAa;QACb,cAAc;QACd,KAAK,CAAC,IAAI,CAAC,MAAkB;YAC3B,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;YAC7D,OAAO,UAAU,CAAC,SAAS,CAAC,CAAC;QAC/B,CAAC;KACF,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@agenticprimitives/delegated-signer",
3
+ "version": "0.0.0-alpha.1",
4
+ "description": "Generic named delegated-signer resolution — compose agent-naming + agent-account + delegation + key-custody into a signer for a named identity, authorized by a delegation chain. Vertical-agnostic; naming/account are injected.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/agentictrustlabs/agenticprimitives.git",
9
+ "directory": "packages/delegated-signer"
10
+ },
11
+ "homepage": "https://github.com/agentictrustlabs/agenticprimitives/tree/master/packages/delegated-signer",
12
+ "bugs": {
13
+ "url": "https://github.com/agentictrustlabs/agenticprimitives/issues"
14
+ },
15
+ "type": "module",
16
+ "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ }
23
+ },
24
+ "files": [
25
+ "LICENSE",
26
+ "dist",
27
+ "spec.md",
28
+ "README.md"
29
+ ],
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "peerDependencies": {
34
+ "viem": "^2.52.2",
35
+ "@agenticprimitives/key-custody": "1.0.0-alpha.9",
36
+ "@agenticprimitives/types": "1.0.0-alpha.9",
37
+ "@agenticprimitives/delegation": "1.0.0-alpha.9"
38
+ },
39
+ "devDependencies": {
40
+ "vitest": "^4.1.8",
41
+ "viem": "^2.52.2"
42
+ },
43
+ "keywords": [
44
+ "agentic",
45
+ "primitives",
46
+ "delegated-signer",
47
+ "kms",
48
+ "delegation"
49
+ ],
50
+ "scripts": {
51
+ "build": "tsc -p tsconfig.build.json",
52
+ "typecheck": "tsc -p tsconfig.json --noEmit",
53
+ "test": "vitest run",
54
+ "test:unit": "vitest run test/unit --passWithNoTests",
55
+ "test:watch": "vitest",
56
+ "clean": "rm -rf dist"
57
+ }
58
+ }
package/spec.md ADDED
@@ -0,0 +1,24 @@
1
+ # @agenticprimitives/delegated-signer — spec
2
+
3
+ The full design lives in
4
+ [`../../specs/276-kms-consumer-surface.md`](../../specs/276-kms-consumer-surface.md)
5
+ (decision KCS-D6).
6
+
7
+ This package is the generic core of an app's bespoke "named delegated signer"
8
+ orchestration: resolve a name to a Smart Agent (injected `agent-naming` client),
9
+ confirm the account (injected `agent-account` client), verify a delegation
10
+ chain's authority linkage (`@agenticprimitives/delegation`), and bind the result
11
+ to an operational signing key (`@agenticprimitives/key-custody`).
12
+
13
+ Architecture decisions:
14
+
15
+ - [ADR-0006](../../docs/architecture/decisions/0006-injected-context-pattern.md)
16
+ — naming/account reach the network through INJECTED clients, so the package
17
+ stays a pure, unit-testable leaf.
18
+ - [ADR-0021](../../docs/architecture/decisions/0021-generic-packages-vs-white-label-apps.md)
19
+ — vertical/deploy specifics (TLDs, registries, Worker routes) live in apps,
20
+ never here.
21
+ - [ADR-0013](../../docs/architecture/decisions/0013-no-silent-fallbacks.md)
22
+ — fail-closed on any unresolved name, invalid account, or broken chain.
23
+
24
+ Do not edit a divergent copy here — edit the canonical spec.