a2a-did 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +180 -0
  3. package/dist/a2a/constants.d.ts +10 -0
  4. package/dist/a2a/constants.d.ts.map +1 -0
  5. package/dist/a2a/constants.js +10 -0
  6. package/dist/a2a/constants.js.map +1 -0
  7. package/dist/a2a/index.d.ts +23 -0
  8. package/dist/a2a/index.d.ts.map +1 -0
  9. package/dist/a2a/index.js +27 -0
  10. package/dist/a2a/index.js.map +1 -0
  11. package/dist/a2a/resolution.d.ts +20 -0
  12. package/dist/a2a/resolution.d.ts.map +1 -0
  13. package/dist/a2a/resolution.js +55 -0
  14. package/dist/a2a/resolution.js.map +1 -0
  15. package/dist/a2a/signing.d.ts +24 -0
  16. package/dist/a2a/signing.d.ts.map +1 -0
  17. package/dist/a2a/signing.js +31 -0
  18. package/dist/a2a/signing.js.map +1 -0
  19. package/dist/a2a/utils.d.ts +29 -0
  20. package/dist/a2a/utils.d.ts.map +1 -0
  21. package/dist/a2a/utils.js +70 -0
  22. package/dist/a2a/utils.js.map +1 -0
  23. package/dist/a2a/verification.d.ts +42 -0
  24. package/dist/a2a/verification.d.ts.map +1 -0
  25. package/dist/a2a/verification.js +156 -0
  26. package/dist/a2a/verification.js.map +1 -0
  27. package/dist/agent.d.ts +99 -0
  28. package/dist/agent.d.ts.map +1 -0
  29. package/dist/agent.js +149 -0
  30. package/dist/agent.js.map +1 -0
  31. package/dist/did/config-types.d.ts +37 -0
  32. package/dist/did/config-types.d.ts.map +1 -0
  33. package/dist/did/config-types.js +6 -0
  34. package/dist/did/config-types.js.map +1 -0
  35. package/dist/did/document.d.ts +20 -0
  36. package/dist/did/document.d.ts.map +1 -0
  37. package/dist/did/document.js +21 -0
  38. package/dist/did/document.js.map +1 -0
  39. package/dist/did/factory.d.ts +31 -0
  40. package/dist/did/factory.d.ts.map +1 -0
  41. package/dist/did/factory.js +46 -0
  42. package/dist/did/factory.js.map +1 -0
  43. package/dist/did/handlers/ethr-handler.d.ts +62 -0
  44. package/dist/did/handlers/ethr-handler.d.ts.map +1 -0
  45. package/dist/did/handlers/ethr-handler.js +184 -0
  46. package/dist/did/handlers/ethr-handler.js.map +1 -0
  47. package/dist/did/handlers/web-handler.d.ts +73 -0
  48. package/dist/did/handlers/web-handler.d.ts.map +1 -0
  49. package/dist/did/handlers/web-handler.js +170 -0
  50. package/dist/did/handlers/web-handler.js.map +1 -0
  51. package/dist/did/index.d.ts +10 -0
  52. package/dist/did/index.d.ts.map +1 -0
  53. package/dist/did/index.js +15 -0
  54. package/dist/did/index.js.map +1 -0
  55. package/dist/did/resolver.d.ts +85 -0
  56. package/dist/did/resolver.d.ts.map +1 -0
  57. package/dist/did/resolver.js +120 -0
  58. package/dist/did/resolver.js.map +1 -0
  59. package/dist/did/resolvers/ethr.d.ts +74 -0
  60. package/dist/did/resolvers/ethr.d.ts.map +1 -0
  61. package/dist/did/resolvers/ethr.js +67 -0
  62. package/dist/did/resolvers/ethr.js.map +1 -0
  63. package/dist/did/resolvers/index.d.ts +8 -0
  64. package/dist/did/resolvers/index.d.ts.map +1 -0
  65. package/dist/did/resolvers/index.js +8 -0
  66. package/dist/did/resolvers/index.js.map +1 -0
  67. package/dist/did/resolvers/web.d.ts +13 -0
  68. package/dist/did/resolvers/web.d.ts.map +1 -0
  69. package/dist/did/resolvers/web.js +97 -0
  70. package/dist/did/resolvers/web.js.map +1 -0
  71. package/dist/did/service-loader.d.ts +15 -0
  72. package/dist/did/service-loader.d.ts.map +1 -0
  73. package/dist/did/service-loader.js +20 -0
  74. package/dist/did/service-loader.js.map +1 -0
  75. package/dist/did/service.d.ts +99 -0
  76. package/dist/did/service.d.ts.map +1 -0
  77. package/dist/did/service.js +75 -0
  78. package/dist/did/service.js.map +1 -0
  79. package/dist/did/signing.d.ts +19 -0
  80. package/dist/did/signing.d.ts.map +1 -0
  81. package/dist/did/signing.js +37 -0
  82. package/dist/did/signing.js.map +1 -0
  83. package/dist/did/types.d.ts +134 -0
  84. package/dist/did/types.d.ts.map +1 -0
  85. package/dist/did/types.js +2 -0
  86. package/dist/did/types.js.map +1 -0
  87. package/dist/index.d.ts +15 -0
  88. package/dist/index.d.ts.map +1 -0
  89. package/dist/index.js +17 -0
  90. package/dist/index.js.map +1 -0
  91. package/dist/types.d.ts +25 -0
  92. package/dist/types.d.ts.map +1 -0
  93. package/dist/types.js +2 -0
  94. package/dist/types.js.map +1 -0
  95. package/package.json +70 -0
@@ -0,0 +1,156 @@
1
+ /**
2
+ * A2A Verification Functions
3
+ * Agent Card と A2A メッセージの署名検証
4
+ * @module a2a/verification
5
+ */
6
+ import { verifyJWS } from 'did-jwt';
7
+ import { resolveDID } from '../did/resolver.js';
8
+ import { base64UrlEncode, decodeBase64UrlJson, fetchUri, jsonEquals } from './utils.js';
9
+ import { extractAgentCardUrl } from './resolution.js';
10
+ /**
11
+ * Verify AgentCard signature
12
+ * @param agentCardUrl - URL to fetch AgentCard from (supports http://, https://, ipfs://)
13
+ * @returns Verification result with signer DID if successful
14
+ */
15
+ export async function verifyAgentCard(agentCardUrl) {
16
+ try {
17
+ // 1. Fetch AgentCard with cryptographic verification (supports http://, https://, ipfs://)
18
+ const response = await fetchUri(agentCardUrl);
19
+ if (!response.ok) {
20
+ return { verified: false, error: `Failed to fetch AgentCard: ${response.status}` };
21
+ }
22
+ const signedCard = await response.json();
23
+ // 2. Check for signatures
24
+ if (!signedCard.signatures || signedCard.signatures.length === 0) {
25
+ return { verified: false, error: 'AgentCard has no signatures' };
26
+ }
27
+ const sig = signedCard.signatures[0];
28
+ // 3. Extract signer DID from protected header (kid field)
29
+ const header = decodeBase64UrlJson(sig.protected);
30
+ if (!header.kid) {
31
+ return { verified: false, error: 'No kid in signature header' };
32
+ }
33
+ // Extract DID from kid (format: did:...:...#key-1)
34
+ const kid = header.kid;
35
+ const signerDid = kid.split('#')[0];
36
+ // 4. Resolve signer's DID to get public key
37
+ const didDocument = await resolveDID(signerDid);
38
+ if (!didDocument) {
39
+ return { verified: false, error: `Failed to resolve signer DID: ${signerDid}` };
40
+ }
41
+ // 5. Find verification method matching the kid
42
+ const keyFragment = kid.split('#')[1];
43
+ const verificationMethod = didDocument.verificationMethod?.find(vm => vm.id === kid || vm.id === `${signerDid}#${keyFragment}`);
44
+ if (!verificationMethod) {
45
+ return { verified: false, error: `No matching verification method for kid: ${kid}` };
46
+ }
47
+ // 6. Reconstruct compact JWS and verify
48
+ // Remove signatures from card to get original payload
49
+ const { signatures: _sigs, ...cardWithoutSig } = signedCard;
50
+ const payloadBase64 = base64UrlEncode(JSON.stringify(cardWithoutSig));
51
+ const compactJws = `${sig.protected}.${payloadBase64}.${sig.signature}`;
52
+ // 7. Verify signature
53
+ verifyJWS(compactJws, verificationMethod);
54
+ return { verified: true, signerDid };
55
+ }
56
+ catch (error) {
57
+ return {
58
+ verified: false,
59
+ error: error instanceof Error ? error.message : 'Unknown verification error',
60
+ };
61
+ }
62
+ }
63
+ /**
64
+ * Verify A2A message JWS signature using DID public key
65
+ * Follows A2A Protocol 0.3.0: Verifies Agent Card signature first, then message signature
66
+ *
67
+ * @param jws - The JWS signature string (compact format)
68
+ * @returns Verification result with sender DID if successful
69
+ */
70
+ export async function verifyA2AMessageSignature(jws) {
71
+ try {
72
+ // 1. Decode the JWS to get the protected header
73
+ const parts = jws.split('.');
74
+ if (parts.length !== 3) {
75
+ return { valid: false, error: 'Invalid JWS format' };
76
+ }
77
+ const header = decodeBase64UrlJson(parts[0]);
78
+ if (!header.kid) {
79
+ return { valid: false, error: 'No kid in signature header' };
80
+ }
81
+ const senderDid = header.kid.split('#')[0];
82
+ // 2. Resolve sender's DID to get public key
83
+ const didDocument = await resolveDID(senderDid);
84
+ if (!didDocument) {
85
+ return { valid: false, error: `Failed to resolve sender DID: ${senderDid}` };
86
+ }
87
+ // 3. ⭐ Verify Agent Card (A2A Protocol 0.3.0 requirement)
88
+ const agentCardUrl = extractAgentCardUrl(didDocument);
89
+ if (!agentCardUrl) {
90
+ return { valid: false, error: 'No Agent Card URL in DID Document' };
91
+ }
92
+ const cardVerification = await verifyAgentCard(agentCardUrl);
93
+ if (!cardVerification.verified) {
94
+ return {
95
+ valid: false,
96
+ error: `Agent Card verification failed: ${cardVerification.error}`
97
+ };
98
+ }
99
+ // 4. Verify Agent Card signer matches message sender
100
+ if (cardVerification.signerDid !== senderDid) {
101
+ return {
102
+ valid: false,
103
+ error: 'Agent Card signer does not match message sender'
104
+ };
105
+ }
106
+ // 5. Find verification method matching the kid
107
+ const keyFragment = header.kid.split('#')[1];
108
+ const verificationMethod = didDocument.verificationMethod?.find(vm => vm.id === header.kid || vm.id === `${senderDid}#${keyFragment}`);
109
+ if (!verificationMethod) {
110
+ return { valid: false, error: `No matching verification method for kid: ${header.kid}` };
111
+ }
112
+ // 6. Verify message signature with the DID public key
113
+ verifyJWS(jws, verificationMethod);
114
+ return { valid: true, senderDid };
115
+ }
116
+ catch (error) {
117
+ return {
118
+ valid: false,
119
+ error: error instanceof Error ? error.message : 'Unknown verification error',
120
+ };
121
+ }
122
+ }
123
+ /**
124
+ * Verify A2A request with signature validation and payload integrity check
125
+ * This is a convenience function for API servers to validate incoming signed requests
126
+ *
127
+ * @param request - The signed A2A request (JSON-RPC with signature field)
128
+ * @returns Verification result with sender DID if successful
129
+ */
130
+ export async function verifySignedA2ARequest(request) {
131
+ if (!request.signature) {
132
+ return { valid: false, error: 'No signature in request' };
133
+ }
134
+ try {
135
+ // 1. Verify the JWS signature
136
+ const signatureResult = await verifyA2AMessageSignature(request.signature);
137
+ if (!signatureResult.valid) {
138
+ return signatureResult;
139
+ }
140
+ // 2. Verify payload integrity (JWS payload matches request body)
141
+ const parts = request.signature.split('.');
142
+ const payload = decodeBase64UrlJson(parts[1]);
143
+ const { signature: _sig, ...requestWithoutSig } = request;
144
+ if (!jsonEquals(payload, requestWithoutSig)) {
145
+ return { valid: false, error: 'JWS payload does not match request body' };
146
+ }
147
+ return { valid: true, senderDid: signatureResult.senderDid };
148
+ }
149
+ catch (error) {
150
+ return {
151
+ valid: false,
152
+ error: error instanceof Error ? error.message : 'Unknown verification error',
153
+ };
154
+ }
155
+ }
156
+ //# sourceMappingURL=verification.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verification.js","sourceRoot":"","sources":["../../src/a2a/verification.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxF,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAmCtD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,YAAoB;IAEpB,IAAI,CAAC;QACH,2FAA2F;QAC3F,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,YAAY,CAAC,CAAC;QAC9C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,8BAA8B,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;QACrF,CAAC;QACD,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAqB,CAAC;QAE5D,0BAA0B;QAC1B,IAAI,CAAC,UAAU,CAAC,UAAU,IAAI,UAAU,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACjE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,6BAA6B,EAAE,CAAC;QACnE,CAAC;QAED,MAAM,GAAG,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC,CAAE,CAAC;QAEtC,0DAA0D;QAC1D,MAAM,MAAM,GAAG,mBAAmB,CAAC,GAAG,CAAC,SAAS,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types.js';
2
+ import type { SignedPayload, VerificationResult } from './types.js';
3
+ /**
4
+ * Agent configuration
5
+ */
6
+ export interface AgentConfig {
7
+ /** Agent name */
8
+ name: string;
9
+ /** Agent description */
10
+ description?: string;
11
+ }
12
+ /**
13
+ * Agent - an autonomous entity with DID identity
14
+ *
15
+ * DID identity is injected, not inherited.
16
+ * Agent can use any DID method (did:web, did:ethr)
17
+ */
18
+ export declare class Agent {
19
+ /** Injected DID identity */
20
+ readonly identity: DIDIdentity;
21
+ /** Agent ID (short identifier) */
22
+ readonly id: string;
23
+ /** Agent name */
24
+ readonly name: string;
25
+ /** Agent description */
26
+ readonly description: string;
27
+ /**
28
+ * Create an Agent with injected DID identity
29
+ * @param identity - DID identity from any provider (did:web, did:ethr)
30
+ * @param id - Short identifier for the agent
31
+ * @param config - Agent configuration (name, description)
32
+ */
33
+ constructor(identity: DIDIdentity, id: string, config: AgentConfig);
34
+ /**
35
+ * Agent's DID
36
+ * @returns The DID string (e.g., "did:web:example.com:agents:bot-1")
37
+ */
38
+ get did(): string;
39
+ /**
40
+ * Key ID for signing
41
+ * @returns The key ID used in JWS/JWT (e.g., "did:web:example.com:agents:bot-1#key-1")
42
+ */
43
+ get keyId(): string;
44
+ /**
45
+ * DID Document (if available locally)
46
+ * - did:web: Available (locally generated)
47
+ * - did:ethr: undefined (use resolveDID() to get from chain)
48
+ * @returns The W3C DID Document or undefined
49
+ */
50
+ get document(): import("./did/types.js").DIDDocument | undefined;
51
+ /**
52
+ * Check if local DID Document is available
53
+ * @returns true if document is available locally
54
+ */
55
+ hasLocalDocument(): boolean;
56
+ /**
57
+ * Controller DID (if set in local document)
58
+ * @returns The DID of the controller (typically a Human), or undefined
59
+ */
60
+ get controller(): string | undefined;
61
+ /**
62
+ * Get all service endpoints from local DID Document
63
+ * For did:ethr, use resolveDID() instead to get on-chain services
64
+ * @returns Array of service endpoints (empty if no local document)
65
+ */
66
+ getServices(): ServiceEndpoint[];
67
+ /**
68
+ * Get a specific service by type from local DID Document
69
+ * For did:ethr, use resolveDID() instead to get on-chain services
70
+ * @param type - The service type to find (e.g., "A2AAgent")
71
+ * @returns The service endpoint if found, undefined otherwise
72
+ */
73
+ getService(type: string): ServiceEndpoint | undefined;
74
+ /**
75
+ * Get A2A Agent Card URL from local DID Document
76
+ * For did:ethr, use resolveDID() instead to get on-chain Agent Card URL
77
+ * @returns The Agent Card URL if configured, undefined otherwise
78
+ */
79
+ getA2AEndpoint(): string | undefined;
80
+ /**
81
+ * Sign a payload as JWT
82
+ * @param payload - The payload to sign
83
+ * @returns Signed payload containing the JWT and original payload
84
+ */
85
+ sign<T extends Record<string, unknown>>(payload: T): Promise<SignedPayload<T>>;
86
+ /**
87
+ * Sign data directly as JWS (no iss/iat claims)
88
+ * @param data - The data to sign
89
+ * @returns The compact JWS string
90
+ */
91
+ signJWS(data: Record<string, unknown>): Promise<string>;
92
+ /**
93
+ * Verify a signed payload
94
+ * @param signed - The signed payload to verify
95
+ * @returns Verification result with issuer and payload if successful
96
+ */
97
+ verify<T = Record<string, unknown>>(signed: SignedPayload<T>): Promise<VerificationResult<T>>;
98
+ }
99
+ //# sourceMappingURL=agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEnE,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGpE;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,iBAAiB;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,wBAAwB;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,qBAAa,KAAK;IAChB,4BAA4B;IAC5B,SAAgB,QAAQ,EAAE,WAAW,CAAC;IAEtC,kCAAkC;IAClC,SAAgB,EAAE,EAAE,MAAM,CAAC;IAE3B,iBAAiB;IACjB,SAAgB,IAAI,EAAE,MAAM,CAAC;IAE7B,wBAAwB;IACxB,SAAgB,WAAW,EAAE,MAAM,CAAC;IAEpC;;;;;OAKG;gBACS,QAAQ,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW;IAOlE;;;OAGG;IACH,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED;;;OAGG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;;;;OAKG;IACH,IAAI,QAAQ,qDAEX;IAED;;;OAGG;IACH,gBAAgB,IAAI,OAAO;IAI3B;;;OAGG;IACH,IAAI,UAAU,IAAI,MAAM,GAAG,SAAS,CAInC;IAED;;;;OAIG;IACH,WAAW,IAAI,eAAe,EAAE;IAIhC;;;;;OAKG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAIrD;;;;OAIG;IACH,cAAc,IAAI,MAAM,GAAG,SAAS;IAQpC;;;;OAIG;IACG,IAAI,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IASpF;;;;OAIG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAI7D;;;;OAIG;IACG,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;CAoBpG"}
package/dist/agent.js ADDED
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Agent
3
+ * An autonomous entity that has a DID identity (injected, not inherited)
4
+ * @module agent
5
+ */
6
+ import { createJWT, createJWS, verifyJWT } from 'did-jwt';
7
+ import { getResolver } from './did/resolver.js';
8
+ import { A2A_AGENT_CARD_SERVICE_TYPE } from './a2a/constants.js';
9
+ /**
10
+ * Agent - an autonomous entity with DID identity
11
+ *
12
+ * DID identity is injected, not inherited.
13
+ * Agent can use any DID method (did:web, did:ethr)
14
+ */
15
+ export class Agent {
16
+ /** Injected DID identity */
17
+ identity;
18
+ /** Agent ID (short identifier) */
19
+ id;
20
+ /** Agent name */
21
+ name;
22
+ /** Agent description */
23
+ description;
24
+ /**
25
+ * Create an Agent with injected DID identity
26
+ * @param identity - DID identity from any provider (did:web, did:ethr)
27
+ * @param id - Short identifier for the agent
28
+ * @param config - Agent configuration (name, description)
29
+ */
30
+ constructor(identity, id, config) {
31
+ this.identity = identity;
32
+ this.id = id;
33
+ this.name = config.name;
34
+ this.description = config.description ?? '';
35
+ }
36
+ /**
37
+ * Agent's DID
38
+ * @returns The DID string (e.g., "did:web:example.com:agents:bot-1")
39
+ */
40
+ get did() {
41
+ return this.identity.did;
42
+ }
43
+ /**
44
+ * Key ID for signing
45
+ * @returns The key ID used in JWS/JWT (e.g., "did:web:example.com:agents:bot-1#key-1")
46
+ */
47
+ get keyId() {
48
+ return this.identity.keyId;
49
+ }
50
+ /**
51
+ * DID Document (if available locally)
52
+ * - did:web: Available (locally generated)
53
+ * - did:ethr: undefined (use resolveDID() to get from chain)
54
+ * @returns The W3C DID Document or undefined
55
+ */
56
+ get document() {
57
+ return this.identity.document;
58
+ }
59
+ /**
60
+ * Check if local DID Document is available
61
+ * @returns true if document is available locally
62
+ */
63
+ hasLocalDocument() {
64
+ return this.identity.document !== undefined;
65
+ }
66
+ /**
67
+ * Controller DID (if set in local document)
68
+ * @returns The DID of the controller (typically a Human), or undefined
69
+ */
70
+ get controller() {
71
+ const ctrl = this.identity.document?.controller;
72
+ if (!ctrl)
73
+ return undefined;
74
+ return Array.isArray(ctrl) ? ctrl[0] : ctrl;
75
+ }
76
+ /**
77
+ * Get all service endpoints from local DID Document
78
+ * For did:ethr, use resolveDID() instead to get on-chain services
79
+ * @returns Array of service endpoints (empty if no local document)
80
+ */
81
+ getServices() {
82
+ return this.identity.document?.service ?? [];
83
+ }
84
+ /**
85
+ * Get a specific service by type from local DID Document
86
+ * For did:ethr, use resolveDID() instead to get on-chain services
87
+ * @param type - The service type to find (e.g., "A2AAgent")
88
+ * @returns The service endpoint if found, undefined otherwise
89
+ */
90
+ getService(type) {
91
+ return this.identity.document?.service?.find(s => s.type === type);
92
+ }
93
+ /**
94
+ * Get A2A Agent Card URL from local DID Document
95
+ * For did:ethr, use resolveDID() instead to get on-chain Agent Card URL
96
+ * @returns The Agent Card URL if configured, undefined otherwise
97
+ */
98
+ getA2AEndpoint() {
99
+ const service = this.getService(A2A_AGENT_CARD_SERVICE_TYPE);
100
+ if (!service)
101
+ return undefined;
102
+ return typeof service.serviceEndpoint === 'string'
103
+ ? service.serviceEndpoint
104
+ : undefined;
105
+ }
106
+ /**
107
+ * Sign a payload as JWT
108
+ * @param payload - The payload to sign
109
+ * @returns Signed payload containing the JWT and original payload
110
+ */
111
+ async sign(payload) {
112
+ const jwt = await createJWT(payload, { issuer: this.did, signer: this.identity.signer }, { alg: 'ES256K', kid: this.keyId });
113
+ return { jws: jwt, payload };
114
+ }
115
+ /**
116
+ * Sign data directly as JWS (no iss/iat claims)
117
+ * @param data - The data to sign
118
+ * @returns The compact JWS string
119
+ */
120
+ async signJWS(data) {
121
+ return createJWS(data, this.identity.signer, { alg: 'ES256K', kid: this.keyId });
122
+ }
123
+ /**
124
+ * Verify a signed payload
125
+ * @param signed - The signed payload to verify
126
+ * @returns Verification result with issuer and payload if successful
127
+ */
128
+ async verify(signed) {
129
+ try {
130
+ const verified = await verifyJWT(signed.jws, {
131
+ resolver: getResolver(),
132
+ });
133
+ return {
134
+ verified: true,
135
+ issuer: verified.issuer,
136
+ payload: verified.payload,
137
+ };
138
+ }
139
+ catch (error) {
140
+ return {
141
+ verified: false,
142
+ issuer: '',
143
+ payload: null,
144
+ error: error instanceof Error ? error.message : 'Unknown error',
145
+ };
146
+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AAQ,CAAC,MAAM,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;IACnF,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,MAAM,CAA8B,MAAwB;QAChE,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE;gBAC3C,QAAQ,EAAE,WAAW,EAAE;aACxB,CAAC,CAAC;YAEH,OAAO;gBACL,QAAQ,EAAE,IAAI;gBACd,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,OAAO,EAAE,QAAQ,CAAC,OAAuB;aAC1C,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,QAAQ,EAAE,KAAK;gBACf,MAAM,EAAE,EAAE;gBACV,OAAO,EAAE,IAAI;gBACb,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe;aAChE,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * DID Method Configuration Types
3
+ * Type-safe configuration for different DID methods
4
+ */
5
+ /**
6
+ * Configuration for did:web method
7
+ */
8
+ export interface WebDIDConfig {
9
+ /** DID method identifier */
10
+ type: 'web';
11
+ /** Domain name (e.g., "example.com") */
12
+ domain: string;
13
+ /** Port number (e.g., 3000) */
14
+ port: number;
15
+ /** Optional controller DID */
16
+ controller?: string;
17
+ }
18
+ /**
19
+ * Configuration for did:ethr method
20
+ */
21
+ export interface EthrDIDConfig {
22
+ /** DID method identifier */
23
+ type: 'ethr';
24
+ /** Network name (e.g., "sepolia", "mainnet") */
25
+ network: string;
26
+ /** JSON-RPC endpoint URL */
27
+ rpcUrl: string;
28
+ /** Optional chain ID (auto-detected from network if not provided) */
29
+ chainId?: number;
30
+ /** Optional registry contract address (uses default if not provided) */
31
+ registry?: string;
32
+ }
33
+ /**
34
+ * Union type for all DID method configurations
35
+ */
36
+ export type DIDConfig = WebDIDConfig | EthrDIDConfig;
37
+ //# sourceMappingURL=config-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-types.d.ts","sourceRoot":"","sources":["../../src/did/config-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,4BAA4B;IAC5B,IAAI,EAAE,KAAK,CAAC;IACZ,wCAAwC;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,+BAA+B;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,8BAA8B;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,OAAO,EAAE,MAAM,CAAC;IAChB,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wEAAwE;IACxE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,YAAY,GAAG,aAAa,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * DID Method Configuration Types
3
+ * Type-safe configuration for different DID methods
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=config-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-types.js","sourceRoot":"","sources":["../../src/did/config-types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * DID Document builder functions with dynamic handler loading
3
+ * @module did/document
4
+ */
5
+ import type { DIDIdentity, DIDDocument, ServiceEndpoint } from './types.js';
6
+ /**
7
+ * Build DID Document for a given identity
8
+ * Dynamically loads the appropriate DID method handler
9
+ *
10
+ * Note: Only supports did:web. For did:ethr, documents are resolved from on-chain.
11
+ *
12
+ * @param identity - The DID identity
13
+ * @param options - Optional services to include in the document
14
+ * @returns The DID Document
15
+ * @throws {Error} When DID method is not 'web'
16
+ */
17
+ export declare function buildDocumentForIdentity(identity: DIDIdentity, options?: {
18
+ services?: ServiceEndpoint[];
19
+ }): Promise<DIDDocument>;
20
+ //# sourceMappingURL=document.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../src/did/document.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE5E;;;;;;;;;;GAUG;AACH,wBAAsB,wBAAwB,CAC5C,QAAQ,EAAE,WAAW,EACrB,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,eAAe,EAAE,CAAA;CAAE,GACzC,OAAO,CAAC,WAAW,CAAC,CAUtB"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Build DID Document for a given identity
3
+ * Dynamically loads the appropriate DID method handler
4
+ *
5
+ * Note: Only supports did:web. For did:ethr, documents are resolved from on-chain.
6
+ *
7
+ * @param identity - The DID identity
8
+ * @param options - Optional services to include in the document
9
+ * @returns The DID Document
10
+ * @throws {Error} When DID method is not 'web'
11
+ */
12
+ export async function buildDocumentForIdentity(identity, options) {
13
+ const method = identity.did.split(':')[1]; // 'did:web:...' → 'web'
14
+ if (method === 'web') {
15
+ const { DIDWebMethodHandler } = await import('./handlers/web-handler.js');
16
+ const handler = new DIDWebMethodHandler();
17
+ return handler.buildDocumentForIdentity(identity, options);
18
+ }
19
+ throw new Error(`buildDocumentForIdentity only supports did:web. For did:ethr, use DID resolver instead.`);
20
+ }
21
+ //# sourceMappingURL=document.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.js","sourceRoot":"","sources":["../../src/did/document.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,QAAqB,EACrB,OAA0C;IAE1C,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,wBAAwB;IAEnE,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;QACrB,MAAM,EAAE,mBAAmB,EAAE,GAAG,MAAM,MAAM,CAAC,2BAA2B,CAAC,CAAC;QAC1E,MAAM,OAAO,GAAG,IAAI,mBAAmB,EAAE,CAAC;QAC1C,OAAO,OAAO,CAAC,wBAAwB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC7D,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,yFAAyF,CAAC,CAAC;AAC7G,CAAC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Agent DID Service Factory
3
+ * Provides convenience functions for creating pre-configured AgentDIDService instances
4
+ */
5
+ import { AgentDIDService } from './service.js';
6
+ /**
7
+ * Supported DID methods for factory creation
8
+ */
9
+ export type DIDMethod = 'web' | 'ethr';
10
+ /**
11
+ * Create an AgentDIDService with specified methods
12
+ * Uses dynamic imports for tree-shaking - only requested methods are bundled
13
+ *
14
+ * @param methods - Array of DID methods to enable (default: ['web'])
15
+ * @returns Configured AgentDIDService instance
16
+ *
17
+ * @example
18
+ * // did:web only (no ethers dependency)
19
+ * const service = await createAgentDIDService(['web']);
20
+ *
21
+ * @example
22
+ * // did:web + did:ethr (includes ethers)
23
+ * const service = await createAgentDIDService(['web', 'ethr']);
24
+ */
25
+ export declare function createAgentDIDService(methods?: DIDMethod[]): Promise<AgentDIDService>;
26
+ /**
27
+ * Get all supported DID method names
28
+ * @returns Array of supported method names
29
+ */
30
+ export declare function getSupportedDIDMethods(): DIDMethod[];
31
+ //# sourceMappingURL=factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/did/factory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,MAAM,CAAC;AAEvC;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,qBAAqB,CAAC,OAAO,GAAE,SAAS,EAAY,GAAG,OAAO,CAAC,eAAe,CAAC,CAiBpG;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,SAAS,EAAE,CAEpD"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Agent DID Service Factory
3
+ * Provides convenience functions for creating pre-configured AgentDIDService instances
4
+ */
5
+ import { AgentDIDService } from './service.js';
6
+ /**
7
+ * Create an AgentDIDService with specified methods
8
+ * Uses dynamic imports for tree-shaking - only requested methods are bundled
9
+ *
10
+ * @param methods - Array of DID methods to enable (default: ['web'])
11
+ * @returns Configured AgentDIDService instance
12
+ *
13
+ * @example
14
+ * // did:web only (no ethers dependency)
15
+ * const service = await createAgentDIDService(['web']);
16
+ *
17
+ * @example
18
+ * // did:web + did:ethr (includes ethers)
19
+ * const service = await createAgentDIDService(['web', 'ethr']);
20
+ */
21
+ export async function createAgentDIDService(methods = ['web']) {
22
+ const service = new AgentDIDService();
23
+ for (const method of methods) {
24
+ if (method === 'web') {
25
+ const { DIDWebMethodHandler } = await import('./handlers/web-handler.js');
26
+ service.registerMethod('web', new DIDWebMethodHandler());
27
+ }
28
+ else if (method === 'ethr') {
29
+ const { DIDEthrMethodHandler } = await import('./handlers/ethr-handler.js');
30
+ service.registerMethod('ethr', new DIDEthrMethodHandler());
31
+ }
32
+ else {
33
+ // Type guard ensures this never happens with proper typing
34
+ throw new Error(`Unsupported DID method: ${method}`);
35
+ }
36
+ }
37
+ return service;
38
+ }
39
+ /**
40
+ * Get all supported DID method names
41
+ * @returns Array of supported method names
42
+ */
43
+ export function getSupportedDIDMethods() {
44
+ return ['web', 'ethr'];
45
+ }
46
+ //# sourceMappingURL=factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/did/factory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAO/C;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,UAAuB,CAAC,KAAK,CAAC;IACxE,MAAM,OAAO,GAAG,IAAI,eAAe,EAAE,CAAC;IAEtC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;YACrB,MAAM,EAAE,mBAAmB,EAAE,GAAG,MAAM,MAAM,CAAC,2BAA2B,CAAC,CAAC;YAC1E,OAAO,CAAC,cAAc,CAAC,KAAK,EAAE,IAAI,mBAAmB,EAAE,CAAC,CAAC;QAC3D,CAAC;aAAM,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;YAC7B,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,MAAM,CAAC,4BAA4B,CAAC,CAAC;YAC5E,OAAO,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,oBAAoB,EAAE,CAAC,CAAC;QAC7D,CAAC;aAAM,CAAC;YACN,2DAA2D;YAC3D,MAAM,IAAI,KAAK,CAAC,2BAA2B,MAAM,EAAE,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB;IACpC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AACzB,CAAC"}