@web_of_trust/core 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +357 -0
- package/dist/adapters/authorization/InMemoryAuthorizationAdapter.d.ts +30 -0
- package/dist/adapters/authorization/InMemoryAuthorizationAdapter.d.ts.map +1 -0
- package/dist/adapters/crypto/WebCryptoAdapter.d.ts +30 -0
- package/dist/adapters/crypto/WebCryptoAdapter.d.ts.map +1 -0
- package/dist/adapters/crypto/index.d.ts +2 -0
- package/dist/adapters/crypto/index.d.ts.map +1 -0
- package/dist/adapters/discovery/HttpDiscoveryAdapter.d.ts +25 -0
- package/dist/adapters/discovery/HttpDiscoveryAdapter.d.ts.map +1 -0
- package/dist/adapters/discovery/InMemoryGraphCacheStore.d.ts +29 -0
- package/dist/adapters/discovery/InMemoryGraphCacheStore.d.ts.map +1 -0
- package/dist/adapters/discovery/InMemoryPublishStateStore.d.ts +13 -0
- package/dist/adapters/discovery/InMemoryPublishStateStore.d.ts.map +1 -0
- package/dist/adapters/discovery/OfflineFirstDiscoveryAdapter.d.ts +62 -0
- package/dist/adapters/discovery/OfflineFirstDiscoveryAdapter.d.ts.map +1 -0
- package/dist/adapters/index.d.ts +5 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/interfaces/AuthorizationAdapter.d.ts +52 -0
- package/dist/adapters/interfaces/AuthorizationAdapter.d.ts.map +1 -0
- package/dist/adapters/interfaces/CryptoAdapter.d.ts +43 -0
- package/dist/adapters/interfaces/CryptoAdapter.d.ts.map +1 -0
- package/dist/adapters/interfaces/DiscoveryAdapter.d.ts +71 -0
- package/dist/adapters/interfaces/DiscoveryAdapter.d.ts.map +1 -0
- package/dist/adapters/interfaces/GraphCacheStore.d.ts +66 -0
- package/dist/adapters/interfaces/GraphCacheStore.d.ts.map +1 -0
- package/dist/adapters/interfaces/MessagingAdapter.d.ts +23 -0
- package/dist/adapters/interfaces/MessagingAdapter.d.ts.map +1 -0
- package/dist/adapters/interfaces/OutboxStore.d.ts +35 -0
- package/dist/adapters/interfaces/OutboxStore.d.ts.map +1 -0
- package/dist/adapters/interfaces/PublishStateStore.d.ts +23 -0
- package/dist/adapters/interfaces/PublishStateStore.d.ts.map +1 -0
- package/dist/adapters/interfaces/ReactiveStorageAdapter.d.ts +23 -0
- package/dist/adapters/interfaces/ReactiveStorageAdapter.d.ts.map +1 -0
- package/dist/adapters/interfaces/ReplicationAdapter.d.ts +57 -0
- package/dist/adapters/interfaces/ReplicationAdapter.d.ts.map +1 -0
- package/dist/adapters/interfaces/SpaceMetadataStorage.d.ts +46 -0
- package/dist/adapters/interfaces/SpaceMetadataStorage.d.ts.map +1 -0
- package/dist/adapters/interfaces/StorageAdapter.d.ts +32 -0
- package/dist/adapters/interfaces/StorageAdapter.d.ts.map +1 -0
- package/dist/adapters/interfaces/Subscribable.d.ts +22 -0
- package/dist/adapters/interfaces/Subscribable.d.ts.map +1 -0
- package/dist/adapters/interfaces/index.d.ts +12 -0
- package/dist/adapters/interfaces/index.d.ts.map +1 -0
- package/dist/adapters/messaging/AutomergeOutboxStore.d.ts +24 -0
- package/dist/adapters/messaging/AutomergeOutboxStore.d.ts.map +1 -0
- package/dist/adapters/messaging/InMemoryMessagingAdapter.d.ts +36 -0
- package/dist/adapters/messaging/InMemoryMessagingAdapter.d.ts.map +1 -0
- package/dist/adapters/messaging/InMemoryOutboxStore.d.ts +12 -0
- package/dist/adapters/messaging/InMemoryOutboxStore.d.ts.map +1 -0
- package/dist/adapters/messaging/OutboxMessagingAdapter.d.ts +61 -0
- package/dist/adapters/messaging/OutboxMessagingAdapter.d.ts.map +1 -0
- package/dist/adapters/messaging/TracedOutboxMessagingAdapter.d.ts +20 -0
- package/dist/adapters/messaging/TracedOutboxMessagingAdapter.d.ts.map +1 -0
- package/dist/adapters/messaging/WebSocketMessagingAdapter.d.ts +63 -0
- package/dist/adapters/messaging/WebSocketMessagingAdapter.d.ts.map +1 -0
- package/dist/adapters/messaging/index.d.ts +3 -0
- package/dist/adapters/messaging/index.d.ts.map +1 -0
- package/dist/adapters/storage/AutomergeSpaceMetadataStorage.d.ts +22 -0
- package/dist/adapters/storage/AutomergeSpaceMetadataStorage.d.ts.map +1 -0
- package/dist/adapters/storage/InMemoryCompactStore.d.ts +18 -0
- package/dist/adapters/storage/InMemoryCompactStore.d.ts.map +1 -0
- package/dist/adapters/storage/InMemorySpaceMetadataStorage.d.ts +17 -0
- package/dist/adapters/storage/InMemorySpaceMetadataStorage.d.ts.map +1 -0
- package/dist/adapters/storage/IndexedDBSpaceMetadataStorage.d.ts +15 -0
- package/dist/adapters/storage/IndexedDBSpaceMetadataStorage.d.ts.map +1 -0
- package/dist/adapters/storage/LocalStorageAdapter.d.ts +26 -0
- package/dist/adapters/storage/LocalStorageAdapter.d.ts.map +1 -0
- package/dist/adapters/storage/index.d.ts +2 -0
- package/dist/adapters/storage/index.d.ts.map +1 -0
- package/dist/crypto/capabilities.d.ts +80 -0
- package/dist/crypto/capabilities.d.ts.map +1 -0
- package/dist/crypto/did.d.ts +19 -0
- package/dist/crypto/did.d.ts.map +1 -0
- package/dist/crypto/encoding.d.ts +7 -0
- package/dist/crypto/encoding.d.ts.map +1 -0
- package/dist/crypto/envelope-auth.d.ts +30 -0
- package/dist/crypto/envelope-auth.d.ts.map +1 -0
- package/dist/crypto/index.d.ts +4 -0
- package/dist/crypto/index.d.ts.map +1 -0
- package/dist/crypto/jws.d.ts +26 -0
- package/dist/crypto/jws.d.ts.map +1 -0
- package/dist/identity/SeedStorage.d.ts +64 -0
- package/dist/identity/SeedStorage.d.ts.map +1 -0
- package/dist/identity/WotIdentity.d.ts +134 -0
- package/dist/identity/WotIdentity.d.ts.map +1 -0
- package/dist/identity/index.d.ts +3 -0
- package/dist/identity/index.d.ts.map +1 -0
- package/dist/index.d.ts +69 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6840 -0
- package/dist/services/AttestationDeliveryService.d.ts +61 -0
- package/dist/services/AttestationDeliveryService.d.ts.map +1 -0
- package/dist/services/EncryptedSyncService.d.ts +26 -0
- package/dist/services/EncryptedSyncService.d.ts.map +1 -0
- package/dist/services/GraphCacheService.d.ts +56 -0
- package/dist/services/GraphCacheService.d.ts.map +1 -0
- package/dist/services/GroupKeyService.d.ts +43 -0
- package/dist/services/GroupKeyService.d.ts.map +1 -0
- package/dist/services/ProfileService.d.ts +19 -0
- package/dist/services/ProfileService.d.ts.map +1 -0
- package/dist/services/VaultClient.d.ts +53 -0
- package/dist/services/VaultClient.d.ts.map +1 -0
- package/dist/services/VaultPushScheduler.d.ts +49 -0
- package/dist/services/VaultPushScheduler.d.ts.map +1 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/storage/CompactStorageManager.d.ts +22 -0
- package/dist/storage/CompactStorageManager.d.ts.map +1 -0
- package/dist/storage/PersistenceMetrics.d.ts +141 -0
- package/dist/storage/PersistenceMetrics.d.ts.map +1 -0
- package/dist/storage/TraceLog.d.ts +85 -0
- package/dist/storage/TraceLog.d.ts.map +1 -0
- package/dist/storage/TracedCompactStorageManager.d.ts +12 -0
- package/dist/storage/TracedCompactStorageManager.d.ts.map +1 -0
- package/dist/types/attestation.d.ts +33 -0
- package/dist/types/attestation.d.ts.map +1 -0
- package/dist/types/contact.d.ts +25 -0
- package/dist/types/contact.d.ts.map +1 -0
- package/dist/types/identity.d.ts +28 -0
- package/dist/types/identity.d.ts.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/messaging.d.ts +33 -0
- package/dist/types/messaging.d.ts.map +1 -0
- package/dist/types/proof.d.ts +12 -0
- package/dist/types/proof.d.ts.map +1 -0
- package/dist/types/resource-ref.d.ts +25 -0
- package/dist/types/resource-ref.d.ts.map +1 -0
- package/dist/types/space.d.ts +25 -0
- package/dist/types/space.d.ts.map +1 -0
- package/dist/types/verification.d.ts +49 -0
- package/dist/types/verification.d.ts.map +1 -0
- package/dist/verification/VerificationHelper.d.ts +75 -0
- package/dist/verification/VerificationHelper.d.ts.map +1 -0
- package/dist/verification/index.d.ts +2 -0
- package/dist/verification/index.d.ts.map +1 -0
- package/dist/wordlists/german-positive.d.ts +21 -0
- package/dist/wordlists/german-positive.d.ts.map +1 -0
- package/dist/wordlists/index.d.ts +2 -0
- package/dist/wordlists/index.d.ts.map +1 -0
- package/package.json +56 -0
package/README.md
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
# @web_of_trust/core
|
|
2
|
+
|
|
3
|
+
Core library for building decentralized Web of Trust applications.
|
|
4
|
+
|
|
5
|
+
## What is Web of Trust?
|
|
6
|
+
|
|
7
|
+
A system where trust grows through real-world encounters. People meet, verify each other's identity, and build reputation through genuine actions - not followers or likes.
|
|
8
|
+
|
|
9
|
+
Three pillars:
|
|
10
|
+
- **Verification** - Confirm identity through meeting in person
|
|
11
|
+
- **Cooperation** - Share encrypted content (calendars, maps, projects)
|
|
12
|
+
- **Attestation** - Build reputation through real deeds
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @web_of_trust/core
|
|
18
|
+
# or
|
|
19
|
+
pnpm add @web_of_trust/core
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { WotIdentity } from '@web_of_trust/core'
|
|
26
|
+
|
|
27
|
+
// Create a new identity
|
|
28
|
+
const identity = new WotIdentity()
|
|
29
|
+
const result = await identity.create('your-secure-passphrase', true)
|
|
30
|
+
|
|
31
|
+
console.log(result.mnemonic) // 12-word BIP39 mnemonic
|
|
32
|
+
console.log(result.did) // did:key:z6Mk...
|
|
33
|
+
|
|
34
|
+
// Later: Unlock from storage
|
|
35
|
+
const identity2 = new WotIdentity()
|
|
36
|
+
await identity2.unlockFromStorage('your-secure-passphrase')
|
|
37
|
+
console.log(identity2.getDid()) // Same DID
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Core Concepts
|
|
41
|
+
|
|
42
|
+
### Identity Management with WotIdentity
|
|
43
|
+
|
|
44
|
+
`WotIdentity` provides a secure, deterministic identity system based on BIP39 mnemonics:
|
|
45
|
+
|
|
46
|
+
**Key Features:**
|
|
47
|
+
|
|
48
|
+
- **BIP39 Mnemonic**: 12-word recovery phrase (128-bit entropy)
|
|
49
|
+
- **Deterministic**: Same mnemonic always produces same DID
|
|
50
|
+
- **Encrypted Storage**: Seed encrypted with PBKDF2 + AES-GCM in IndexedDB
|
|
51
|
+
- **Native WebCrypto**: Pure browser crypto, no external dependencies
|
|
52
|
+
- **Runtime-only Keys**: Keys exist only in memory during session (non-extractable)
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { WotIdentity } from '@web_of_trust/core'
|
|
56
|
+
|
|
57
|
+
const identity = new WotIdentity()
|
|
58
|
+
|
|
59
|
+
// Create new identity
|
|
60
|
+
const { mnemonic, did } = await identity.create('passphrase', true)
|
|
61
|
+
// Save the mnemonic securely! It's the only way to recover your identity
|
|
62
|
+
|
|
63
|
+
// Recover from mnemonic
|
|
64
|
+
await identity.unlock(mnemonic, 'passphrase')
|
|
65
|
+
|
|
66
|
+
// Sign data
|
|
67
|
+
const signature = await identity.sign('Hello, World!')
|
|
68
|
+
|
|
69
|
+
// Get public key
|
|
70
|
+
const pubKey = await identity.getPublicKeyMultibase()
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Decentralized Identifiers (DIDs)
|
|
74
|
+
|
|
75
|
+
Every identity is a `did:key` - a self-sovereign identifier derived from an Ed25519 public key. No central authority needed.
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
const did = identity.getDid()
|
|
79
|
+
console.log(did) // did:key:z6MkpTHz...
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Encrypted Storage
|
|
83
|
+
|
|
84
|
+
Identity seeds are stored encrypted in IndexedDB:
|
|
85
|
+
|
|
86
|
+
- Seed encrypted with PBKDF2 (600k iterations) + AES-GCM
|
|
87
|
+
- Random salt and IV per storage operation
|
|
88
|
+
- Keys derived at runtime as non-extractable CryptoKey objects
|
|
89
|
+
- Keys cleared from memory on lock/reload
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
// Check if identity exists
|
|
93
|
+
const hasIdentity = await identity.hasStoredIdentity()
|
|
94
|
+
|
|
95
|
+
// Delete stored identity
|
|
96
|
+
await identity.deleteStoredIdentity()
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Adapter Interfaces
|
|
100
|
+
|
|
101
|
+
The core defines 7 adapter interfaces. Each can be implemented independently — swap your CRDT, messaging protocol, or storage backend without touching application code.
|
|
102
|
+
|
|
103
|
+
### StorageAdapter
|
|
104
|
+
|
|
105
|
+
Local persistence for identity, contacts, verifications, and attestations. Follows the **Receiver Principle**: verifications and attestations are stored at the recipient, not the sender.
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
interface StorageAdapter {
|
|
109
|
+
createIdentity(did: string, profile: Profile): Promise<Identity>
|
|
110
|
+
getContacts(): Promise<Contact[]>
|
|
111
|
+
addContact(contact: Contact): Promise<void>
|
|
112
|
+
saveVerification(verification: Verification): Promise<void>
|
|
113
|
+
saveAttestation(attestation: Attestation): Promise<void>
|
|
114
|
+
// ... full CRUD for all entity types
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**Implementations:** `LocalStorageAdapter` (IndexedDB)
|
|
119
|
+
|
|
120
|
+
### ReactiveStorageAdapter
|
|
121
|
+
|
|
122
|
+
Extends StorageAdapter with live queries and subscriptions. UI components subscribe to data changes and re-render automatically.
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
interface ReactiveStorageAdapter extends StorageAdapter {
|
|
126
|
+
watchIdentity(): Subscribable<Identity | null>
|
|
127
|
+
watchContacts(): Subscribable<Contact[]>
|
|
128
|
+
watchAllVerifications(): Subscribable<Verification[]>
|
|
129
|
+
watchReceivedAttestations(): Subscribable<Attestation[]>
|
|
130
|
+
// ... observables for all entity types
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
**Implementations:** Yjs-based (default), Automerge-based (option)
|
|
135
|
+
|
|
136
|
+
### CryptoAdapter
|
|
137
|
+
|
|
138
|
+
Signing, verification, and symmetric encryption. Uses WebCrypto API internally — no external crypto dependencies for core operations.
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
interface CryptoAdapter {
|
|
142
|
+
sign(data: Uint8Array, privateKey: CryptoKey): Promise<Uint8Array>
|
|
143
|
+
verify(data: Uint8Array, signature: Uint8Array, publicKey: Uint8Array): Promise<boolean>
|
|
144
|
+
generateSymmetricKey(): Promise<Uint8Array>
|
|
145
|
+
encryptSymmetric(data: Uint8Array, key: Uint8Array): Promise<Uint8Array>
|
|
146
|
+
decryptSymmetric(data: Uint8Array, key: Uint8Array): Promise<Uint8Array>
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**Implementations:** `WebCryptoCryptoAdapter` (Ed25519, AES-256-GCM)
|
|
151
|
+
|
|
152
|
+
### DiscoveryAdapter
|
|
153
|
+
|
|
154
|
+
Public profile lookup — find information about a DID before establishing contact. Profiles are JWS-signed for authenticity.
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
interface DiscoveryAdapter {
|
|
158
|
+
lookupProfile(did: string): Promise<PublicProfile | null>
|
|
159
|
+
publishProfile(profile: PublicProfile): Promise<void>
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**Implementations:** `HttpDiscoveryAdapter` (wot-profiles server), `OfflineFirstDiscoveryAdapter` (cache + dirty flags)
|
|
164
|
+
|
|
165
|
+
### MessagingAdapter
|
|
166
|
+
|
|
167
|
+
Point-to-point message delivery between DIDs. Messages are E2E encrypted and delivered via the Relay with ACK-based guaranteed delivery.
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
interface MessagingAdapter {
|
|
171
|
+
sendMessage(recipientDid: string, message: Uint8Array): Promise<void>
|
|
172
|
+
onMessage(handler: (senderDid: string, message: Uint8Array) => void): void
|
|
173
|
+
register(did: string): Promise<void>
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**Implementations:** `WebSocketMessagingAdapter` (wot-relay), `OutboxMessagingAdapter` (decorator, queues for offline)
|
|
178
|
+
|
|
179
|
+
### ReplicationAdapter
|
|
180
|
+
|
|
181
|
+
Encrypted CRDT-based shared spaces. Multiple users collaborate on the same document with automatic conflict resolution and group key encryption.
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
interface ReplicationAdapter {
|
|
185
|
+
createSpace(info: SpaceInfo): Promise<SpaceHandle>
|
|
186
|
+
joinSpace(spaceId: string, info: SpaceInfo): Promise<SpaceHandle>
|
|
187
|
+
getSpace(spaceId: string): SpaceHandle | undefined
|
|
188
|
+
listSpaces(): SpaceHandle[]
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
**Implementations:** `YjsReplicationAdapter` (default), `AutomergeReplicationAdapter` (option)
|
|
193
|
+
|
|
194
|
+
### AuthorizationAdapter
|
|
195
|
+
|
|
196
|
+
UCAN-inspired capability system. Capabilities are offline-verifiable, delegable, and attenuable. The private key stays encapsulated via the SignFn pattern.
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
interface AuthorizationAdapter {
|
|
200
|
+
createCapability(scope: string, actions: string[], subject: string): Promise<Capability>
|
|
201
|
+
verifyCapability(capability: Capability): Promise<boolean>
|
|
202
|
+
delegateCapability(capability: Capability, to: string, attenuate?: Attenuation): Promise<Capability>
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
**Implementations:** `InMemoryAuthorizationAdapter` + `crypto/capabilities.ts`
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## API Reference
|
|
211
|
+
|
|
212
|
+
### WotIdentity
|
|
213
|
+
|
|
214
|
+
Core identity management class.
|
|
215
|
+
|
|
216
|
+
#### Constructor
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
const identity = new WotIdentity()
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
#### Methods
|
|
223
|
+
|
|
224
|
+
**`create(passphrase: string, storeSeed: boolean): Promise<{ mnemonic: string, did: string }>`**
|
|
225
|
+
|
|
226
|
+
Create a new identity with a BIP39 mnemonic.
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
const { mnemonic, did } = await identity.create('secure-passphrase', true)
|
|
230
|
+
// Save mnemonic securely! It's your only recovery method
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
**`unlock(mnemonic: string, passphrase: string): Promise<void>`**
|
|
234
|
+
|
|
235
|
+
Restore identity from BIP39 mnemonic.
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
await identity.unlock(mnemonic, 'secure-passphrase')
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
**`unlockFromStorage(passphrase: string): Promise<void>`**
|
|
242
|
+
|
|
243
|
+
Unlock identity from encrypted storage.
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
await identity.unlockFromStorage('secure-passphrase')
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
**`sign(data: string): Promise<string>`**
|
|
250
|
+
|
|
251
|
+
Sign data with Ed25519, returns base64url signature.
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
const signature = await identity.sign('Hello, World!')
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
**`getDid(): string`**
|
|
258
|
+
|
|
259
|
+
Get the current DID (throws if locked).
|
|
260
|
+
|
|
261
|
+
```typescript
|
|
262
|
+
const did = identity.getDid() // did:key:z6Mk...
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
**`getPublicKeyMultibase(): Promise<string>`**
|
|
266
|
+
|
|
267
|
+
Get public key in multibase format (z-prefixed base58btc).
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
const pubKey = await identity.getPublicKeyMultibase()
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
**`hasStoredIdentity(): Promise<boolean>`**
|
|
274
|
+
|
|
275
|
+
Check if encrypted seed exists in storage.
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
const exists = await identity.hasStoredIdentity()
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
**`deleteStoredIdentity(): Promise<void>`**
|
|
282
|
+
|
|
283
|
+
Delete encrypted seed from storage and lock identity.
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
await identity.deleteStoredIdentity()
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
**`deriveFrameworkKey(info: string): Promise<Uint8Array>`**
|
|
290
|
+
|
|
291
|
+
Derive framework-specific keys using HKDF.
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
const evolKey = await identity.deriveFrameworkKey('evolu-storage-v1')
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### SeedStorage
|
|
298
|
+
|
|
299
|
+
Low-level encrypted storage for identity seeds.
|
|
300
|
+
|
|
301
|
+
```typescript
|
|
302
|
+
import { SeedStorage } from '@web_of_trust/core'
|
|
303
|
+
|
|
304
|
+
const storage = new SeedStorage()
|
|
305
|
+
|
|
306
|
+
// Store encrypted
|
|
307
|
+
await storage.storeSeed(seedBytes, 'passphrase')
|
|
308
|
+
|
|
309
|
+
// Load and decrypt
|
|
310
|
+
const seed = await storage.loadSeed('passphrase')
|
|
311
|
+
|
|
312
|
+
// Check existence
|
|
313
|
+
const exists = await storage.hasSeed()
|
|
314
|
+
|
|
315
|
+
// Delete
|
|
316
|
+
await storage.deleteSeed()
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
## Development
|
|
320
|
+
|
|
321
|
+
```bash
|
|
322
|
+
# Install dependencies
|
|
323
|
+
pnpm install
|
|
324
|
+
|
|
325
|
+
# Build
|
|
326
|
+
pnpm build
|
|
327
|
+
|
|
328
|
+
# Run tests
|
|
329
|
+
pnpm test
|
|
330
|
+
|
|
331
|
+
# Type check
|
|
332
|
+
pnpm typecheck
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
### Testing
|
|
336
|
+
|
|
337
|
+
The package includes comprehensive test coverage:
|
|
338
|
+
|
|
339
|
+
- **29 tests** covering identity creation, encryption, deterministic key derivation
|
|
340
|
+
- Uses Vitest with happy-dom and fake-indexeddb for browser environment simulation
|
|
341
|
+
- Tests validate BIP39 mnemonic generation, PBKDF2+AES-GCM encryption, and Ed25519 signing
|
|
342
|
+
|
|
343
|
+
Run tests with:
|
|
344
|
+
|
|
345
|
+
```bash
|
|
346
|
+
pnpm test
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
## Part of the Web of Trust Project
|
|
350
|
+
|
|
351
|
+
This package is the foundation for:
|
|
352
|
+
- [Demo App](../apps/demo) - Try the Web of Trust
|
|
353
|
+
- [Protocol Docs](../docs) - Full specification
|
|
354
|
+
|
|
355
|
+
## License
|
|
356
|
+
|
|
357
|
+
MIT
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ResourceRef } from '../../types/resource-ref';
|
|
2
|
+
import { AuthorizationAdapter } from '../interfaces/AuthorizationAdapter';
|
|
3
|
+
import { CapabilityJws, CapabilityVerificationResult, Permission, SignFn } from '../../crypto/capabilities';
|
|
4
|
+
/**
|
|
5
|
+
* In-memory AuthorizationAdapter for testing and simple use cases.
|
|
6
|
+
*
|
|
7
|
+
* Stores capabilities and revocations in memory.
|
|
8
|
+
* Requires a SignFn for creating/delegating capabilities.
|
|
9
|
+
*/
|
|
10
|
+
export declare class InMemoryAuthorizationAdapter implements AuthorizationAdapter {
|
|
11
|
+
private myDid;
|
|
12
|
+
private sign;
|
|
13
|
+
/** Capabilities granted TO this user (received from others) */
|
|
14
|
+
private received;
|
|
15
|
+
/** Capabilities granted BY this user (issued to others) */
|
|
16
|
+
private granted;
|
|
17
|
+
/** Revoked capability IDs */
|
|
18
|
+
private revoked;
|
|
19
|
+
constructor(myDid: string, sign: SignFn);
|
|
20
|
+
grant(resource: ResourceRef, toDid: string, permissions: Permission[], expiration: string): Promise<CapabilityJws>;
|
|
21
|
+
delegate(parentCapabilityJws: CapabilityJws, toDid: string, permissions: Permission[], expiration?: string): Promise<CapabilityJws>;
|
|
22
|
+
verify(capabilityJws: CapabilityJws): Promise<CapabilityVerificationResult>;
|
|
23
|
+
canAccess(did: string, resource: ResourceRef, permission: Permission): Promise<boolean>;
|
|
24
|
+
revoke(capabilityId: string): Promise<void>;
|
|
25
|
+
isRevoked(capabilityId: string): Promise<boolean>;
|
|
26
|
+
store(capabilityJws: CapabilityJws): Promise<void>;
|
|
27
|
+
getMyCapabilities(resource?: ResourceRef): Promise<CapabilityJws[]>;
|
|
28
|
+
getGrantedCapabilities(resource?: ResourceRef): Promise<CapabilityJws[]>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=InMemoryAuthorizationAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InMemoryAuthorizationAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/authorization/InMemoryAuthorizationAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAC3D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAA;AAC9E,OAAO,EAKL,KAAK,aAAa,EAClB,KAAK,4BAA4B,EACjC,KAAK,UAAU,EACf,KAAK,MAAM,EACZ,MAAM,2BAA2B,CAAA;AAElC;;;;;GAKG;AACH,qBAAa,4BAA6B,YAAW,oBAAoB;IACvE,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,IAAI,CAAQ;IAEpB,+DAA+D;IAC/D,OAAO,CAAC,QAAQ,CAAsB;IAEtC,2DAA2D;IAC3D,OAAO,CAAC,OAAO,CAAsB;IAErC,6BAA6B;IAC7B,OAAO,CAAC,OAAO,CAAyB;gBAE5B,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAKjC,KAAK,CACT,QAAQ,EAAE,WAAW,EACrB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,UAAU,EAAE,EACzB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,aAAa,CAAC;IAenB,QAAQ,CACZ,mBAAmB,EAAE,aAAa,EAClC,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,UAAU,EAAE,EACzB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,aAAa,CAAC;IAcnB,MAAM,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,4BAA4B,CAAC;IAiB3E,SAAS,CACb,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,WAAW,EACrB,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,OAAO,CAAC;IAmBb,MAAM,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI3C,SAAS,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIjD,KAAK,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD,iBAAiB,CAAC,QAAQ,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAQnE,sBAAsB,CAAC,QAAQ,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAO/E"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CryptoAdapter } from '../interfaces/CryptoAdapter';
|
|
2
|
+
import { KeyPair } from '../../types';
|
|
3
|
+
export declare class WebCryptoAdapter implements CryptoAdapter {
|
|
4
|
+
generateKeyPair(): Promise<KeyPair>;
|
|
5
|
+
exportKeyPair(keyPair: KeyPair): Promise<{
|
|
6
|
+
publicKey: string;
|
|
7
|
+
privateKey: string;
|
|
8
|
+
}>;
|
|
9
|
+
importKeyPair(exported: {
|
|
10
|
+
publicKey: string;
|
|
11
|
+
privateKey: string;
|
|
12
|
+
}): Promise<KeyPair>;
|
|
13
|
+
exportPublicKey(publicKey: CryptoKey): Promise<string>;
|
|
14
|
+
importPublicKey(exported: string): Promise<CryptoKey>;
|
|
15
|
+
createDid(publicKey: CryptoKey): Promise<string>;
|
|
16
|
+
didToPublicKey(did: string): Promise<CryptoKey>;
|
|
17
|
+
sign(data: Uint8Array, privateKey: CryptoKey): Promise<Uint8Array>;
|
|
18
|
+
verify(data: Uint8Array, signature: Uint8Array, publicKey: CryptoKey): Promise<boolean>;
|
|
19
|
+
signString(data: string, privateKey: CryptoKey): Promise<string>;
|
|
20
|
+
verifyString(data: string, signature: string, publicKey: CryptoKey): Promise<boolean>;
|
|
21
|
+
generateSymmetricKey(): Promise<Uint8Array>;
|
|
22
|
+
encryptSymmetric(plaintext: Uint8Array, key: Uint8Array): Promise<{
|
|
23
|
+
ciphertext: Uint8Array;
|
|
24
|
+
nonce: Uint8Array;
|
|
25
|
+
}>;
|
|
26
|
+
decryptSymmetric(ciphertext: Uint8Array, nonce: Uint8Array, key: Uint8Array): Promise<Uint8Array>;
|
|
27
|
+
generateNonce(): string;
|
|
28
|
+
hashData(data: Uint8Array): Promise<Uint8Array>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=WebCryptoAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebCryptoAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/crypto/WebCryptoAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAI1C,qBAAa,gBAAiB,YAAW,aAAa;IAC9C,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;IAYnC,aAAa,CAAC,OAAO,EAAE,OAAO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a,IAAI,MAAM;IAMjB,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;CAItD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/crypto/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { PublicProfile } from '../../types/identity';
|
|
2
|
+
import { Verification } from '../../types/verification';
|
|
3
|
+
import { Attestation } from '../../types/attestation';
|
|
4
|
+
import { WotIdentity } from '../../identity/WotIdentity';
|
|
5
|
+
import { DiscoveryAdapter, ProfileResolveResult, PublicVerificationsData, PublicAttestationsData, ProfileSummary } from '../interfaces/DiscoveryAdapter';
|
|
6
|
+
/**
|
|
7
|
+
* HTTP-based DiscoveryAdapter implementation.
|
|
8
|
+
*
|
|
9
|
+
* POC implementation backed by wot-profiles (HTTP REST + SQLite).
|
|
10
|
+
* Replaceable by Automerge Auto-Groups, IPFS, DHT, etc.
|
|
11
|
+
*/
|
|
12
|
+
export declare class HttpDiscoveryAdapter implements DiscoveryAdapter {
|
|
13
|
+
private baseUrl;
|
|
14
|
+
private readonly TIMEOUT_MS;
|
|
15
|
+
constructor(baseUrl: string);
|
|
16
|
+
private fetchWithTimeout;
|
|
17
|
+
publishProfile(data: PublicProfile, identity: WotIdentity): Promise<void>;
|
|
18
|
+
publishVerifications(data: PublicVerificationsData, identity: WotIdentity): Promise<void>;
|
|
19
|
+
publishAttestations(data: PublicAttestationsData, identity: WotIdentity): Promise<void>;
|
|
20
|
+
resolveProfile(did: string): Promise<ProfileResolveResult>;
|
|
21
|
+
resolveVerifications(did: string): Promise<Verification[]>;
|
|
22
|
+
resolveAttestations(did: string): Promise<Attestation[]>;
|
|
23
|
+
resolveSummaries(dids: string[]): Promise<ProfileSummary[]>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=HttpDiscoveryAdapter.d.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AO,CAAC,cAAc,EAAE,CAAC;CAelE"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { PublicProfile } from '../../types/identity';
|
|
2
|
+
import { Verification } from '../../types/verification';
|
|
3
|
+
import { Attestation } from '../../types/attestation';
|
|
4
|
+
import { GraphCacheStore, CachedGraphEntry } from '../interfaces/GraphCacheStore';
|
|
5
|
+
/**
|
|
6
|
+
* In-memory implementation of GraphCacheStore.
|
|
7
|
+
*
|
|
8
|
+
* Useful for tests. Data is lost on page reload.
|
|
9
|
+
*/
|
|
10
|
+
export declare class InMemoryGraphCacheStore implements GraphCacheStore {
|
|
11
|
+
private profiles;
|
|
12
|
+
private verifications;
|
|
13
|
+
private attestations;
|
|
14
|
+
private fetchedAt;
|
|
15
|
+
private summaryCounts;
|
|
16
|
+
cacheEntry(did: string, profile: PublicProfile | null, verifications: Verification[], attestations: Attestation[]): Promise<void>;
|
|
17
|
+
getEntry(did: string): Promise<CachedGraphEntry | null>;
|
|
18
|
+
getEntries(dids: string[]): Promise<Map<string, CachedGraphEntry>>;
|
|
19
|
+
getCachedVerifications(did: string): Promise<Verification[]>;
|
|
20
|
+
getCachedAttestations(did: string): Promise<Attestation[]>;
|
|
21
|
+
resolveName(did: string): Promise<string | null>;
|
|
22
|
+
resolveNames(dids: string[]): Promise<Map<string, string>>;
|
|
23
|
+
findMutualContacts(targetDid: string, myContactDids: string[]): Promise<string[]>;
|
|
24
|
+
search(query: string): Promise<CachedGraphEntry[]>;
|
|
25
|
+
updateSummary(did: string, name: string | null, verificationCount: number, attestationCount: number): Promise<void>;
|
|
26
|
+
evict(did: string): Promise<void>;
|
|
27
|
+
clear(): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=InMemoryGraphCacheStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InMemoryGraphCacheStore.d.ts","sourceRoot":"","sources":["../../../src/adapters/discovery/InMemoryGraphCacheStore.ts"],"names":[],"m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MAAM,EAAE,CAAC;IAMjF,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAiBlD,aAAa,CACjB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,GAAG,IAAI,EACnB,iBAAiB,EAAE,MAAM,EACzB,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,IAAI,CAAC;IAiBV,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQjC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAO7B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PublishStateField, PublishStateStore } from '../interfaces/PublishStateStore';
|
|
2
|
+
/**
|
|
3
|
+
* In-memory implementation of PublishStateStore.
|
|
4
|
+
*
|
|
5
|
+
* Useful for tests. Data is lost on page reload.
|
|
6
|
+
*/
|
|
7
|
+
export declare class InMemoryPublishStateStore implements PublishStateStore {
|
|
8
|
+
private dirty;
|
|
9
|
+
markDirty(did: string, field: PublishStateField): Promise<void>;
|
|
10
|
+
clearDirty(did: string, field: PublishStateField): Promise<void>;
|
|
11
|
+
getDirtyFields(did: string): Promise<Set<PublishStateField>>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=InMemoryPublishStateStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InMemoryPublishStateStore.d.ts","sourceRoot":"","sources":["../../../src/adapters/discovery/InMemoryPublishStateStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAE3F;;;;GAIG;AACH,qBAAa,yBAA0B,YAAW,iBAAiB;IACjE,OAAO,CAAC,KAAK,CAA4C;IAEnD,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAM/D,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAQhE,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;CAGnE"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { PublicProfile } from '../../types/identity';
|
|
2
|
+
import { Verification } from '../../types/verification';
|
|
3
|
+
import { Attestation } from '../../types/attestation';
|
|
4
|
+
import { WotIdentity } from '../../identity/WotIdentity';
|
|
5
|
+
import { DiscoveryAdapter, ProfileResolveResult, PublicVerificationsData, PublicAttestationsData, ProfileSummary } from '../interfaces/DiscoveryAdapter';
|
|
6
|
+
import { PublishStateStore } from '../interfaces/PublishStateStore';
|
|
7
|
+
import { GraphCacheStore } from '../interfaces/GraphCacheStore';
|
|
8
|
+
/**
|
|
9
|
+
* Offline-first wrapper for any DiscoveryAdapter.
|
|
10
|
+
*
|
|
11
|
+
* Decorator pattern: wraps an inner DiscoveryAdapter and adds:
|
|
12
|
+
* - Dirty-flag tracking for publish operations (via PublishStateStore)
|
|
13
|
+
* - Profile/verification/attestation caching for resolve operations (via GraphCacheStore)
|
|
14
|
+
* - syncPending() method for retry on reconnect
|
|
15
|
+
*
|
|
16
|
+
* The wrapper is optional — adapters that are natively offline-capable
|
|
17
|
+
* (e.g. Automerge-based) don't need it.
|
|
18
|
+
*
|
|
19
|
+
* Usage:
|
|
20
|
+
* const http = new HttpDiscoveryAdapter(url)
|
|
21
|
+
* const publishState = new EvoluPublishStateStore(evolu, did)
|
|
22
|
+
* const graphCache = new EvoluGraphCacheStore(evolu)
|
|
23
|
+
* const discovery = new OfflineFirstDiscoveryAdapter(http, publishState, graphCache)
|
|
24
|
+
*/
|
|
25
|
+
export declare class OfflineFirstDiscoveryAdapter implements DiscoveryAdapter {
|
|
26
|
+
private inner;
|
|
27
|
+
private publishState;
|
|
28
|
+
private graphCache;
|
|
29
|
+
private _lastError;
|
|
30
|
+
private _errorListeners;
|
|
31
|
+
constructor(inner: DiscoveryAdapter, publishState: PublishStateStore, graphCache: GraphCacheStore);
|
|
32
|
+
/** Last publish error message (null if last attempt succeeded) */
|
|
33
|
+
get lastError(): string | null;
|
|
34
|
+
/** Subscribe to error state changes */
|
|
35
|
+
onErrorChange(listener: (error: string | null) => void): () => void;
|
|
36
|
+
private setError;
|
|
37
|
+
private clearError;
|
|
38
|
+
publishProfile(data: PublicProfile, identity: WotIdentity): Promise<void>;
|
|
39
|
+
publishVerifications(data: PublicVerificationsData, identity: WotIdentity): Promise<void>;
|
|
40
|
+
publishAttestations(data: PublicAttestationsData, identity: WotIdentity): Promise<void>;
|
|
41
|
+
resolveProfile(did: string): Promise<ProfileResolveResult>;
|
|
42
|
+
resolveVerifications(did: string): Promise<Verification[]>;
|
|
43
|
+
resolveAttestations(did: string): Promise<Attestation[]>;
|
|
44
|
+
resolveSummaries(dids: string[]): Promise<ProfileSummary[]>;
|
|
45
|
+
/**
|
|
46
|
+
* Retry all pending publish operations.
|
|
47
|
+
*
|
|
48
|
+
* Called by the app when connectivity is restored (online event,
|
|
49
|
+
* visibility change, or on mount).
|
|
50
|
+
*
|
|
51
|
+
* @param did - The local user's DID
|
|
52
|
+
* @param identity - The unlocked WotIdentity (needed for JWS signing)
|
|
53
|
+
* @param getPublishData - Callback that reads current local data at retry time
|
|
54
|
+
* (not stale data from the original publish attempt)
|
|
55
|
+
*/
|
|
56
|
+
syncPending(did: string, identity: WotIdentity, getPublishData: () => Promise<{
|
|
57
|
+
profile?: PublicProfile;
|
|
58
|
+
verifications?: PublicVerificationsData;
|
|
59
|
+
attestations?: PublicAttestationsData;
|
|
60
|
+
}>): Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=OfflineFirstDiscoveryAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OfflineFirstDiscoveryAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/discovery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E,sBAAsB,EAAE,QAAQ,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAWvF,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAuB1D,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAQ1D,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAQxD,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAOjE;;;;;;;;;;OAUG;IACG,WAAW,CACf,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,WAAW,EACrB,cAAc,EAAE,MAAM,OAAO,CAAC;QAC5B,OAAO,CAAC,EAAE,aAAa,CAAA;QACvB,aAAa,CAAC,EAAE,uBAAuB,CAAA;QACvC,YAAY,CAAC,EAAE,sBAAsB,CAAA;KACtC,CAAC,GACD,OAAO,CAAC,IAAI,CAAC;CAoCjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ResourceRef } from '../../types/resource-ref';
|
|
2
|
+
import { CapabilityJws, CapabilityVerificationResult, Permission } from '../../crypto/capabilities';
|
|
3
|
+
/**
|
|
4
|
+
* AuthorizationAdapter — Stateful layer for capability management.
|
|
5
|
+
*
|
|
6
|
+
* Manages the lifecycle of capability tokens:
|
|
7
|
+
* - Granting capabilities to other DIDs
|
|
8
|
+
* - Storing received capabilities
|
|
9
|
+
* - Querying who can access what
|
|
10
|
+
* - Verifying access (signature + expiration + chain + revocation)
|
|
11
|
+
* - Revoking capabilities
|
|
12
|
+
*
|
|
13
|
+
* The cryptographic primitives (create, verify, delegate) live in
|
|
14
|
+
* crypto/capabilities.ts. This adapter adds state: storage, queries,
|
|
15
|
+
* and revocation lists.
|
|
16
|
+
*
|
|
17
|
+
* Implementations:
|
|
18
|
+
* - InMemoryAuthorizationAdapter (tests)
|
|
19
|
+
* - AutomergeAuthorizationAdapter (Demo-App, stores in Personal-Doc)
|
|
20
|
+
* - StatelessAuthorizationAdapter (wot-vault, verify-only)
|
|
21
|
+
*/
|
|
22
|
+
export interface AuthorizationAdapter {
|
|
23
|
+
/** Grant a capability to another DID. Signs and stores it. */
|
|
24
|
+
grant(resource: ResourceRef, toDid: string, permissions: Permission[], expiration: string): Promise<CapabilityJws>;
|
|
25
|
+
/**
|
|
26
|
+
* Delegate a received capability to another DID (attenuation only).
|
|
27
|
+
* Permissions must be a subset of the parent's.
|
|
28
|
+
* Expiration must be <= parent's.
|
|
29
|
+
*/
|
|
30
|
+
delegate(parentCapabilityJws: CapabilityJws, toDid: string, permissions: Permission[], expiration?: string): Promise<CapabilityJws>;
|
|
31
|
+
/**
|
|
32
|
+
* Verify a capability: signature, expiration, chain, and revocation.
|
|
33
|
+
* Returns the full decoded capability and chain on success.
|
|
34
|
+
*/
|
|
35
|
+
verify(capabilityJws: CapabilityJws): Promise<CapabilityVerificationResult>;
|
|
36
|
+
/**
|
|
37
|
+
* Check if a DID can perform an action on a resource.
|
|
38
|
+
* Convenience method that searches stored capabilities.
|
|
39
|
+
*/
|
|
40
|
+
canAccess(did: string, resource: ResourceRef, permission: Permission): Promise<boolean>;
|
|
41
|
+
/** Revoke a capability by ID. Only the issuer can revoke. */
|
|
42
|
+
revoke(capabilityId: string): Promise<void>;
|
|
43
|
+
/** Check if a capability ID has been revoked. */
|
|
44
|
+
isRevoked(capabilityId: string): Promise<boolean>;
|
|
45
|
+
/** Store a received capability (e.g. from a space invite). */
|
|
46
|
+
store(capabilityJws: CapabilityJws): Promise<void>;
|
|
47
|
+
/** Get all capabilities granted TO the current user. */
|
|
48
|
+
getMyCapabilities(resource?: ResourceRef): Promise<CapabilityJws[]>;
|
|
49
|
+
/** Get all capabilities granted BY the current user. */
|
|
50
|
+
getGrantedCapabilities(resource?: ResourceRef): Promise<CapabilityJws[]>;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=AuthorizationAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthorizationAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/interfaces/AuthorizationAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAC3D,OAAO,KAAK,EACV,aAAa,EACb,4BAA4B,EAC5B,UAAU,EACX,MAAM,2BAA2B,CAAA;AAElC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,WAAW,oBAAoB;IAGnC,8DAA8D;IAC9D,KAAK,CACH,QAAQ,EAAE,WAAW,EACrB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,UAAU,EAAE,EACzB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,aAAa,CAAC,CAAA;IAIzB;;;;OAIG;IACH,QAAQ,CACN,mBAAmB,EAAE,aAAa,EAClC,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,UAAU,EAAE,EACzB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,aAAa,CAAC,CAAA;IAIzB;;;OAGG;IACH,MAAM,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAA;IAE3E;;;OAGG;IACH,SAAS,CACP,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,WAAW,EACrB,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,OAAO,CAAC,CAAA;IAInB,6DAA6D;IAC7D,MAAM,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE3C,iDAAiD;IACjD,SAAS,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