@peac/adapter-did 0.12.6
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 +190 -0
- package/README.md +71 -0
- package/dist/cache.d.ts +48 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/did-key.d.ts +31 -0
- package/dist/did-key.d.ts.map +1 -0
- package/dist/did-key.js +97 -0
- package/dist/did-key.js.map +1 -0
- package/dist/did-web.d.ts +73 -0
- package/dist/did-web.d.ts.map +1 -0
- package/dist/errors.d.ts +15 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +21 -0
- package/dist/errors.js.map +1 -0
- package/dist/extract-key.d.ts +44 -0
- package/dist/extract-key.d.ts.map +1 -0
- package/dist/extract-key.js +131 -0
- package/dist/extract-key.js.map +1 -0
- package/dist/index.cjs +461 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +453 -0
- package/dist/index.mjs.map +1 -0
- package/dist/multicodec.d.ts +24 -0
- package/dist/multicodec.d.ts.map +1 -0
- package/dist/multicodec.js +121 -0
- package/dist/multicodec.js.map +1 -0
- package/dist/resolver.d.ts +30 -0
- package/dist/resolver.d.ts.map +1 -0
- package/dist/resolver.js +58 -0
- package/dist/resolver.js.map +1 -0
- package/dist/types.d.ts +82 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +13 -0
- package/dist/types.js.map +1 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2025-2026 PEAC Protocol Contributors
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# @peac/adapter-did
|
|
2
|
+
|
|
3
|
+
DID document resolution for PEAC receipt verification. Supports did:key with zero network I/O.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @peac/adapter-did
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## What It Does
|
|
12
|
+
|
|
13
|
+
`@peac/adapter-did` is a Layer 4 adapter that resolves W3C Decentralized Identifiers (DIDs) to Ed25519 public keys for use with `verifyLocal()`. It implements the DID Verification Method Selection Policy (DD-202) for deterministic key extraction.
|
|
14
|
+
|
|
15
|
+
Supports `did:key` (Ed25519, zero network I/O) and `did:web` (caller-provided SSRF-hardened HTTPS fetch). Includes TTL-based caching and composite resolver for multi-method support.
|
|
16
|
+
|
|
17
|
+
## How Do I Use It?
|
|
18
|
+
|
|
19
|
+
### Resolve a did:key and extract the public key
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { DidKeyResolver, extractVerificationKey } from '@peac/adapter-did';
|
|
23
|
+
import { verifyLocal } from '@peac/protocol';
|
|
24
|
+
|
|
25
|
+
const resolver = new DidKeyResolver();
|
|
26
|
+
const result = await resolver.resolve('did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK');
|
|
27
|
+
const publicKey = extractVerificationKey(result.didDocument!);
|
|
28
|
+
|
|
29
|
+
const verification = await verifyLocal(receiptJws, publicKey!, {
|
|
30
|
+
strictness: 'strict',
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Use a composite resolver for multiple DID methods
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { createCompositeResolver, DidKeyResolver } from '@peac/adapter-did';
|
|
38
|
+
|
|
39
|
+
const resolver = createCompositeResolver([
|
|
40
|
+
new DidKeyResolver(),
|
|
41
|
+
// add DidWebResolver here when available
|
|
42
|
+
]);
|
|
43
|
+
|
|
44
|
+
const result = await resolver.resolve('did:key:z6Mk...');
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Integrates With
|
|
48
|
+
|
|
49
|
+
- `@peac/kernel` (Layer 0): Error codes (E*DID*\*) and types
|
|
50
|
+
- `@peac/schema` (Layer 1): Schema validation
|
|
51
|
+
- `@peac/protocol` (Layer 3): `verifyLocal()` accepts the extracted public key directly
|
|
52
|
+
|
|
53
|
+
## Supported Key Types
|
|
54
|
+
|
|
55
|
+
Only Ed25519 keys are extracted. Other key types are silently skipped to prevent key-type oracle attacks. Both multibase encodings from the did:key spec are supported: `z` (base58btc) and `u` (base64url).
|
|
56
|
+
|
|
57
|
+
## Standards
|
|
58
|
+
|
|
59
|
+
- W3C DID Core v1.0 (Recommendation 2022): baseline type model
|
|
60
|
+
- did:key (W3C CCG v0.9): method-specific resolution as interoperability adapter
|
|
61
|
+
- did:web (W3C CCG draft): HTTPS resolution as interoperability adapter, not a normative dependency
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
Apache-2.0
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
PEAC Protocol is an open source project stewarded by Originary and community contributors.
|
|
70
|
+
|
|
71
|
+
[Docs](https://www.peacprotocol.org) | [GitHub](https://github.com/peacprotocol/peac) | [Originary](https://www.originary.xyz)
|
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Caching resolver wrapper.
|
|
3
|
+
*
|
|
4
|
+
* Wraps any DIDResolver with TTL-based in-memory caching.
|
|
5
|
+
* Cache entries expire after configurable TTL and are evicted
|
|
6
|
+
* when maxEntries is reached (oldest-first).
|
|
7
|
+
*
|
|
8
|
+
* The cache key is the full DID string.
|
|
9
|
+
*/
|
|
10
|
+
import type { DIDResolutionResult } from './types.js';
|
|
11
|
+
import type { DIDResolver } from './resolver.js';
|
|
12
|
+
export interface CachingResolverOptions {
|
|
13
|
+
/** Time-to-live in milliseconds (default: 300000 = 5 minutes) */
|
|
14
|
+
ttlMs?: number;
|
|
15
|
+
/** Maximum number of cached entries (default: 1000) */
|
|
16
|
+
maxEntries?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Caching wrapper for any DIDResolver.
|
|
20
|
+
*
|
|
21
|
+
* - TTL-based expiry: entries older than ttlMs are evicted on access
|
|
22
|
+
* - Max entries: oldest entries evicted when capacity is reached
|
|
23
|
+
* - Only successful resolutions are cached (didDocument !== null)
|
|
24
|
+
* - Failed resolutions are NOT cached (each attempt is fresh)
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const inner = new DidKeyResolver();
|
|
29
|
+
* const cached = new CachingResolver(inner, { ttlMs: 60000 });
|
|
30
|
+
* const result = await cached.resolve('did:key:z6Mk...');
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare class CachingResolver implements DIDResolver {
|
|
34
|
+
readonly methods: readonly string[];
|
|
35
|
+
private readonly inner;
|
|
36
|
+
private readonly ttlMs;
|
|
37
|
+
private readonly maxEntries;
|
|
38
|
+
private readonly cache;
|
|
39
|
+
constructor(inner: DIDResolver, options?: CachingResolverOptions);
|
|
40
|
+
resolve(did: string): Promise<DIDResolutionResult>;
|
|
41
|
+
/** Invalidate a specific cached entry */
|
|
42
|
+
invalidate(did: string): void;
|
|
43
|
+
/** Clear the entire cache */
|
|
44
|
+
clear(): void;
|
|
45
|
+
/** Current number of cached entries */
|
|
46
|
+
get size(): number;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAMjD,MAAM,WAAW,sBAAsB;IACrC,iEAAiE;IACjE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uDAAuD;IACvD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAkBD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,eAAgB,YAAW,WAAW;IACjD,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAEpC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAc;IACpC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiC;gBAE3C,KAAK,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,sBAAsB;IAO1D,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAoCxD,yCAAyC;IACzC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAI7B,6BAA6B;IAC7B,KAAK,IAAI,IAAI;IAIb,uCAAuC;IACvC,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* did:key resolver (Ed25519, zero network I/O).
|
|
3
|
+
*
|
|
4
|
+
* Implements the did:key method spec (W3C CCG v0.9).
|
|
5
|
+
* Parses the multicodec-encoded Ed25519 public key directly from
|
|
6
|
+
* the DID string. No network requests, no ambient discovery.
|
|
7
|
+
*
|
|
8
|
+
* Only Ed25519 keys (multicodec 0xed01) are supported.
|
|
9
|
+
* Non-Ed25519 did:key DIDs produce an error without revealing
|
|
10
|
+
* the actual key type (no oracle).
|
|
11
|
+
*/
|
|
12
|
+
import type { DIDResolutionResult } from './types.js';
|
|
13
|
+
import type { DIDResolver } from './resolver.js';
|
|
14
|
+
/**
|
|
15
|
+
* Resolver for the did:key method.
|
|
16
|
+
*
|
|
17
|
+
* did:key encodes the public key directly in the DID string.
|
|
18
|
+
* Resolution is pure computation with zero network I/O.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const resolver = new DidKeyResolver();
|
|
23
|
+
* const result = await resolver.resolve('did:key:z6MkhaXgBZDvotDkL...');
|
|
24
|
+
* const key = extractVerificationKey(result.didDocument!);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare class DidKeyResolver implements DIDResolver {
|
|
28
|
+
readonly methods: readonly ["key"];
|
|
29
|
+
resolve(did: string): Promise<DIDResolutionResult>;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=did-key.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"did-key.d.ts","sourceRoot":"","sources":["../src/did-key.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAQjD;;;;;;;;;;;;GAYG;AACH,qBAAa,cAAe,YAAW,WAAW;IAChD,QAAQ,CAAC,OAAO,mBAAoB;IAE9B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAoEzD"}
|
package/dist/did-key.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* did:key resolver (Ed25519, zero network I/O).
|
|
4
|
+
*
|
|
5
|
+
* Implements the did:key method spec (W3C CCG v0.9).
|
|
6
|
+
* Parses the multicodec-encoded Ed25519 public key directly from
|
|
7
|
+
* the DID string. No network requests, no ambient discovery.
|
|
8
|
+
*
|
|
9
|
+
* Only Ed25519 keys (multicodec 0xed01) are supported.
|
|
10
|
+
* Non-Ed25519 did:key DIDs produce an error without revealing
|
|
11
|
+
* the actual key type (no oracle).
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.DidKeyResolver = void 0;
|
|
15
|
+
const multicodec_js_1 = require("./multicodec.js");
|
|
16
|
+
const errors_js_1 = require("./errors.js");
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// did:key Resolver
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
/**
|
|
21
|
+
* Resolver for the did:key method.
|
|
22
|
+
*
|
|
23
|
+
* did:key encodes the public key directly in the DID string.
|
|
24
|
+
* Resolution is pure computation with zero network I/O.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const resolver = new DidKeyResolver();
|
|
29
|
+
* const result = await resolver.resolve('did:key:z6MkhaXgBZDvotDkL...');
|
|
30
|
+
* const key = extractVerificationKey(result.didDocument!);
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
class DidKeyResolver {
|
|
34
|
+
methods = ['key'];
|
|
35
|
+
async resolve(did) {
|
|
36
|
+
// Validate DID format
|
|
37
|
+
if (!did.startsWith('did:key:')) {
|
|
38
|
+
return {
|
|
39
|
+
didDocument: null,
|
|
40
|
+
didResolutionMetadata: { error: 'invalidDid' },
|
|
41
|
+
didDocumentMetadata: {},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const multibaseValue = did.slice('did:key:'.length);
|
|
45
|
+
if (!multibaseValue) {
|
|
46
|
+
return {
|
|
47
|
+
didDocument: null,
|
|
48
|
+
didResolutionMetadata: { error: 'invalidDid' },
|
|
49
|
+
didDocumentMetadata: {},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
// Extract Ed25519 public key (validates multicodec prefix)
|
|
53
|
+
let publicKeyBytes;
|
|
54
|
+
try {
|
|
55
|
+
publicKeyBytes = (0, multicodec_js_1.extractEd25519FromMultibase)(multibaseValue);
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
if (e instanceof errors_js_1.DIDError) {
|
|
59
|
+
return {
|
|
60
|
+
didDocument: null,
|
|
61
|
+
didResolutionMetadata: { error: e.code },
|
|
62
|
+
didDocumentMetadata: {},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
didDocument: null,
|
|
67
|
+
didResolutionMetadata: { error: 'invalidDid' },
|
|
68
|
+
didDocumentMetadata: {},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
// Build DID Document with the extracted key
|
|
72
|
+
const keyId = `${did}#${multibaseValue}`;
|
|
73
|
+
const verificationMethod = {
|
|
74
|
+
id: keyId,
|
|
75
|
+
type: 'Ed25519VerificationKey2020',
|
|
76
|
+
controller: did,
|
|
77
|
+
publicKeyMultibase: multibaseValue,
|
|
78
|
+
};
|
|
79
|
+
const document = {
|
|
80
|
+
'@context': [
|
|
81
|
+
'https://www.w3.org/ns/did/v1',
|
|
82
|
+
'https://w3id.org/security/suites/ed25519-2020/v1',
|
|
83
|
+
],
|
|
84
|
+
id: did,
|
|
85
|
+
verificationMethod: [verificationMethod],
|
|
86
|
+
authentication: [keyId],
|
|
87
|
+
assertionMethod: [keyId],
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
didDocument: document,
|
|
91
|
+
didResolutionMetadata: { contentType: 'application/did+json' },
|
|
92
|
+
didDocumentMetadata: {},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.DidKeyResolver = DidKeyResolver;
|
|
97
|
+
//# sourceMappingURL=did-key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"did-key.js","sourceRoot":"","sources":["../src/did-key.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAKH,mDAA8D;AAC9D,2CAAuC;AAEvC,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E;;;;;;;;;;;;GAYG;AACH,MAAa,cAAc;IAChB,OAAO,GAAG,CAAC,KAAK,CAAU,CAAC;IAEpC,KAAK,CAAC,OAAO,CAAC,GAAW;QACvB,sBAAsB;QACtB,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAChC,OAAO;gBACL,WAAW,EAAE,IAAI;gBACjB,qBAAqB,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE;gBAC9C,mBAAmB,EAAE,EAAE;aACxB,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AW,EAAE,QAAQ;YACrB,qBAAqB,EAAE,EAAE,WAAW,EAAE,sBAAsB,EAAE;YAC9D,mBAAmB,EAAE,EAAE;SACxB,CAAC;IACJ,CAAC;CACF;AApED,wCAoEC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* did:web resolver using a caller-provided SSRF-hardened fetch.
|
|
3
|
+
*
|
|
4
|
+
* Implements the did:web method spec (W3C CCG draft).
|
|
5
|
+
* Resolves did:web DIDs to DID Documents via HTTPS fetch.
|
|
6
|
+
*
|
|
7
|
+
* Callers MUST provide a hardened fetch function (e.g., safeFetchJson
|
|
8
|
+
* from @peac/net-node) that enforces:
|
|
9
|
+
* - HTTPS only
|
|
10
|
+
* - No redirects
|
|
11
|
+
* - Private-IP / DNS-rebinding protections
|
|
12
|
+
* - Timeout
|
|
13
|
+
* - Response size limit
|
|
14
|
+
*
|
|
15
|
+
* This resolver adds:
|
|
16
|
+
* - did:web authority/path validation (no userinfo, no query/fragment,
|
|
17
|
+
* no empty segments, no IP literals)
|
|
18
|
+
* - Content-type enforcement (application/did+json or application/json)
|
|
19
|
+
* - Exact DID Document id match (DD-203)
|
|
20
|
+
* - Domain allowlist (optional)
|
|
21
|
+
*
|
|
22
|
+
* URL transformation rules:
|
|
23
|
+
* - did:web:example.com -> https://example.com/.well-known/did.json
|
|
24
|
+
* - did:web:example.com:path:to -> https://example.com/path/to/did.json
|
|
25
|
+
* - did:web:example.com%3A8443 -> https://example.com:8443/.well-known/did.json
|
|
26
|
+
*/
|
|
27
|
+
import type { DIDResolutionResult } from './types.js';
|
|
28
|
+
import type { DIDResolver } from './resolver.js';
|
|
29
|
+
/**
|
|
30
|
+
* Result shape for the caller-provided hardened fetch function.
|
|
31
|
+
*
|
|
32
|
+
* Callers should use safeFetchJson from @peac/net-node, which returns
|
|
33
|
+
* this shape. The resolver uses contentType and finalUrl for additional
|
|
34
|
+
* validation beyond what the fetch function itself enforces.
|
|
35
|
+
*/
|
|
36
|
+
export interface HardenedFetchResult<T = unknown> {
|
|
37
|
+
ok: boolean;
|
|
38
|
+
data?: T;
|
|
39
|
+
code?: string;
|
|
40
|
+
error?: string;
|
|
41
|
+
/** Content-Type of the response (for validation) */
|
|
42
|
+
contentType?: string;
|
|
43
|
+
/** Final URL after any processing (for redirect detection) */
|
|
44
|
+
finalUrl?: string;
|
|
45
|
+
}
|
|
46
|
+
export type HardenedFetchFn = <T = unknown>(url: string, options?: {
|
|
47
|
+
timeoutMs?: number;
|
|
48
|
+
maxResponseBytes?: number;
|
|
49
|
+
maxRedirects?: number;
|
|
50
|
+
}) => Promise<HardenedFetchResult<T>>;
|
|
51
|
+
export interface DidWebResolverOptions {
|
|
52
|
+
/** Request timeout in milliseconds (default: 5000) */
|
|
53
|
+
timeoutMs?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Optional domain allowlist (lowercase). If set, only these domains
|
|
56
|
+
* are permitted. Comparison is case-insensitive.
|
|
57
|
+
*/
|
|
58
|
+
allowedDomains?: string[];
|
|
59
|
+
/**
|
|
60
|
+
* SSRF-hardened fetch function. Required.
|
|
61
|
+
* Use safeFetchJson from @peac/net-node for production.
|
|
62
|
+
*/
|
|
63
|
+
fetchFn: HardenedFetchFn;
|
|
64
|
+
}
|
|
65
|
+
export declare class DidWebResolver implements DIDResolver {
|
|
66
|
+
readonly methods: readonly ["web"];
|
|
67
|
+
private readonly timeoutMs;
|
|
68
|
+
private readonly allowedDomains;
|
|
69
|
+
private readonly fetchFn;
|
|
70
|
+
constructor(options: DidWebResolverOptions);
|
|
71
|
+
resolve(did: string): Promise<DIDResolutionResult>;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=did-web.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"did-web.d.ts","sourceRoot":"","sources":["../src/did-web.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,OAAO,KAAK,EAAE,mBAAmB,EAA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
* DID adapter error types.
|
|
3
|
+
*
|
|
4
|
+
* Uses error codes registered in specs/kernel/errors.json (PR3 #571).
|
|
5
|
+
*/
|
|
6
|
+
/** DID-specific error codes (registered in kernel) */
|
|
7
|
+
export type DIDErrorCode = 'E_DID_RESOLUTION_FAILED' | 'E_DID_DOCUMENT_INVALID' | 'E_DID_KEY_NOT_FOUND' | 'E_DID_UNSUPPORTED_METHOD' | 'E_DID_DEACTIVATED' | 'E_DID_KEY_AMBIGUOUS';
|
|
8
|
+
/**
|
|
9
|
+
* Error thrown by DID adapter operations.
|
|
10
|
+
*/
|
|
11
|
+
export declare class DIDError extends Error {
|
|
12
|
+
readonly code: DIDErrorCode;
|
|
13
|
+
constructor(code: DIDErrorCode, message: string);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,sDAAsD;AACtD,MAAM,MAAM,YAAY,GACpB,yBAAyB,GACzB,wBAAwB,GACxB,qBAAqB,GACrB,0BAA0B,GAC1B,mBAAmB,GACnB,qBAAqB,CAAC;AAE1B;;GAEG;AACH,qBAAa,QAAS,SAAQ,KAAK;IACjC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;gBAEhB,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM;CAKhD"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* DID adapter error types.
|
|
4
|
+
*
|
|
5
|
+
* Uses error codes registered in specs/kernel/errors.json (PR3 #571).
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.DIDError = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* Error thrown by DID adapter operations.
|
|
11
|
+
*/
|
|
12
|
+
class DIDError extends Error {
|
|
13
|
+
code;
|
|
14
|
+
constructor(code, message) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = 'DIDError';
|
|
17
|
+
this.code = code;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.DIDError = DIDError;
|
|
21
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAWH;;GAEG;AACH,MAAa,QAAS,SAAQ,KAAK;IACxB,IAAI,CAAe;IAE5B,YAAY,IAAkB,EAAE,OAAe;QAC7C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AARD,4BAQC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verification key extraction from DID Documents.
|
|
3
|
+
*
|
|
4
|
+
* Implements DD-202 (DID Verification Method Selection Policy):
|
|
5
|
+
* 1. Prefer methods referenced in authentication/assertionMethod
|
|
6
|
+
* 2. If multiple eligible Ed25519 methods remain, require caller keyId
|
|
7
|
+
* or fail with E_DID_KEY_AMBIGUOUS
|
|
8
|
+
* 3. Only Ed25519 keys extracted; other types silently skipped
|
|
9
|
+
* 4. Iterates ALL methods regardless of match (no early-return oracle)
|
|
10
|
+
*/
|
|
11
|
+
import type { DIDDocument } from './types.js';
|
|
12
|
+
export interface ExtractKeyOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Explicit key ID to select.
|
|
15
|
+
* If provided, only methods with this ID are considered.
|
|
16
|
+
*/
|
|
17
|
+
keyId?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Which verification relationship to prefer.
|
|
20
|
+
* Default: 'authentication'
|
|
21
|
+
*/
|
|
22
|
+
relationship?: 'authentication' | 'assertionMethod';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Extract an Ed25519 public key from a DID Document.
|
|
26
|
+
*
|
|
27
|
+
* Selection policy (DD-202):
|
|
28
|
+
* 1. Collect all verification methods from the document
|
|
29
|
+
* 2. Filter by keyId if provided
|
|
30
|
+
* 3. Filter by relationship references (authentication/assertionMethod)
|
|
31
|
+
* 4. Try to extract Ed25519 key from each eligible method
|
|
32
|
+
* 5. If exactly one Ed25519 key found: return it
|
|
33
|
+
* 6. If zero found: return null
|
|
34
|
+
* 7. If multiple found without keyId: throw E_DID_KEY_AMBIGUOUS
|
|
35
|
+
*
|
|
36
|
+
* All methods are iterated regardless of match to prevent key-type oracle.
|
|
37
|
+
*
|
|
38
|
+
* @param document - The resolved DID Document
|
|
39
|
+
* @param options - Key selection options
|
|
40
|
+
* @returns 32-byte Ed25519 public key, or null if no suitable key found
|
|
41
|
+
* @throws DIDError with E_DID_KEY_AMBIGUOUS if multiple eligible keys
|
|
42
|
+
*/
|
|
43
|
+
export declare function extractVerificationKey(document: DIDDocument, options?: ExtractKeyOptions): Uint8Array | null;
|
|
44
|
+
//# sourceMappingURL=extract-key.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-key.d.ts","sourceRoot":"","sources":["../src/extract-key.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAsB,MAAM,YAAY,CAAC;AAQlE,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,YAAY,CAAC,EAAE,gBAAgB,GAAG,iBAAiB,CAAC;CACrD;AAMD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,WAAW,EACrB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,UAAU,GAAG,IAAI,CAmDnB"}
|