@kybernesis/arp-templates 0.2.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 +84 -0
- package/dist/index.cjs +175 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +158 -0
- package/dist/index.d.ts +158 -0
- package/dist/index.js +165 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kybernesis AI
|
|
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,84 @@
|
|
|
1
|
+
# @kybernesis/arp-templates
|
|
2
|
+
|
|
3
|
+
Pure builder functions that produce validated ARP documents from typed inputs.
|
|
4
|
+
|
|
5
|
+
Every export in this package takes a small typed input, constructs the canonical ARP shape, validates the result against the matching Zod schema from [`@kybernesis/arp-spec`](../spec), and returns the validated object. On validation failure, the builder throws `TemplateValidationError` — you should never see an invalid document leak out of a builder.
|
|
6
|
+
|
|
7
|
+
These functions are stateless: no filesystem, no network, no clock reads beyond documented optional defaults. Safe to use in registrar integrations, the ARP runtime, SDKs, or the owner app.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @kybernesis/arp-templates
|
|
13
|
+
# peer: @kybernesis/arp-spec is bundled as a regular dependency
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
### Build a DID document
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { buildDidDocument } from '@kybernesis/arp-templates';
|
|
22
|
+
|
|
23
|
+
const didDoc = buildDidDocument({
|
|
24
|
+
agentDid: 'did:web:samantha.agent',
|
|
25
|
+
controllerDid: 'did:web:ian.example.agent',
|
|
26
|
+
publicKeyMultibase: 'z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp',
|
|
27
|
+
endpoints: {
|
|
28
|
+
didcomm: 'https://samantha.agent/didcomm',
|
|
29
|
+
agentCard: 'https://samantha.agent/.well-known/agent-card.json',
|
|
30
|
+
},
|
|
31
|
+
representationVcUrl: 'https://ian.samantha.agent/.well-known/representation.jwt',
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Build an agent card
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { buildAgentCard } from '@kybernesis/arp-templates';
|
|
39
|
+
|
|
40
|
+
const card = buildAgentCard({
|
|
41
|
+
name: 'Samantha',
|
|
42
|
+
did: 'did:web:samantha.agent',
|
|
43
|
+
endpoints: {
|
|
44
|
+
didcomm: 'https://samantha.agent/didcomm',
|
|
45
|
+
pairing: 'https://samantha.agent/pair',
|
|
46
|
+
},
|
|
47
|
+
agentOrigin: 'https://samantha.agent',
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Build a handoff bundle (registrar integration)
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { buildHandoffBundle } from '@kybernesis/arp-templates';
|
|
55
|
+
|
|
56
|
+
const bundle = buildHandoffBundle({
|
|
57
|
+
agentDid: 'did:web:samantha.agent',
|
|
58
|
+
principalDid: 'did:web:ian.example.agent',
|
|
59
|
+
publicKeyMultibase: 'z6Mk...',
|
|
60
|
+
agentOrigin: 'https://samantha.agent',
|
|
61
|
+
dnsRecordsPublished: ['A', '_arp TXT', '_did TXT', '_didcomm TXT', '_principal TXT'],
|
|
62
|
+
certExpiresAt: '2026-07-22T00:00:00Z',
|
|
63
|
+
bootstrapToken: bootstrapJwt,
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Builders
|
|
68
|
+
|
|
69
|
+
| Export | Source |
|
|
70
|
+
|---|---|
|
|
71
|
+
| `buildDidDocument` | `ARP-tld-integration-spec-v2.md §6.1` |
|
|
72
|
+
| `buildAgentCard` | `ARP-tld-integration-spec-v2.md §6.2` |
|
|
73
|
+
| `buildArpJson` | `ARP-tld-integration-spec-v2.md §6.3` |
|
|
74
|
+
| `buildRepresentationVc` | `ARP-tld-integration-spec-v2.md §6.4` |
|
|
75
|
+
| `buildRevocations` | `ARP-tld-integration-spec-v2.md §6.5` |
|
|
76
|
+
| `buildHandoffBundle` | `ARP-tld-integration-spec-v2.md §7 step 14` |
|
|
77
|
+
|
|
78
|
+
## Phase
|
|
79
|
+
|
|
80
|
+
Shipped as part of Phase 1. See [`docs/ARP-phase-0-roadmap.md`](../../docs/ARP-phase-0-roadmap.md).
|
|
81
|
+
|
|
82
|
+
## License
|
|
83
|
+
|
|
84
|
+
MIT.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var arpSpec = require('@kybernesis/arp-spec');
|
|
4
|
+
|
|
5
|
+
// src/util.ts
|
|
6
|
+
var TemplateValidationError = class extends Error {
|
|
7
|
+
issues;
|
|
8
|
+
constructor(templateName, issues) {
|
|
9
|
+
super(
|
|
10
|
+
`${templateName}: produced invalid output (${issues.length} issue${issues.length === 1 ? "" : "s"})`
|
|
11
|
+
);
|
|
12
|
+
this.name = "TemplateValidationError";
|
|
13
|
+
this.issues = issues;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
function validateOrThrow(templateName, schema, candidate) {
|
|
17
|
+
const parsed = schema.safeParse(candidate);
|
|
18
|
+
if (!parsed.success) {
|
|
19
|
+
throw new TemplateValidationError(templateName, parsed.error.issues);
|
|
20
|
+
}
|
|
21
|
+
return parsed.data;
|
|
22
|
+
}
|
|
23
|
+
function makeServiceId(agentDid, suffix) {
|
|
24
|
+
return `${agentDid}#${suffix}`;
|
|
25
|
+
}
|
|
26
|
+
function buildDidDocument(input) {
|
|
27
|
+
const keyId = input.keyId ?? "key-1";
|
|
28
|
+
const verificationMethodId = makeServiceId(input.agentDid, keyId);
|
|
29
|
+
const doc = {
|
|
30
|
+
"@context": ["https://www.w3.org/ns/did/v1"],
|
|
31
|
+
id: input.agentDid,
|
|
32
|
+
controller: input.controllerDid,
|
|
33
|
+
verificationMethod: [
|
|
34
|
+
{
|
|
35
|
+
id: verificationMethodId,
|
|
36
|
+
type: "Ed25519VerificationKey2020",
|
|
37
|
+
controller: input.agentDid,
|
|
38
|
+
publicKeyMultibase: input.publicKeyMultibase
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
authentication: [verificationMethodId],
|
|
42
|
+
assertionMethod: [verificationMethodId],
|
|
43
|
+
keyAgreement: [verificationMethodId],
|
|
44
|
+
service: [
|
|
45
|
+
{
|
|
46
|
+
id: makeServiceId(input.agentDid, "didcomm"),
|
|
47
|
+
type: "DIDCommMessaging",
|
|
48
|
+
serviceEndpoint: input.endpoints.didcomm,
|
|
49
|
+
accept: ["didcomm/v2"]
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: makeServiceId(input.agentDid, "agent-card"),
|
|
53
|
+
type: "AgentCard",
|
|
54
|
+
serviceEndpoint: input.endpoints.agentCard
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
principal: {
|
|
58
|
+
did: input.controllerDid,
|
|
59
|
+
representationVC: input.representationVcUrl
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
return validateOrThrow("buildDidDocument", arpSpec.DidDocumentSchema, doc);
|
|
63
|
+
}
|
|
64
|
+
function buildAgentCard(input) {
|
|
65
|
+
const policySchemaUrl = input.policySchemaUrl ?? (input.agentOrigin ? `${input.agentOrigin.replace(/\/$/, "")}/.well-known/policy-schema.json` : void 0);
|
|
66
|
+
if (!policySchemaUrl) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
"buildAgentCard: either policySchemaUrl or agentOrigin must be provided"
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
const card = {
|
|
72
|
+
arp_version: arpSpec.ARP_VERSION,
|
|
73
|
+
name: input.name,
|
|
74
|
+
did: input.did,
|
|
75
|
+
description: input.description ?? "Personal agent",
|
|
76
|
+
created_at: input.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
77
|
+
endpoints: {
|
|
78
|
+
didcomm: input.endpoints.didcomm,
|
|
79
|
+
...input.endpoints.a2a ? { a2a: input.endpoints.a2a } : {},
|
|
80
|
+
pairing: input.endpoints.pairing
|
|
81
|
+
},
|
|
82
|
+
accepted_protocols: [...input.acceptedProtocols ?? arpSpec.SUPPORTED_PROTOCOLS],
|
|
83
|
+
supported_scopes: [...input.supportedScopes ?? []],
|
|
84
|
+
payment: {
|
|
85
|
+
x402_enabled: input.payment?.x402Enabled ?? false,
|
|
86
|
+
currencies: [...input.payment?.currencies ?? []],
|
|
87
|
+
pricing_url: input.payment?.pricingUrl ?? null
|
|
88
|
+
},
|
|
89
|
+
vc_requirements: [...input.vcRequirements ?? []],
|
|
90
|
+
policy: {
|
|
91
|
+
engine: "cedar",
|
|
92
|
+
schema: policySchemaUrl
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
return validateOrThrow("buildAgentCard", arpSpec.AgentCardSchema, card);
|
|
96
|
+
}
|
|
97
|
+
var DEFAULT_CAPABILITIES = ["didcomm-v2", "cedar-pdp", "ucan-tokens"];
|
|
98
|
+
function buildArpJson(input) {
|
|
99
|
+
const origin = input.agentOrigin.replace(/\/$/, "");
|
|
100
|
+
const doc = {
|
|
101
|
+
version: arpSpec.ARP_VERSION,
|
|
102
|
+
capabilities: [...input.capabilities ?? DEFAULT_CAPABILITIES],
|
|
103
|
+
scope_catalog_url: input.scopeCatalogUrl ?? `${origin}/.well-known/scope-catalog.json`,
|
|
104
|
+
policy_schema_url: input.policySchemaUrl ?? `${origin}/.well-known/policy-schema.json`
|
|
105
|
+
};
|
|
106
|
+
return validateOrThrow("buildArpJson", arpSpec.ArpJsonSchema, doc);
|
|
107
|
+
}
|
|
108
|
+
var DEFAULT_MAX_CONCURRENT_CONNECTIONS = 100;
|
|
109
|
+
var ONE_YEAR_SECONDS = 365 * 24 * 60 * 60;
|
|
110
|
+
function buildRepresentationVc(input) {
|
|
111
|
+
const iat = input.iat ?? Math.floor(Date.now() / 1e3);
|
|
112
|
+
const exp = input.exp ?? iat + ONE_YEAR_SECONDS;
|
|
113
|
+
const doc = {
|
|
114
|
+
iss: input.principalDid,
|
|
115
|
+
sub: input.agentDid,
|
|
116
|
+
iat,
|
|
117
|
+
exp,
|
|
118
|
+
vc: {
|
|
119
|
+
"@context": ["https://www.w3.org/2018/credentials/v1"],
|
|
120
|
+
type: ["VerifiableCredential", "AgentRepresentation"],
|
|
121
|
+
credentialSubject: {
|
|
122
|
+
id: input.agentDid,
|
|
123
|
+
representedBy: input.principalDid,
|
|
124
|
+
scope: input.scope ?? "full",
|
|
125
|
+
constraints: {
|
|
126
|
+
maxConcurrentConnections: input.constraints?.maxConcurrentConnections ?? DEFAULT_MAX_CONCURRENT_CONNECTIONS,
|
|
127
|
+
allowedTransferOfOwnership: input.constraints?.allowedTransferOfOwnership ?? false
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
return validateOrThrow("buildRepresentationVc", arpSpec.RepresentationVcSchema, doc);
|
|
133
|
+
}
|
|
134
|
+
function buildRevocations(input) {
|
|
135
|
+
const doc = {
|
|
136
|
+
issuer: input.issuer,
|
|
137
|
+
updated_at: input.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
138
|
+
revocations: input.revocations ? [...input.revocations] : [],
|
|
139
|
+
signature: {
|
|
140
|
+
alg: "EdDSA",
|
|
141
|
+
kid: input.signature.kid,
|
|
142
|
+
value: input.signature.value
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
return validateOrThrow("buildRevocations", arpSpec.RevocationsSchema, doc);
|
|
146
|
+
}
|
|
147
|
+
function buildHandoffBundle(input) {
|
|
148
|
+
const origin = input.agentOrigin.replace(/\/$/, "");
|
|
149
|
+
const doc = {
|
|
150
|
+
agent_did: input.agentDid,
|
|
151
|
+
principal_did: input.principalDid,
|
|
152
|
+
public_key_multibase: input.publicKeyMultibase,
|
|
153
|
+
well_known_urls: {
|
|
154
|
+
did: input.wellKnownUrls?.did ?? `${origin}/.well-known/did.json`,
|
|
155
|
+
agent_card: input.wellKnownUrls?.agentCard ?? `${origin}/.well-known/agent-card.json`,
|
|
156
|
+
arp: input.wellKnownUrls?.arp ?? `${origin}/.well-known/arp.json`
|
|
157
|
+
},
|
|
158
|
+
dns_records_published: [...input.dnsRecordsPublished],
|
|
159
|
+
cert_expires_at: input.certExpiresAt,
|
|
160
|
+
bootstrap_token: input.bootstrapToken
|
|
161
|
+
};
|
|
162
|
+
return validateOrThrow("buildHandoffBundle", arpSpec.HandoffBundleSchema, doc);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
exports.TemplateValidationError = TemplateValidationError;
|
|
166
|
+
exports.buildAgentCard = buildAgentCard;
|
|
167
|
+
exports.buildArpJson = buildArpJson;
|
|
168
|
+
exports.buildDidDocument = buildDidDocument;
|
|
169
|
+
exports.buildHandoffBundle = buildHandoffBundle;
|
|
170
|
+
exports.buildRepresentationVc = buildRepresentationVc;
|
|
171
|
+
exports.buildRevocations = buildRevocations;
|
|
172
|
+
exports.makeServiceId = makeServiceId;
|
|
173
|
+
exports.validateOrThrow = validateOrThrow;
|
|
174
|
+
//# sourceMappingURL=index.cjs.map
|
|
175
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/util.ts","../src/did-document.ts","../src/agent-card.ts","../src/arp-json.ts","../src/representation-vc.ts","../src/revocations.ts","../src/handoff-bundle.ts"],"names":["DidDocumentSchema","ARP_VERSION","SUPPORTED_PROTOCOLS","AgentCardSchema","ArpJsonSchema","RepresentationVcSchema","RevocationsSchema","HandoffBundleSchema"],"mappings":";;;;;AASO,IAAM,uBAAA,GAAN,cAAsC,KAAA,CAAM;AAAA,EACjC,MAAA;AAAA,EAEhB,WAAA,CAAY,cAAsB,MAAA,EAAsB;AACtD,IAAA,KAAA;AAAA,MACE,CAAA,EAAG,YAAY,CAAA,2BAAA,EAA8B,MAAA,CAAO,MAAM,SAAS,MAAA,CAAO,MAAA,KAAW,CAAA,GAAI,EAAA,GAAK,GAAG,CAAA,CAAA;AAAA,KACnG;AACA,IAAA,IAAA,CAAK,IAAA,GAAO,yBAAA;AACZ,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AAAA,EAChB;AACF;AAMO,SAAS,eAAA,CACd,YAAA,EACA,MAAA,EACA,SAAA,EACY;AACZ,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,SAAA,CAAU,SAAS,C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AO,MAAM,SAAA,CAAU;AAAA;AACzB,GACF;AAEA,EAAA,OAAO,eAAA,CAAgB,kBAAA,EAAoBC,yBAAA,EAAmB,GAAG,CAAA;AACnE;ACLO,SAAS,mBAAmB,KAAA,EAA+C;AAChF,EAAA,MAAM,MAAA,GAAS,KAAA,CAAM,WAAA,CAAY,OAAA,CAAQ,OAAO,EAAE,CAAA;AAClD,EAAA,MAAM,GAAA,GAAM;AAAA,IACV,WAAW,KAAA,CAAM,QAAA;AAAA,IACjB,eAAe,KAAA,CAAM,YAAA;AAAA,IACrB,sBAAsB,KAAA,CAAM,kBAAA;AAAA,IAC5B,eAAA,EAAiB;AAAA,MACf,GAAA,EAAK,KAAA,CAAM,aAAA,EAAe,GAAA,IAAO,GAAG,MAAM,CAAA,qBAAA,CAAA;AAAA,MAC1C,UAAA,EACE,KAAA,CAAM,aAAA,EAAe,SAAA,IAAa,GAAG,MAAM,CAAA,4BAAA,CAAA;AAAA,MAC7C,GAAA,EAAK,KAAA,CAAM,aAAA,EAAe,GAAA,IAAO,GAAG,MAAM,CAAA,qBAAA;AAAA,KAC5C;AAAA,IACA,qBAAA,EAAuB,CAAC,GAAG,KAAA,CAAM,mBAAmB,CAAA;AAAA,IACpD,iBAAiB,KAAA,CAAM,aAAA;AAAA,IACvB,iBAAiB,KAAA,CAAM;AAAA,GACzB;AAEA,EAAA,OAAO,eAAA,CAAgB,oBAAA,EAAsBC,2BAAA,EAAqB,GAAG,CAAA;AACvE","file":"index.cjs","sourcesContent":["import { z, type ZodTypeAny } from 'zod';\n\n/**\n * Error thrown when a template output fails its own Zod validation.\n *\n * Template functions are pure — inputs are typed, but defaults, URL\n * composition, and date math still need a schema check before the object\n * leaves the builder.\n */\nexport class TemplateValidationError extends Error {\n public readonly issues: z.ZodIssue[];\n\n constructor(templateName: string, issues: z.ZodIssue[]) {\n super(\n `${templateName}: produced invalid output (${issues.length} issue${issues.length === 1 ? '' : 's'})`\n );\n this.name = 'TemplateValidationError';\n this.issues = issues;\n }\n}\n\n/**\n * Validate `candidate` against `schema`. Throws `TemplateValidationError` on\n * failure, returns the parsed value on success.\n */\nexport function validateOrThrow<S extends ZodTypeAny>(\n templateName: string,\n schema: S,\n candidate: unknown\n): z.infer<S> {\n const parsed = schema.safeParse(candidate);\n if (!parsed.success) {\n throw new TemplateValidationError(templateName, parsed.error.issues);\n }\n return parsed.data;\n}\n\n/**\n * Canonical service ID helper: `<agentDid>#<suffix>`.\n */\nexport function makeServiceId(agentDid: string, suffix: string): string {\n return `${agentDid}#${suffix}`;\n}\n","import {\n DidDocumentSchema,\n type DidDocument,\n type DidUri,\n type PublicKeyMultibase,\n} from '@kybernesis/arp-spec';\nimport { validateOrThrow, makeServiceId } from './util.js';\n\nexport interface BuildDidDocumentInput {\n /** Agent DID (e.g. \"did:web:samantha.agent\"). */\n agentDid: DidUri;\n /** Principal (controller) DID. May be a placeholder pre-binding. */\n controllerDid: DidUri;\n /** Ed25519 public key in multibase (z-base58btc). */\n publicKeyMultibase: PublicKeyMultibase;\n /** Service endpoints. */\n endpoints: {\n didcomm: string;\n agentCard: string;\n };\n /** Representation VC URL served on the owner subdomain. */\n representationVcUrl: string;\n /** Optional verification-method key id suffix. Defaults to `key-1`. */\n keyId?: string;\n}\n\n/**\n * Build a W3C DID Document conforming to ARP-tld-integration-spec-v2 §6.1.\n *\n * The output is validated against `DidDocumentSchema` before return; on\n * failure a `TemplateValidationError` is thrown.\n */\nexport function buildDidDocument(input: BuildDidDocumentInput): DidDocument {\n const keyId = input.keyId ?? 'key-1';\n const verificationMethodId = makeServiceId(input.agentDid, keyId);\n\n const doc = {\n '@context': ['https://www.w3.org/ns/did/v1'],\n id: input.agentDid,\n controller: input.controllerDid,\n verificationMethod: [\n {\n id: verificationMethodId,\n type: 'Ed25519VerificationKey2020' as const,\n controller: input.agentDid,\n publicKeyMultibase: input.publicKeyMultibase,\n },\n ],\n authentication: [verificationMethodId],\n assertionMethod: [verificationMethodId],\n keyAgreement: [verificationMethodId],\n service: [\n {\n id: makeServiceId(input.agentDid, 'didcomm'),\n type: 'DIDCommMessaging' as const,\n serviceEndpoint: input.endpoints.didcomm,\n accept: ['didcomm/v2'],\n },\n {\n id: makeServiceId(input.agentDid, 'agent-card'),\n type: 'AgentCard' as const,\n serviceEndpoint: input.endpoints.agentCard,\n },\n ],\n principal: {\n did: input.controllerDid,\n representationVC: input.representationVcUrl,\n },\n };\n\n return validateOrThrow('buildDidDocument', DidDocumentSchema, doc);\n}\n","import {\n AgentCardSchema,\n ARP_VERSION,\n SUPPORTED_PROTOCOLS,\n type AgentCard,\n type DidUri,\n} from '@kybernesis/arp-spec';\nimport { validateOrThrow } from './util.js';\n\nexport interface BuildAgentCardInput {\n name: string;\n did: DidUri;\n /** One-line description; defaults to \"Personal agent\". */\n description?: string;\n /** ISO 8601 datetime with offset. Defaults to `new Date().toISOString()`. */\n createdAt?: string;\n endpoints: {\n didcomm: string;\n /** Optional in v0 (stubbed). */\n a2a?: string;\n pairing: string;\n };\n /**\n * Override accepted protocols. Defaults to the canonical `didcomm/v2` +\n * `a2a/1.0` set from `@kybernesis/arp-spec`.\n */\n acceptedProtocols?: readonly string[];\n supportedScopes?: readonly string[];\n payment?: {\n x402Enabled: boolean;\n currencies?: readonly string[];\n pricingUrl?: string | null;\n };\n vcRequirements?: readonly string[];\n /**\n * HTTPS URL of the Cedar policy schema. Defaults to the conventional\n * `<agent-origin>/.well-known/policy-schema.json` when `policySchemaUrl`\n * is omitted and `agentOrigin` is provided.\n */\n policySchemaUrl?: string;\n /** Used to derive the default `policySchemaUrl`. */\n agentOrigin?: string;\n}\n\nexport function buildAgentCard(input: BuildAgentCardInput): AgentCard {\n const policySchemaUrl =\n input.policySchemaUrl ??\n (input.agentOrigin\n ? `${input.agentOrigin.replace(/\\/$/, '')}/.well-known/policy-schema.json`\n : undefined);\n\n if (!policySchemaUrl) {\n throw new Error(\n 'buildAgentCard: either policySchemaUrl or agentOrigin must be provided'\n );\n }\n\n const card = {\n arp_version: ARP_VERSION,\n name: input.name,\n did: input.did,\n description: input.description ?? 'Personal agent',\n created_at: input.createdAt ?? new Date().toISOString(),\n endpoints: {\n didcomm: input.endpoints.didcomm,\n ...(input.endpoints.a2a ? { a2a: input.endpoints.a2a } : {}),\n pairing: input.endpoints.pairing,\n },\n accepted_protocols: [...(input.acceptedProtocols ?? SUPPORTED_PROTOCOLS)],\n supported_scopes: [...(input.supportedScopes ?? [])],\n payment: {\n x402_enabled: input.payment?.x402Enabled ?? false,\n currencies: [...(input.payment?.currencies ?? [])],\n pricing_url: input.payment?.pricingUrl ?? null,\n },\n vc_requirements: [...(input.vcRequirements ?? [])],\n policy: {\n engine: 'cedar' as const,\n schema: policySchemaUrl,\n },\n };\n\n return validateOrThrow('buildAgentCard', AgentCardSchema, card);\n}\n","import { ArpJsonSchema, ARP_VERSION, type ArpJson } from '@kybernesis/arp-spec';\nimport { validateOrThrow } from './util.js';\n\nexport interface BuildArpJsonInput {\n /** HTTPS origin of the agent (e.g. \"https://samantha.agent\"). */\n agentOrigin: string;\n /**\n * Override the advertised capabilities. Defaults to the v0 set:\n * didcomm-v2, cedar-pdp, ucan-tokens.\n */\n capabilities?: readonly string[];\n /** Override the scope-catalog URL (defaults to `<agentOrigin>/.well-known/scope-catalog.json`). */\n scopeCatalogUrl?: string;\n /** Override the policy-schema URL (defaults to `<agentOrigin>/.well-known/policy-schema.json`). */\n policySchemaUrl?: string;\n}\n\nconst DEFAULT_CAPABILITIES = ['didcomm-v2', 'cedar-pdp', 'ucan-tokens'] as const;\n\nexport function buildArpJson(input: BuildArpJsonInput): ArpJson {\n const origin = input.agentOrigin.replace(/\\/$/, '');\n const doc = {\n version: ARP_VERSION,\n capabilities: [...(input.capabilities ?? DEFAULT_CAPABILITIES)],\n scope_catalog_url:\n input.scopeCatalogUrl ?? `${origin}/.well-known/scope-catalog.json`,\n policy_schema_url:\n input.policySchemaUrl ?? `${origin}/.well-known/policy-schema.json`,\n };\n return validateOrThrow('buildArpJson', ArpJsonSchema, doc);\n}\n","import {\n RepresentationVcSchema,\n type RepresentationVc,\n type DidUri,\n} from '@kybernesis/arp-spec';\nimport { validateOrThrow } from './util.js';\n\nexport interface BuildRepresentationVcInput {\n /** Principal DID (the human doing the representing). */\n principalDid: DidUri;\n /** Agent DID (the agent being represented). */\n agentDid: DidUri;\n /** Issued-at (Unix seconds). Defaults to now. */\n iat?: number;\n /** Expiry (Unix seconds). Defaults to iat + 1 year. */\n exp?: number;\n /** Representation scope. Defaults to \"full\". */\n scope?: 'full' | 'scoped';\n constraints?: {\n maxConcurrentConnections?: number;\n allowedTransferOfOwnership?: boolean;\n };\n}\n\nconst DEFAULT_MAX_CONCURRENT_CONNECTIONS = 100;\nconst ONE_YEAR_SECONDS = 365 * 24 * 60 * 60;\n\nexport function buildRepresentationVc(input: BuildRepresentationVcInput): RepresentationVc {\n const iat = input.iat ?? Math.floor(Date.now() / 1000);\n const exp = input.exp ?? iat + ONE_YEAR_SECONDS;\n\n const doc = {\n iss: input.principalDid,\n sub: input.agentDid,\n iat,\n exp,\n vc: {\n '@context': ['https://www.w3.org/2018/credentials/v1'],\n type: ['VerifiableCredential', 'AgentRepresentation'],\n credentialSubject: {\n id: input.agentDid,\n representedBy: input.principalDid,\n scope: input.scope ?? ('full' as const),\n constraints: {\n maxConcurrentConnections:\n input.constraints?.maxConcurrentConnections ?? DEFAULT_MAX_CONCURRENT_CONNECTIONS,\n allowedTransferOfOwnership: input.constraints?.allowedTransferOfOwnership ?? false,\n },\n },\n },\n };\n\n return validateOrThrow('buildRepresentationVc', RepresentationVcSchema, doc);\n}\n","import {\n RevocationsSchema,\n type Revocations,\n type RevocationEntry,\n type DidUri,\n} from '@kybernesis/arp-spec';\nimport { validateOrThrow } from './util.js';\n\nexport interface BuildRevocationsInput {\n /** Issuer DID (principal). */\n issuer: DidUri;\n /** ISO 8601 timestamp. Defaults to now. */\n updatedAt?: string;\n /** Revocation entries. Defaults to empty. */\n revocations?: readonly RevocationEntry[];\n /** Signature over the JCS canonicalization of the unsigned document. */\n signature: {\n kid: string;\n /** Base64url-encoded signature bytes. */\n value: string;\n };\n}\n\nexport function buildRevocations(input: BuildRevocationsInput): Revocations {\n const doc = {\n issuer: input.issuer,\n updated_at: input.updatedAt ?? new Date().toISOString(),\n revocations: input.revocations ? [...input.revocations] : [],\n signature: {\n alg: 'EdDSA' as const,\n kid: input.signature.kid,\n value: input.signature.value,\n },\n };\n\n return validateOrThrow('buildRevocations', RevocationsSchema, doc);\n}\n","import {\n HandoffBundleSchema,\n type HandoffBundle,\n type DidUri,\n type PublicKeyMultibase,\n type DnsRecordTag,\n} from '@kybernesis/arp-spec';\nimport { validateOrThrow } from './util.js';\n\nexport interface BuildHandoffBundleInput {\n agentDid: DidUri;\n principalDid: DidUri;\n publicKeyMultibase: PublicKeyMultibase;\n /**\n * HTTPS origin of the agent. Used to derive the canonical well-known URLs\n * when individual overrides are not provided.\n */\n agentOrigin: string;\n /** Override well-known URLs (useful when hosting is on a different origin). */\n wellKnownUrls?: {\n did?: string;\n agentCard?: string;\n arp?: string;\n };\n dnsRecordsPublished: readonly DnsRecordTag[];\n /** ISO 8601 cert expiry. */\n certExpiresAt: string;\n /** Bootstrap JWT scoped to the arp-sdk takeover (exp ≤ 15min). */\n bootstrapToken: string;\n}\n\nexport function buildHandoffBundle(input: BuildHandoffBundleInput): HandoffBundle {\n const origin = input.agentOrigin.replace(/\\/$/, '');\n const doc = {\n agent_did: input.agentDid,\n principal_did: input.principalDid,\n public_key_multibase: input.publicKeyMultibase,\n well_known_urls: {\n did: input.wellKnownUrls?.did ?? `${origin}/.well-known/did.json`,\n agent_card:\n input.wellKnownUrls?.agentCard ?? `${origin}/.well-known/agent-card.json`,\n arp: input.wellKnownUrls?.arp ?? `${origin}/.well-known/arp.json`,\n },\n dns_records_published: [...input.dnsRecordsPublished],\n cert_expires_at: input.certExpiresAt,\n bootstrap_token: input.bootstrapToken,\n };\n\n return validateOrThrow('buildHandoffBundle', HandoffBundleSchema, doc);\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { z, ZodTypeAny } from 'zod';
|
|
2
|
+
import { DidUri, PublicKeyMultibase, DidDocument, AgentCard, ArpJson, RepresentationVc, RevocationEntry, Revocations, DnsRecordTag, HandoffBundle } from '@kybernesis/arp-spec';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Error thrown when a template output fails its own Zod validation.
|
|
6
|
+
*
|
|
7
|
+
* Template functions are pure — inputs are typed, but defaults, URL
|
|
8
|
+
* composition, and date math still need a schema check before the object
|
|
9
|
+
* leaves the builder.
|
|
10
|
+
*/
|
|
11
|
+
declare class TemplateValidationError extends Error {
|
|
12
|
+
readonly issues: z.ZodIssue[];
|
|
13
|
+
constructor(templateName: string, issues: z.ZodIssue[]);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Validate `candidate` against `schema`. Throws `TemplateValidationError` on
|
|
17
|
+
* failure, returns the parsed value on success.
|
|
18
|
+
*/
|
|
19
|
+
declare function validateOrThrow<S extends ZodTypeAny>(templateName: string, schema: S, candidate: unknown): z.infer<S>;
|
|
20
|
+
/**
|
|
21
|
+
* Canonical service ID helper: `<agentDid>#<suffix>`.
|
|
22
|
+
*/
|
|
23
|
+
declare function makeServiceId(agentDid: string, suffix: string): string;
|
|
24
|
+
|
|
25
|
+
interface BuildDidDocumentInput {
|
|
26
|
+
/** Agent DID (e.g. "did:web:samantha.agent"). */
|
|
27
|
+
agentDid: DidUri;
|
|
28
|
+
/** Principal (controller) DID. May be a placeholder pre-binding. */
|
|
29
|
+
controllerDid: DidUri;
|
|
30
|
+
/** Ed25519 public key in multibase (z-base58btc). */
|
|
31
|
+
publicKeyMultibase: PublicKeyMultibase;
|
|
32
|
+
/** Service endpoints. */
|
|
33
|
+
endpoints: {
|
|
34
|
+
didcomm: string;
|
|
35
|
+
agentCard: string;
|
|
36
|
+
};
|
|
37
|
+
/** Representation VC URL served on the owner subdomain. */
|
|
38
|
+
representationVcUrl: string;
|
|
39
|
+
/** Optional verification-method key id suffix. Defaults to `key-1`. */
|
|
40
|
+
keyId?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Build a W3C DID Document conforming to ARP-tld-integration-spec-v2 §6.1.
|
|
44
|
+
*
|
|
45
|
+
* The output is validated against `DidDocumentSchema` before return; on
|
|
46
|
+
* failure a `TemplateValidationError` is thrown.
|
|
47
|
+
*/
|
|
48
|
+
declare function buildDidDocument(input: BuildDidDocumentInput): DidDocument;
|
|
49
|
+
|
|
50
|
+
interface BuildAgentCardInput {
|
|
51
|
+
name: string;
|
|
52
|
+
did: DidUri;
|
|
53
|
+
/** One-line description; defaults to "Personal agent". */
|
|
54
|
+
description?: string;
|
|
55
|
+
/** ISO 8601 datetime with offset. Defaults to `new Date().toISOString()`. */
|
|
56
|
+
createdAt?: string;
|
|
57
|
+
endpoints: {
|
|
58
|
+
didcomm: string;
|
|
59
|
+
/** Optional in v0 (stubbed). */
|
|
60
|
+
a2a?: string;
|
|
61
|
+
pairing: string;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Override accepted protocols. Defaults to the canonical `didcomm/v2` +
|
|
65
|
+
* `a2a/1.0` set from `@kybernesis/arp-spec`.
|
|
66
|
+
*/
|
|
67
|
+
acceptedProtocols?: readonly string[];
|
|
68
|
+
supportedScopes?: readonly string[];
|
|
69
|
+
payment?: {
|
|
70
|
+
x402Enabled: boolean;
|
|
71
|
+
currencies?: readonly string[];
|
|
72
|
+
pricingUrl?: string | null;
|
|
73
|
+
};
|
|
74
|
+
vcRequirements?: readonly string[];
|
|
75
|
+
/**
|
|
76
|
+
* HTTPS URL of the Cedar policy schema. Defaults to the conventional
|
|
77
|
+
* `<agent-origin>/.well-known/policy-schema.json` when `policySchemaUrl`
|
|
78
|
+
* is omitted and `agentOrigin` is provided.
|
|
79
|
+
*/
|
|
80
|
+
policySchemaUrl?: string;
|
|
81
|
+
/** Used to derive the default `policySchemaUrl`. */
|
|
82
|
+
agentOrigin?: string;
|
|
83
|
+
}
|
|
84
|
+
declare function buildAgentCard(input: BuildAgentCardInput): AgentCard;
|
|
85
|
+
|
|
86
|
+
interface BuildArpJsonInput {
|
|
87
|
+
/** HTTPS origin of the agent (e.g. "https://samantha.agent"). */
|
|
88
|
+
agentOrigin: string;
|
|
89
|
+
/**
|
|
90
|
+
* Override the advertised capabilities. Defaults to the v0 set:
|
|
91
|
+
* didcomm-v2, cedar-pdp, ucan-tokens.
|
|
92
|
+
*/
|
|
93
|
+
capabilities?: readonly string[];
|
|
94
|
+
/** Override the scope-catalog URL (defaults to `<agentOrigin>/.well-known/scope-catalog.json`). */
|
|
95
|
+
scopeCatalogUrl?: string;
|
|
96
|
+
/** Override the policy-schema URL (defaults to `<agentOrigin>/.well-known/policy-schema.json`). */
|
|
97
|
+
policySchemaUrl?: string;
|
|
98
|
+
}
|
|
99
|
+
declare function buildArpJson(input: BuildArpJsonInput): ArpJson;
|
|
100
|
+
|
|
101
|
+
interface BuildRepresentationVcInput {
|
|
102
|
+
/** Principal DID (the human doing the representing). */
|
|
103
|
+
principalDid: DidUri;
|
|
104
|
+
/** Agent DID (the agent being represented). */
|
|
105
|
+
agentDid: DidUri;
|
|
106
|
+
/** Issued-at (Unix seconds). Defaults to now. */
|
|
107
|
+
iat?: number;
|
|
108
|
+
/** Expiry (Unix seconds). Defaults to iat + 1 year. */
|
|
109
|
+
exp?: number;
|
|
110
|
+
/** Representation scope. Defaults to "full". */
|
|
111
|
+
scope?: 'full' | 'scoped';
|
|
112
|
+
constraints?: {
|
|
113
|
+
maxConcurrentConnections?: number;
|
|
114
|
+
allowedTransferOfOwnership?: boolean;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
declare function buildRepresentationVc(input: BuildRepresentationVcInput): RepresentationVc;
|
|
118
|
+
|
|
119
|
+
interface BuildRevocationsInput {
|
|
120
|
+
/** Issuer DID (principal). */
|
|
121
|
+
issuer: DidUri;
|
|
122
|
+
/** ISO 8601 timestamp. Defaults to now. */
|
|
123
|
+
updatedAt?: string;
|
|
124
|
+
/** Revocation entries. Defaults to empty. */
|
|
125
|
+
revocations?: readonly RevocationEntry[];
|
|
126
|
+
/** Signature over the JCS canonicalization of the unsigned document. */
|
|
127
|
+
signature: {
|
|
128
|
+
kid: string;
|
|
129
|
+
/** Base64url-encoded signature bytes. */
|
|
130
|
+
value: string;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
declare function buildRevocations(input: BuildRevocationsInput): Revocations;
|
|
134
|
+
|
|
135
|
+
interface BuildHandoffBundleInput {
|
|
136
|
+
agentDid: DidUri;
|
|
137
|
+
principalDid: DidUri;
|
|
138
|
+
publicKeyMultibase: PublicKeyMultibase;
|
|
139
|
+
/**
|
|
140
|
+
* HTTPS origin of the agent. Used to derive the canonical well-known URLs
|
|
141
|
+
* when individual overrides are not provided.
|
|
142
|
+
*/
|
|
143
|
+
agentOrigin: string;
|
|
144
|
+
/** Override well-known URLs (useful when hosting is on a different origin). */
|
|
145
|
+
wellKnownUrls?: {
|
|
146
|
+
did?: string;
|
|
147
|
+
agentCard?: string;
|
|
148
|
+
arp?: string;
|
|
149
|
+
};
|
|
150
|
+
dnsRecordsPublished: readonly DnsRecordTag[];
|
|
151
|
+
/** ISO 8601 cert expiry. */
|
|
152
|
+
certExpiresAt: string;
|
|
153
|
+
/** Bootstrap JWT scoped to the arp-sdk takeover (exp ≤ 15min). */
|
|
154
|
+
bootstrapToken: string;
|
|
155
|
+
}
|
|
156
|
+
declare function buildHandoffBundle(input: BuildHandoffBundleInput): HandoffBundle;
|
|
157
|
+
|
|
158
|
+
export { type BuildAgentCardInput, type BuildArpJsonInput, type BuildDidDocumentInput, type BuildHandoffBundleInput, type BuildRepresentationVcInput, type BuildRevocationsInput, TemplateValidationError, buildAgentCard, buildArpJson, buildDidDocument, buildHandoffBundle, buildRepresentationVc, buildRevocations, makeServiceId, validateOrThrow };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { z, ZodTypeAny } from 'zod';
|
|
2
|
+
import { DidUri, PublicKeyMultibase, DidDocument, AgentCard, ArpJson, RepresentationVc, RevocationEntry, Revocations, DnsRecordTag, HandoffBundle } from '@kybernesis/arp-spec';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Error thrown when a template output fails its own Zod validation.
|
|
6
|
+
*
|
|
7
|
+
* Template functions are pure — inputs are typed, but defaults, URL
|
|
8
|
+
* composition, and date math still need a schema check before the object
|
|
9
|
+
* leaves the builder.
|
|
10
|
+
*/
|
|
11
|
+
declare class TemplateValidationError extends Error {
|
|
12
|
+
readonly issues: z.ZodIssue[];
|
|
13
|
+
constructor(templateName: string, issues: z.ZodIssue[]);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Validate `candidate` against `schema`. Throws `TemplateValidationError` on
|
|
17
|
+
* failure, returns the parsed value on success.
|
|
18
|
+
*/
|
|
19
|
+
declare function validateOrThrow<S extends ZodTypeAny>(templateName: string, schema: S, candidate: unknown): z.infer<S>;
|
|
20
|
+
/**
|
|
21
|
+
* Canonical service ID helper: `<agentDid>#<suffix>`.
|
|
22
|
+
*/
|
|
23
|
+
declare function makeServiceId(agentDid: string, suffix: string): string;
|
|
24
|
+
|
|
25
|
+
interface BuildDidDocumentInput {
|
|
26
|
+
/** Agent DID (e.g. "did:web:samantha.agent"). */
|
|
27
|
+
agentDid: DidUri;
|
|
28
|
+
/** Principal (controller) DID. May be a placeholder pre-binding. */
|
|
29
|
+
controllerDid: DidUri;
|
|
30
|
+
/** Ed25519 public key in multibase (z-base58btc). */
|
|
31
|
+
publicKeyMultibase: PublicKeyMultibase;
|
|
32
|
+
/** Service endpoints. */
|
|
33
|
+
endpoints: {
|
|
34
|
+
didcomm: string;
|
|
35
|
+
agentCard: string;
|
|
36
|
+
};
|
|
37
|
+
/** Representation VC URL served on the owner subdomain. */
|
|
38
|
+
representationVcUrl: string;
|
|
39
|
+
/** Optional verification-method key id suffix. Defaults to `key-1`. */
|
|
40
|
+
keyId?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Build a W3C DID Document conforming to ARP-tld-integration-spec-v2 §6.1.
|
|
44
|
+
*
|
|
45
|
+
* The output is validated against `DidDocumentSchema` before return; on
|
|
46
|
+
* failure a `TemplateValidationError` is thrown.
|
|
47
|
+
*/
|
|
48
|
+
declare function buildDidDocument(input: BuildDidDocumentInput): DidDocument;
|
|
49
|
+
|
|
50
|
+
interface BuildAgentCardInput {
|
|
51
|
+
name: string;
|
|
52
|
+
did: DidUri;
|
|
53
|
+
/** One-line description; defaults to "Personal agent". */
|
|
54
|
+
description?: string;
|
|
55
|
+
/** ISO 8601 datetime with offset. Defaults to `new Date().toISOString()`. */
|
|
56
|
+
createdAt?: string;
|
|
57
|
+
endpoints: {
|
|
58
|
+
didcomm: string;
|
|
59
|
+
/** Optional in v0 (stubbed). */
|
|
60
|
+
a2a?: string;
|
|
61
|
+
pairing: string;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Override accepted protocols. Defaults to the canonical `didcomm/v2` +
|
|
65
|
+
* `a2a/1.0` set from `@kybernesis/arp-spec`.
|
|
66
|
+
*/
|
|
67
|
+
acceptedProtocols?: readonly string[];
|
|
68
|
+
supportedScopes?: readonly string[];
|
|
69
|
+
payment?: {
|
|
70
|
+
x402Enabled: boolean;
|
|
71
|
+
currencies?: readonly string[];
|
|
72
|
+
pricingUrl?: string | null;
|
|
73
|
+
};
|
|
74
|
+
vcRequirements?: readonly string[];
|
|
75
|
+
/**
|
|
76
|
+
* HTTPS URL of the Cedar policy schema. Defaults to the conventional
|
|
77
|
+
* `<agent-origin>/.well-known/policy-schema.json` when `policySchemaUrl`
|
|
78
|
+
* is omitted and `agentOrigin` is provided.
|
|
79
|
+
*/
|
|
80
|
+
policySchemaUrl?: string;
|
|
81
|
+
/** Used to derive the default `policySchemaUrl`. */
|
|
82
|
+
agentOrigin?: string;
|
|
83
|
+
}
|
|
84
|
+
declare function buildAgentCard(input: BuildAgentCardInput): AgentCard;
|
|
85
|
+
|
|
86
|
+
interface BuildArpJsonInput {
|
|
87
|
+
/** HTTPS origin of the agent (e.g. "https://samantha.agent"). */
|
|
88
|
+
agentOrigin: string;
|
|
89
|
+
/**
|
|
90
|
+
* Override the advertised capabilities. Defaults to the v0 set:
|
|
91
|
+
* didcomm-v2, cedar-pdp, ucan-tokens.
|
|
92
|
+
*/
|
|
93
|
+
capabilities?: readonly string[];
|
|
94
|
+
/** Override the scope-catalog URL (defaults to `<agentOrigin>/.well-known/scope-catalog.json`). */
|
|
95
|
+
scopeCatalogUrl?: string;
|
|
96
|
+
/** Override the policy-schema URL (defaults to `<agentOrigin>/.well-known/policy-schema.json`). */
|
|
97
|
+
policySchemaUrl?: string;
|
|
98
|
+
}
|
|
99
|
+
declare function buildArpJson(input: BuildArpJsonInput): ArpJson;
|
|
100
|
+
|
|
101
|
+
interface BuildRepresentationVcInput {
|
|
102
|
+
/** Principal DID (the human doing the representing). */
|
|
103
|
+
principalDid: DidUri;
|
|
104
|
+
/** Agent DID (the agent being represented). */
|
|
105
|
+
agentDid: DidUri;
|
|
106
|
+
/** Issued-at (Unix seconds). Defaults to now. */
|
|
107
|
+
iat?: number;
|
|
108
|
+
/** Expiry (Unix seconds). Defaults to iat + 1 year. */
|
|
109
|
+
exp?: number;
|
|
110
|
+
/** Representation scope. Defaults to "full". */
|
|
111
|
+
scope?: 'full' | 'scoped';
|
|
112
|
+
constraints?: {
|
|
113
|
+
maxConcurrentConnections?: number;
|
|
114
|
+
allowedTransferOfOwnership?: boolean;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
declare function buildRepresentationVc(input: BuildRepresentationVcInput): RepresentationVc;
|
|
118
|
+
|
|
119
|
+
interface BuildRevocationsInput {
|
|
120
|
+
/** Issuer DID (principal). */
|
|
121
|
+
issuer: DidUri;
|
|
122
|
+
/** ISO 8601 timestamp. Defaults to now. */
|
|
123
|
+
updatedAt?: string;
|
|
124
|
+
/** Revocation entries. Defaults to empty. */
|
|
125
|
+
revocations?: readonly RevocationEntry[];
|
|
126
|
+
/** Signature over the JCS canonicalization of the unsigned document. */
|
|
127
|
+
signature: {
|
|
128
|
+
kid: string;
|
|
129
|
+
/** Base64url-encoded signature bytes. */
|
|
130
|
+
value: string;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
declare function buildRevocations(input: BuildRevocationsInput): Revocations;
|
|
134
|
+
|
|
135
|
+
interface BuildHandoffBundleInput {
|
|
136
|
+
agentDid: DidUri;
|
|
137
|
+
principalDid: DidUri;
|
|
138
|
+
publicKeyMultibase: PublicKeyMultibase;
|
|
139
|
+
/**
|
|
140
|
+
* HTTPS origin of the agent. Used to derive the canonical well-known URLs
|
|
141
|
+
* when individual overrides are not provided.
|
|
142
|
+
*/
|
|
143
|
+
agentOrigin: string;
|
|
144
|
+
/** Override well-known URLs (useful when hosting is on a different origin). */
|
|
145
|
+
wellKnownUrls?: {
|
|
146
|
+
did?: string;
|
|
147
|
+
agentCard?: string;
|
|
148
|
+
arp?: string;
|
|
149
|
+
};
|
|
150
|
+
dnsRecordsPublished: readonly DnsRecordTag[];
|
|
151
|
+
/** ISO 8601 cert expiry. */
|
|
152
|
+
certExpiresAt: string;
|
|
153
|
+
/** Bootstrap JWT scoped to the arp-sdk takeover (exp ≤ 15min). */
|
|
154
|
+
bootstrapToken: string;
|
|
155
|
+
}
|
|
156
|
+
declare function buildHandoffBundle(input: BuildHandoffBundleInput): HandoffBundle;
|
|
157
|
+
|
|
158
|
+
export { type BuildAgentCardInput, type BuildArpJsonInput, type BuildDidDocumentInput, type BuildHandoffBundleInput, type BuildRepresentationVcInput, type BuildRevocationsInput, TemplateValidationError, buildAgentCard, buildArpJson, buildDidDocument, buildHandoffBundle, buildRepresentationVc, buildRevocations, makeServiceId, validateOrThrow };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { DidDocumentSchema, SUPPORTED_PROTOCOLS, ARP_VERSION, AgentCardSchema, ArpJsonSchema, RepresentationVcSchema, RevocationsSchema, HandoffBundleSchema } from '@kybernesis/arp-spec';
|
|
2
|
+
|
|
3
|
+
// src/util.ts
|
|
4
|
+
var TemplateValidationError = class extends Error {
|
|
5
|
+
issues;
|
|
6
|
+
constructor(templateName, issues) {
|
|
7
|
+
super(
|
|
8
|
+
`${templateName}: produced invalid output (${issues.length} issue${issues.length === 1 ? "" : "s"})`
|
|
9
|
+
);
|
|
10
|
+
this.name = "TemplateValidationError";
|
|
11
|
+
this.issues = issues;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
function validateOrThrow(templateName, schema, candidate) {
|
|
15
|
+
const parsed = schema.safeParse(candidate);
|
|
16
|
+
if (!parsed.success) {
|
|
17
|
+
throw new TemplateValidationError(templateName, parsed.error.issues);
|
|
18
|
+
}
|
|
19
|
+
return parsed.data;
|
|
20
|
+
}
|
|
21
|
+
function makeServiceId(agentDid, suffix) {
|
|
22
|
+
return `${agentDid}#${suffix}`;
|
|
23
|
+
}
|
|
24
|
+
function buildDidDocument(input) {
|
|
25
|
+
const keyId = input.keyId ?? "key-1";
|
|
26
|
+
const verificationMethodId = makeServiceId(input.agentDid, keyId);
|
|
27
|
+
const doc = {
|
|
28
|
+
"@context": ["https://www.w3.org/ns/did/v1"],
|
|
29
|
+
id: input.agentDid,
|
|
30
|
+
controller: input.controllerDid,
|
|
31
|
+
verificationMethod: [
|
|
32
|
+
{
|
|
33
|
+
id: verificationMethodId,
|
|
34
|
+
type: "Ed25519VerificationKey2020",
|
|
35
|
+
controller: input.agentDid,
|
|
36
|
+
publicKeyMultibase: input.publicKeyMultibase
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
authentication: [verificationMethodId],
|
|
40
|
+
assertionMethod: [verificationMethodId],
|
|
41
|
+
keyAgreement: [verificationMethodId],
|
|
42
|
+
service: [
|
|
43
|
+
{
|
|
44
|
+
id: makeServiceId(input.agentDid, "didcomm"),
|
|
45
|
+
type: "DIDCommMessaging",
|
|
46
|
+
serviceEndpoint: input.endpoints.didcomm,
|
|
47
|
+
accept: ["didcomm/v2"]
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: makeServiceId(input.agentDid, "agent-card"),
|
|
51
|
+
type: "AgentCard",
|
|
52
|
+
serviceEndpoint: input.endpoints.agentCard
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
principal: {
|
|
56
|
+
did: input.controllerDid,
|
|
57
|
+
representationVC: input.representationVcUrl
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
return validateOrThrow("buildDidDocument", DidDocumentSchema, doc);
|
|
61
|
+
}
|
|
62
|
+
function buildAgentCard(input) {
|
|
63
|
+
const policySchemaUrl = input.policySchemaUrl ?? (input.agentOrigin ? `${input.agentOrigin.replace(/\/$/, "")}/.well-known/policy-schema.json` : void 0);
|
|
64
|
+
if (!policySchemaUrl) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
"buildAgentCard: either policySchemaUrl or agentOrigin must be provided"
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
const card = {
|
|
70
|
+
arp_version: ARP_VERSION,
|
|
71
|
+
name: input.name,
|
|
72
|
+
did: input.did,
|
|
73
|
+
description: input.description ?? "Personal agent",
|
|
74
|
+
created_at: input.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
75
|
+
endpoints: {
|
|
76
|
+
didcomm: input.endpoints.didcomm,
|
|
77
|
+
...input.endpoints.a2a ? { a2a: input.endpoints.a2a } : {},
|
|
78
|
+
pairing: input.endpoints.pairing
|
|
79
|
+
},
|
|
80
|
+
accepted_protocols: [...input.acceptedProtocols ?? SUPPORTED_PROTOCOLS],
|
|
81
|
+
supported_scopes: [...input.supportedScopes ?? []],
|
|
82
|
+
payment: {
|
|
83
|
+
x402_enabled: input.payment?.x402Enabled ?? false,
|
|
84
|
+
currencies: [...input.payment?.currencies ?? []],
|
|
85
|
+
pricing_url: input.payment?.pricingUrl ?? null
|
|
86
|
+
},
|
|
87
|
+
vc_requirements: [...input.vcRequirements ?? []],
|
|
88
|
+
policy: {
|
|
89
|
+
engine: "cedar",
|
|
90
|
+
schema: policySchemaUrl
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
return validateOrThrow("buildAgentCard", AgentCardSchema, card);
|
|
94
|
+
}
|
|
95
|
+
var DEFAULT_CAPABILITIES = ["didcomm-v2", "cedar-pdp", "ucan-tokens"];
|
|
96
|
+
function buildArpJson(input) {
|
|
97
|
+
const origin = input.agentOrigin.replace(/\/$/, "");
|
|
98
|
+
const doc = {
|
|
99
|
+
version: ARP_VERSION,
|
|
100
|
+
capabilities: [...input.capabilities ?? DEFAULT_CAPABILITIES],
|
|
101
|
+
scope_catalog_url: input.scopeCatalogUrl ?? `${origin}/.well-known/scope-catalog.json`,
|
|
102
|
+
policy_schema_url: input.policySchemaUrl ?? `${origin}/.well-known/policy-schema.json`
|
|
103
|
+
};
|
|
104
|
+
return validateOrThrow("buildArpJson", ArpJsonSchema, doc);
|
|
105
|
+
}
|
|
106
|
+
var DEFAULT_MAX_CONCURRENT_CONNECTIONS = 100;
|
|
107
|
+
var ONE_YEAR_SECONDS = 365 * 24 * 60 * 60;
|
|
108
|
+
function buildRepresentationVc(input) {
|
|
109
|
+
const iat = input.iat ?? Math.floor(Date.now() / 1e3);
|
|
110
|
+
const exp = input.exp ?? iat + ONE_YEAR_SECONDS;
|
|
111
|
+
const doc = {
|
|
112
|
+
iss: input.principalDid,
|
|
113
|
+
sub: input.agentDid,
|
|
114
|
+
iat,
|
|
115
|
+
exp,
|
|
116
|
+
vc: {
|
|
117
|
+
"@context": ["https://www.w3.org/2018/credentials/v1"],
|
|
118
|
+
type: ["VerifiableCredential", "AgentRepresentation"],
|
|
119
|
+
credentialSubject: {
|
|
120
|
+
id: input.agentDid,
|
|
121
|
+
representedBy: input.principalDid,
|
|
122
|
+
scope: input.scope ?? "full",
|
|
123
|
+
constraints: {
|
|
124
|
+
maxConcurrentConnections: input.constraints?.maxConcurrentConnections ?? DEFAULT_MAX_CONCURRENT_CONNECTIONS,
|
|
125
|
+
allowedTransferOfOwnership: input.constraints?.allowedTransferOfOwnership ?? false
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
return validateOrThrow("buildRepresentationVc", RepresentationVcSchema, doc);
|
|
131
|
+
}
|
|
132
|
+
function buildRevocations(input) {
|
|
133
|
+
const doc = {
|
|
134
|
+
issuer: input.issuer,
|
|
135
|
+
updated_at: input.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
136
|
+
revocations: input.revocations ? [...input.revocations] : [],
|
|
137
|
+
signature: {
|
|
138
|
+
alg: "EdDSA",
|
|
139
|
+
kid: input.signature.kid,
|
|
140
|
+
value: input.signature.value
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
return validateOrThrow("buildRevocations", RevocationsSchema, doc);
|
|
144
|
+
}
|
|
145
|
+
function buildHandoffBundle(input) {
|
|
146
|
+
const origin = input.agentOrigin.replace(/\/$/, "");
|
|
147
|
+
const doc = {
|
|
148
|
+
agent_did: input.agentDid,
|
|
149
|
+
principal_did: input.principalDid,
|
|
150
|
+
public_key_multibase: input.publicKeyMultibase,
|
|
151
|
+
well_known_urls: {
|
|
152
|
+
did: input.wellKnownUrls?.did ?? `${origin}/.well-known/did.json`,
|
|
153
|
+
agent_card: input.wellKnownUrls?.agentCard ?? `${origin}/.well-known/agent-card.json`,
|
|
154
|
+
arp: input.wellKnownUrls?.arp ?? `${origin}/.well-known/arp.json`
|
|
155
|
+
},
|
|
156
|
+
dns_records_published: [...input.dnsRecordsPublished],
|
|
157
|
+
cert_expires_at: input.certExpiresAt,
|
|
158
|
+
bootstrap_token: input.bootstrapToken
|
|
159
|
+
};
|
|
160
|
+
return validateOrThrow("buildHandoffBundle", HandoffBundleSchema, doc);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export { TemplateValidationError, buildAgentCard, buildArpJson, buildDidDocument, buildHandoffBundle, buildRepresentationVc, buildRevocations, makeServiceId, validateOrThrow };
|
|
164
|
+
//# sourceMappingURL=index.js.map
|
|
165
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/util.ts","../src/did-document.ts","../src/agent-card.ts","../src/arp-json.ts","../src/representation-vc.ts","../src/revocations.ts","../src/handoff-bundle.ts"],"names":["ARP_VERSION"],"mappings":";;;AASO,IAAM,uBAAA,GAAN,cAAsC,KAAA,CAAM;AAAA,EACjC,MAAA;AAAA,EAEhB,WAAA,CAAY,cAAsB,MAAA,EAAsB;AACtD,IAAA,KAAA;AAAA,MACE,CAAA,EAAG,YAAY,CAAA,2BAAA,EAA8B,MAAA,CAAO,MAAM,SAAS,MAAA,CAAO,MAAA,KAAW,CAAA,GAAI,EAAA,GAAK,GAAG,CAAA,CAAA;AAAA,KACnG;AACA,IAAA,IAAA,CAAK,IAAA,GAAO,yBAAA;AACZ,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AAAA,EAChB;AACF;AAMO,SAAS,eAAA,CACd,YAAA,EACA,MAAA,EACA,SAAA,EACY;AACZ,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,SAAA,CAAU,SAAS,CAAA;AACzC,EAAA,IAAI,CAAC,OAAO,OAAA,EAAS;AACnB,IAAA,MAAM,IAAI,uBAAA,CAAwB,YAAA,EAAc,MAAA,CAAO,MAAM,MAAM,CAAA;AAAA,EACrE;AACA,EAAA,OAAO,MAAA,CAAO,IAAA;AAChB;AAKO,SAAS,aAAA,CAAc,UAAkB,MAAA,EAAwB;AACtE,EAAA,OAAO,CAAA,EAAG,QAAQ,CAAA,CAAA,EAAI,MAAM,CAAA,CAAA;AAC9B;ACVO,SAAS,iBAAiB,KAAA,EAA2C;AAC1E,EAAA,MAAM,KAAA,GAAQ,MAAM,KAAA,IAAS,OAAA;AAC7B,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AAA,EAAK,KAAA,CAAM,aAAA,EAAe,GAAA,IAAO,GAAG,MAAM,CAAA,qBAAA,CAAA;AAAA,MAC1C,UAAA,EACE,KAAA,CAAM,aAAA,EAAe,SAAA,IAAa,GAAG,MAAM,CAAA,4BAAA,CAAA;AAAA,MAC7C,GAAA,EAAK,KAAA,CAAM,aAAA,EAAe,GAAA,IAAO,GAAG,MAAM,CAAA,qBAAA;AAAA,KAC5C;AAAA,IACA,qBAAA,EAAuB,CAAC,GAAG,KAAA,CAAM,mBAAmB,CAAA;AAAA,IACpD,iBAAiB,KAAA,CAAM,aAAA;AAAA,IACvB,iBAAiB,KAAA,CAAM;AAAA,GACzB;AAEA,EAAA,OAAO,eAAA,CAAgB,oBAAA,EAAsB,mBAAA,EAAqB,GAAG,CAAA;AACvE","file":"index.js","sourcesContent":["import { z, type ZodTypeAny } from 'zod';\n\n/**\n * Error thrown when a template output fails its own Zod validation.\n *\n * Template functions are pure — inputs are typed, but defaults, URL\n * composition, and date math still need a schema check before the object\n * leaves the builder.\n */\nexport class TemplateValidationError extends Error {\n public readonly issues: z.ZodIssue[];\n\n constructor(templateName: string, issues: z.ZodIssue[]) {\n super(\n `${templateName}: produced invalid output (${issues.length} issue${issues.length === 1 ? '' : 's'})`\n );\n this.name = 'TemplateValidationError';\n this.issues = issues;\n }\n}\n\n/**\n * Validate `candidate` against `schema`. Throws `TemplateValidationError` on\n * failure, returns the parsed value on success.\n */\nexport function validateOrThrow<S extends ZodTypeAny>(\n templateName: string,\n schema: S,\n candidate: unknown\n): z.infer<S> {\n const parsed = schema.safeParse(candidate);\n if (!parsed.success) {\n throw new TemplateValidationError(templateName, parsed.error.issues);\n }\n return parsed.data;\n}\n\n/**\n * Canonical service ID helper: `<agentDid>#<suffix>`.\n */\nexport function makeServiceId(agentDid: string, suffix: string): string {\n return `${agentDid}#${suffix}`;\n}\n","import {\n DidDocumentSchema,\n type DidDocument,\n type DidUri,\n type PublicKeyMultibase,\n} from '@kybernesis/arp-spec';\nimport { validateOrThrow, makeServiceId } from './util.js';\n\nexport interface BuildDidDocumentInput {\n /** Agent DID (e.g. \"did:web:samantha.agent\"). */\n agentDid: DidUri;\n /** Principal (controller) DID. May be a placeholder pre-binding. */\n controllerDid: DidUri;\n /** Ed25519 public key in multibase (z-base58btc). */\n publicKeyMultibase: PublicKeyMultibase;\n /** Service endpoints. */\n endpoints: {\n didcomm: string;\n agentCard: string;\n };\n /** Representation VC URL served on the owner subdomain. */\n representationVcUrl: string;\n /** Optional verification-method key id suffix. Defaults to `key-1`. */\n keyId?: string;\n}\n\n/**\n * Build a W3C DID Document conforming to ARP-tld-integration-spec-v2 §6.1.\n *\n * The output is validated against `DidDocumentSchema` before return; on\n * failure a `TemplateValidationError` is thrown.\n */\nexport function buildDidDocument(input: BuildDidDocumentInput): DidDocument {\n const keyId = input.keyId ?? 'key-1';\n const verificationMethodId = makeServiceId(input.agentDid, keyId);\n\n const doc = {\n '@context': ['https://www.w3.org/ns/did/v1'],\n id: input.agentDid,\n controller: input.controllerDid,\n verificationMethod: [\n {\n id: verificationMethodId,\n type: 'Ed25519VerificationKey2020' as const,\n controller: input.agentDid,\n publicKeyMultibase: input.publicKeyMultibase,\n },\n ],\n authentication: [verificationMethodId],\n assertionMethod: [verificationMethodId],\n keyAgreement: [verificationMethodId],\n service: [\n {\n id: makeServiceId(input.agentDid, 'didcomm'),\n type: 'DIDCommMessaging' as const,\n serviceEndpoint: input.endpoints.didcomm,\n accept: ['didcomm/v2'],\n },\n {\n id: makeServiceId(input.agentDid, 'agent-card'),\n type: 'AgentCard' as const,\n serviceEndpoint: input.endpoints.agentCard,\n },\n ],\n principal: {\n did: input.controllerDid,\n representationVC: input.representationVcUrl,\n },\n };\n\n return validateOrThrow('buildDidDocument', DidDocumentSchema, doc);\n}\n","import {\n AgentCardSchema,\n ARP_VERSION,\n SUPPORTED_PROTOCOLS,\n type AgentCard,\n type DidUri,\n} from '@kybernesis/arp-spec';\nimport { validateOrThrow } from './util.js';\n\nexport interface BuildAgentCardInput {\n name: string;\n did: DidUri;\n /** One-line description; defaults to \"Personal agent\". */\n description?: string;\n /** ISO 8601 datetime with offset. Defaults to `new Date().toISOString()`. */\n createdAt?: string;\n endpoints: {\n didcomm: string;\n /** Optional in v0 (stubbed). */\n a2a?: string;\n pairing: string;\n };\n /**\n * Override accepted protocols. Defaults to the canonical `didcomm/v2` +\n * `a2a/1.0` set from `@kybernesis/arp-spec`.\n */\n acceptedProtocols?: readonly string[];\n supportedScopes?: readonly string[];\n payment?: {\n x402Enabled: boolean;\n currencies?: readonly string[];\n pricingUrl?: string | null;\n };\n vcRequirements?: readonly string[];\n /**\n * HTTPS URL of the Cedar policy schema. Defaults to the conventional\n * `<agent-origin>/.well-known/policy-schema.json` when `policySchemaUrl`\n * is omitted and `agentOrigin` is provided.\n */\n policySchemaUrl?: string;\n /** Used to derive the default `policySchemaUrl`. */\n agentOrigin?: string;\n}\n\nexport function buildAgentCard(input: BuildAgentCardInput): AgentCard {\n const policySchemaUrl =\n input.policySchemaUrl ??\n (input.agentOrigin\n ? `${input.agentOrigin.replace(/\\/$/, '')}/.well-known/policy-schema.json`\n : undefined);\n\n if (!policySchemaUrl) {\n throw new Error(\n 'buildAgentCard: either policySchemaUrl or agentOrigin must be provided'\n );\n }\n\n const card = {\n arp_version: ARP_VERSION,\n name: input.name,\n did: input.did,\n description: input.description ?? 'Personal agent',\n created_at: input.createdAt ?? new Date().toISOString(),\n endpoints: {\n didcomm: input.endpoints.didcomm,\n ...(input.endpoints.a2a ? { a2a: input.endpoints.a2a } : {}),\n pairing: input.endpoints.pairing,\n },\n accepted_protocols: [...(input.acceptedProtocols ?? SUPPORTED_PROTOCOLS)],\n supported_scopes: [...(input.supportedScopes ?? [])],\n payment: {\n x402_enabled: input.payment?.x402Enabled ?? false,\n currencies: [...(input.payment?.currencies ?? [])],\n pricing_url: input.payment?.pricingUrl ?? null,\n },\n vc_requirements: [...(input.vcRequirements ?? [])],\n policy: {\n engine: 'cedar' as const,\n schema: policySchemaUrl,\n },\n };\n\n return validateOrThrow('buildAgentCard', AgentCardSchema, card);\n}\n","import { ArpJsonSchema, ARP_VERSION, type ArpJson } from '@kybernesis/arp-spec';\nimport { validateOrThrow } from './util.js';\n\nexport interface BuildArpJsonInput {\n /** HTTPS origin of the agent (e.g. \"https://samantha.agent\"). */\n agentOrigin: string;\n /**\n * Override the advertised capabilities. Defaults to the v0 set:\n * didcomm-v2, cedar-pdp, ucan-tokens.\n */\n capabilities?: readonly string[];\n /** Override the scope-catalog URL (defaults to `<agentOrigin>/.well-known/scope-catalog.json`). */\n scopeCatalogUrl?: string;\n /** Override the policy-schema URL (defaults to `<agentOrigin>/.well-known/policy-schema.json`). */\n policySchemaUrl?: string;\n}\n\nconst DEFAULT_CAPABILITIES = ['didcomm-v2', 'cedar-pdp', 'ucan-tokens'] as const;\n\nexport function buildArpJson(input: BuildArpJsonInput): ArpJson {\n const origin = input.agentOrigin.replace(/\\/$/, '');\n const doc = {\n version: ARP_VERSION,\n capabilities: [...(input.capabilities ?? DEFAULT_CAPABILITIES)],\n scope_catalog_url:\n input.scopeCatalogUrl ?? `${origin}/.well-known/scope-catalog.json`,\n policy_schema_url:\n input.policySchemaUrl ?? `${origin}/.well-known/policy-schema.json`,\n };\n return validateOrThrow('buildArpJson', ArpJsonSchema, doc);\n}\n","import {\n RepresentationVcSchema,\n type RepresentationVc,\n type DidUri,\n} from '@kybernesis/arp-spec';\nimport { validateOrThrow } from './util.js';\n\nexport interface BuildRepresentationVcInput {\n /** Principal DID (the human doing the representing). */\n principalDid: DidUri;\n /** Agent DID (the agent being represented). */\n agentDid: DidUri;\n /** Issued-at (Unix seconds). Defaults to now. */\n iat?: number;\n /** Expiry (Unix seconds). Defaults to iat + 1 year. */\n exp?: number;\n /** Representation scope. Defaults to \"full\". */\n scope?: 'full' | 'scoped';\n constraints?: {\n maxConcurrentConnections?: number;\n allowedTransferOfOwnership?: boolean;\n };\n}\n\nconst DEFAULT_MAX_CONCURRENT_CONNECTIONS = 100;\nconst ONE_YEAR_SECONDS = 365 * 24 * 60 * 60;\n\nexport function buildRepresentationVc(input: BuildRepresentationVcInput): RepresentationVc {\n const iat = input.iat ?? Math.floor(Date.now() / 1000);\n const exp = input.exp ?? iat + ONE_YEAR_SECONDS;\n\n const doc = {\n iss: input.principalDid,\n sub: input.agentDid,\n iat,\n exp,\n vc: {\n '@context': ['https://www.w3.org/2018/credentials/v1'],\n type: ['VerifiableCredential', 'AgentRepresentation'],\n credentialSubject: {\n id: input.agentDid,\n representedBy: input.principalDid,\n scope: input.scope ?? ('full' as const),\n constraints: {\n maxConcurrentConnections:\n input.constraints?.maxConcurrentConnections ?? DEFAULT_MAX_CONCURRENT_CONNECTIONS,\n allowedTransferOfOwnership: input.constraints?.allowedTransferOfOwnership ?? false,\n },\n },\n },\n };\n\n return validateOrThrow('buildRepresentationVc', RepresentationVcSchema, doc);\n}\n","import {\n RevocationsSchema,\n type Revocations,\n type RevocationEntry,\n type DidUri,\n} from '@kybernesis/arp-spec';\nimport { validateOrThrow } from './util.js';\n\nexport interface BuildRevocationsInput {\n /** Issuer DID (principal). */\n issuer: DidUri;\n /** ISO 8601 timestamp. Defaults to now. */\n updatedAt?: string;\n /** Revocation entries. Defaults to empty. */\n revocations?: readonly RevocationEntry[];\n /** Signature over the JCS canonicalization of the unsigned document. */\n signature: {\n kid: string;\n /** Base64url-encoded signature bytes. */\n value: string;\n };\n}\n\nexport function buildRevocations(input: BuildRevocationsInput): Revocations {\n const doc = {\n issuer: input.issuer,\n updated_at: input.updatedAt ?? new Date().toISOString(),\n revocations: input.revocations ? [...input.revocations] : [],\n signature: {\n alg: 'EdDSA' as const,\n kid: input.signature.kid,\n value: input.signature.value,\n },\n };\n\n return validateOrThrow('buildRevocations', RevocationsSchema, doc);\n}\n","import {\n HandoffBundleSchema,\n type HandoffBundle,\n type DidUri,\n type PublicKeyMultibase,\n type DnsRecordTag,\n} from '@kybernesis/arp-spec';\nimport { validateOrThrow } from './util.js';\n\nexport interface BuildHandoffBundleInput {\n agentDid: DidUri;\n principalDid: DidUri;\n publicKeyMultibase: PublicKeyMultibase;\n /**\n * HTTPS origin of the agent. Used to derive the canonical well-known URLs\n * when individual overrides are not provided.\n */\n agentOrigin: string;\n /** Override well-known URLs (useful when hosting is on a different origin). */\n wellKnownUrls?: {\n did?: string;\n agentCard?: string;\n arp?: string;\n };\n dnsRecordsPublished: readonly DnsRecordTag[];\n /** ISO 8601 cert expiry. */\n certExpiresAt: string;\n /** Bootstrap JWT scoped to the arp-sdk takeover (exp ≤ 15min). */\n bootstrapToken: string;\n}\n\nexport function buildHandoffBundle(input: BuildHandoffBundleInput): HandoffBundle {\n const origin = input.agentOrigin.replace(/\\/$/, '');\n const doc = {\n agent_did: input.agentDid,\n principal_did: input.principalDid,\n public_key_multibase: input.publicKeyMultibase,\n well_known_urls: {\n did: input.wellKnownUrls?.did ?? `${origin}/.well-known/did.json`,\n agent_card:\n input.wellKnownUrls?.agentCard ?? `${origin}/.well-known/agent-card.json`,\n arp: input.wellKnownUrls?.arp ?? `${origin}/.well-known/arp.json`,\n },\n dns_records_published: [...input.dnsRecordsPublished],\n cert_expires_at: input.certExpiresAt,\n bootstrap_token: input.bootstrapToken,\n };\n\n return validateOrThrow('buildHandoffBundle', HandoffBundleSchema, doc);\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kybernesis/arp-templates",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "ARP document builders — pure functions that produce validated DID documents, agent cards, arp.json, representation VCs, revocations, and handoff bundles.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/KybernesisAI/arp.git",
|
|
9
|
+
"directory": "packages/templates"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./dist/index.cjs",
|
|
16
|
+
"module": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"require": "./dist/index.cjs"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"README.md"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"zod": "^3.23.8",
|
|
31
|
+
"@kybernesis/arp-spec": "0.2.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsup",
|
|
36
|
+
"test": "vitest run",
|
|
37
|
+
"typecheck": "tsc --noEmit",
|
|
38
|
+
"lint": "eslint src tests"
|
|
39
|
+
}
|
|
40
|
+
}
|