@owlmeans/client-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.
- package/LICENSE +21 -0
- package/README.md +713 -0
- package/build/.gitkeep +0 -0
- package/build/account.d.ts +5 -0
- package/build/account.d.ts.map +1 -0
- package/build/account.js +26 -0
- package/build/account.js.map +1 -0
- package/build/consts.d.ts +7 -0
- package/build/consts.d.ts.map +1 -0
- package/build/consts.js +10 -0
- package/build/consts.js.map +1 -0
- package/build/index.d.ts +5 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +4 -0
- package/build/index.js.map +1 -0
- package/build/service.d.ts +6 -0
- package/build/service.d.ts.map +1 -0
- package/build/service.js +68 -0
- package/build/service.js.map +1 -0
- package/build/types.d.ts +23 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +2 -0
- package/build/types.js.map +1 -0
- package/package.json +39 -0
- package/src/account.ts +29 -0
- package/src/consts.ts +13 -0
- package/src/index.ts +5 -0
- package/src/service.ts +87 -0
- package/src/types.ts +26 -0
- package/tsconfig.json +15 -0
- package/tsconfig.tsbuildinfo +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 OwlMeans Common — Fullstack typescript framework
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,713 @@
|
|
|
1
|
+
# @owlmeans/client-did
|
|
2
|
+
|
|
3
|
+
Client-side Decentralized Identity (DID) implementation for OwlMeans applications. This package provides complete DID wallet management, authentication, and account functionality for browser and React Native environments.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The `@owlmeans/client-did` package enables client-side decentralized identity functionality, providing:
|
|
8
|
+
|
|
9
|
+
- **DID Wallet Service**: Complete wallet lifecycle management with lazy initialization
|
|
10
|
+
- **DID Account Models**: Account abstraction for authentication and signing operations
|
|
11
|
+
- **Resource Integration**: Seamless integration with client resource system for persistent storage
|
|
12
|
+
- **Authentication Support**: DID-based authentication credential generation
|
|
13
|
+
- **State Management**: Integration with OwlMeans state system for reactive updates
|
|
14
|
+
- **Cross-Platform Support**: Works in web browsers and React Native environments
|
|
15
|
+
|
|
16
|
+
This package is part of the OwlMeans DID ecosystem:
|
|
17
|
+
- **@owlmeans/did**: Core DID functionality and wallet implementation
|
|
18
|
+
- **@owlmeans/client-did**: Client-side DID implementation *(this package)*
|
|
19
|
+
- **@owlmeans/basic-keys**: Cryptographic key management
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install @owlmeans/client-did
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Dependencies
|
|
28
|
+
|
|
29
|
+
This package requires:
|
|
30
|
+
- `@owlmeans/did`: Core DID functionality
|
|
31
|
+
- `@owlmeans/client-context`: Client context management
|
|
32
|
+
- `@owlmeans/client-resource`: Client resource system
|
|
33
|
+
- `@owlmeans/basic-keys`: Cryptographic operations
|
|
34
|
+
- `@owlmeans/auth`: Authentication types and interfaces
|
|
35
|
+
- `@owlmeans/state`: State management integration
|
|
36
|
+
|
|
37
|
+
## Core Concepts
|
|
38
|
+
|
|
39
|
+
### DID Wallet Service
|
|
40
|
+
|
|
41
|
+
The DID wallet service manages the lifecycle of decentralized identity wallets, including creation, initialization, and persistence across client sessions.
|
|
42
|
+
|
|
43
|
+
### DID Account Model
|
|
44
|
+
|
|
45
|
+
Account models provide a simplified interface for DID-based authentication and credential generation.
|
|
46
|
+
|
|
47
|
+
### Resource Dependencies
|
|
48
|
+
|
|
49
|
+
The service uses three key resources for persistent storage:
|
|
50
|
+
- **Keys Resource**: Stores cryptographic key pairs
|
|
51
|
+
- **Meta Resource**: Stores metadata about DID keys
|
|
52
|
+
- **Master Resource**: Stores master wallet configuration
|
|
53
|
+
|
|
54
|
+
## API Reference
|
|
55
|
+
|
|
56
|
+
### Types
|
|
57
|
+
|
|
58
|
+
#### `DIDService`
|
|
59
|
+
|
|
60
|
+
Main service interface for DID wallet management.
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
interface DIDService extends LazyService {
|
|
64
|
+
wallet: DIDWallet // Current wallet instance
|
|
65
|
+
exists(): Promise<boolean> // Check if wallet exists
|
|
66
|
+
create(opts?: MakeDIDWalletOptions): Promise<DIDWallet> // Create new wallet
|
|
67
|
+
intialize(): Promise<DIDWallet> // Initialize existing wallet
|
|
68
|
+
get(): DIDWallet // Get current wallet
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
#### `DIDServiceAppend`
|
|
73
|
+
|
|
74
|
+
Interface for contexts that provide DID service access.
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
interface DIDServiceAppend {
|
|
78
|
+
getDidService(alias?: string): DIDService
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
#### `DIDServiceDeps`
|
|
83
|
+
|
|
84
|
+
Configuration for service resource dependencies.
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
interface DIDServiceDeps {
|
|
88
|
+
keys: string // Key pair resource alias
|
|
89
|
+
meta: string // Key metadata resource alias
|
|
90
|
+
master: string // Master wallet resource alias
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
#### `DIDAccountModel`
|
|
95
|
+
|
|
96
|
+
Account model interface for DID-based authentication.
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
interface DIDAccountModel {
|
|
100
|
+
did: DIDKeyModel // DID key model
|
|
101
|
+
authenticate<T extends Partial<AuthCredentials>>(auth: T): Promise<T> // Generate auth credentials
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Factory Functions
|
|
106
|
+
|
|
107
|
+
#### `makeWalletService(alias?: string, deps?: DIDServiceDeps): DIDService`
|
|
108
|
+
|
|
109
|
+
Creates a DID wallet service with resource dependencies.
|
|
110
|
+
|
|
111
|
+
**Parameters:**
|
|
112
|
+
- `alias`: Service alias (default: 'did-wallet')
|
|
113
|
+
- `deps`: Resource dependencies configuration
|
|
114
|
+
|
|
115
|
+
**Returns:** DIDService instance
|
|
116
|
+
|
|
117
|
+
**Example:**
|
|
118
|
+
```typescript
|
|
119
|
+
import { makeWalletService } from '@owlmeans/client-did'
|
|
120
|
+
|
|
121
|
+
const didService = makeWalletService('primary-wallet')
|
|
122
|
+
|
|
123
|
+
// Custom resource dependencies
|
|
124
|
+
const customService = makeWalletService('custom-wallet', {
|
|
125
|
+
keys: 'custom-keys',
|
|
126
|
+
meta: 'custom-meta',
|
|
127
|
+
master: 'custom-master'
|
|
128
|
+
})
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
#### `appendDidService<C extends ClientConfig, T extends ClientContext<C>>(ctx: T, alias?: string, customDeps?: Partial<DIDServiceDeps>): T & DIDServiceAppend`
|
|
132
|
+
|
|
133
|
+
Appends DID service capabilities to a client context.
|
|
134
|
+
|
|
135
|
+
**Parameters:**
|
|
136
|
+
- `ctx`: Client context to extend
|
|
137
|
+
- `alias`: Service alias (default: 'did-wallet')
|
|
138
|
+
- `customDeps`: Custom resource dependencies
|
|
139
|
+
|
|
140
|
+
**Returns:** Context with DID service capabilities
|
|
141
|
+
|
|
142
|
+
**Features:**
|
|
143
|
+
- Automatically creates required resources if they don't exist
|
|
144
|
+
- Registers DID service with context
|
|
145
|
+
- Adds `getDidService()` method to context
|
|
146
|
+
- Integrates with state debugging
|
|
147
|
+
|
|
148
|
+
**Example:**
|
|
149
|
+
```typescript
|
|
150
|
+
import { appendDidService } from '@owlmeans/client-did'
|
|
151
|
+
import { makeClientContext } from '@owlmeans/client-context'
|
|
152
|
+
|
|
153
|
+
const context = makeClientContext(config)
|
|
154
|
+
const contextWithDid = appendDidService(context)
|
|
155
|
+
|
|
156
|
+
// Initialize context
|
|
157
|
+
await contextWithDid.configure().init()
|
|
158
|
+
|
|
159
|
+
// Access DID service
|
|
160
|
+
const didService = contextWithDid.getDidService()
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
#### `makeDidAccountModel(did: KeyPair | DIDKeyModel | string, isPub?: boolean): DIDAccountModel`
|
|
164
|
+
|
|
165
|
+
Creates a DID account model for authentication operations.
|
|
166
|
+
|
|
167
|
+
**Parameters:**
|
|
168
|
+
- `did`: DID key material (KeyPair, DIDKeyModel, or string)
|
|
169
|
+
- `isPub`: Whether the string is a public key (default: false)
|
|
170
|
+
|
|
171
|
+
**Returns:** DIDAccountModel instance
|
|
172
|
+
|
|
173
|
+
**Example:**
|
|
174
|
+
```typescript
|
|
175
|
+
import { makeDidAccountModel } from '@owlmeans/client-did'
|
|
176
|
+
|
|
177
|
+
// From existing DID key model
|
|
178
|
+
const account1 = makeDidAccountModel(didKeyModel)
|
|
179
|
+
|
|
180
|
+
// From key pair
|
|
181
|
+
const account2 = makeDidAccountModel(keyPair)
|
|
182
|
+
|
|
183
|
+
// From private key string
|
|
184
|
+
const account3 = makeDidAccountModel('ed25519:privateKeyString')
|
|
185
|
+
|
|
186
|
+
// From public key string
|
|
187
|
+
const account4 = makeDidAccountModel('ed25519:publicKeyString', true)
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Service Methods
|
|
191
|
+
|
|
192
|
+
#### `exists(): Promise<boolean>`
|
|
193
|
+
|
|
194
|
+
Checks if a DID wallet already exists in persistent storage.
|
|
195
|
+
|
|
196
|
+
**Returns:** Promise resolving to boolean indicating existence
|
|
197
|
+
|
|
198
|
+
**Example:**
|
|
199
|
+
```typescript
|
|
200
|
+
const didService = makeWalletService()
|
|
201
|
+
|
|
202
|
+
if (await didService.exists()) {
|
|
203
|
+
console.log('Wallet already exists')
|
|
204
|
+
await didService.intialize()
|
|
205
|
+
} else {
|
|
206
|
+
console.log('Creating new wallet')
|
|
207
|
+
await didService.create()
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
#### `create(opts?: MakeDIDWalletOptions): Promise<DIDWallet>`
|
|
212
|
+
|
|
213
|
+
Creates a new DID wallet. Throws error if wallet already exists.
|
|
214
|
+
|
|
215
|
+
**Parameters:**
|
|
216
|
+
- `opts`: Wallet creation options
|
|
217
|
+
|
|
218
|
+
**Returns:** Promise resolving to new DIDWallet
|
|
219
|
+
|
|
220
|
+
**Throws:** `DIDInitializationError` if wallet already exists
|
|
221
|
+
|
|
222
|
+
**Example:**
|
|
223
|
+
```typescript
|
|
224
|
+
try {
|
|
225
|
+
const wallet = await didService.create({
|
|
226
|
+
// Custom wallet options
|
|
227
|
+
keyType: 'ed25519',
|
|
228
|
+
derivationPath: "m/44'/60'/0'/0/0"
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
console.log('Wallet created:', wallet.exportAddress())
|
|
232
|
+
} catch (error) {
|
|
233
|
+
if (error instanceof DIDInitializationError) {
|
|
234
|
+
console.error('Wallet already exists')
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
#### `intialize(): Promise<DIDWallet>`
|
|
240
|
+
|
|
241
|
+
Initializes an existing DID wallet from persistent storage.
|
|
242
|
+
|
|
243
|
+
**Returns:** Promise resolving to initialized DIDWallet
|
|
244
|
+
|
|
245
|
+
**Example:**
|
|
246
|
+
```typescript
|
|
247
|
+
const wallet = await didService.intialize()
|
|
248
|
+
console.log('Wallet initialized:', wallet.exportAddress())
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
#### `get(): DIDWallet`
|
|
252
|
+
|
|
253
|
+
Gets the current wallet instance (must be initialized first).
|
|
254
|
+
|
|
255
|
+
**Returns:** Current DIDWallet instance
|
|
256
|
+
|
|
257
|
+
**Example:**
|
|
258
|
+
```typescript
|
|
259
|
+
await didService.intialize()
|
|
260
|
+
const wallet = didService.get()
|
|
261
|
+
|
|
262
|
+
// Use wallet for operations
|
|
263
|
+
const signature = await wallet.sign('message to sign')
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### Account Model Methods
|
|
267
|
+
|
|
268
|
+
#### `authenticate<T extends Partial<AuthCredentials>>(auth: T): Promise<T>`
|
|
269
|
+
|
|
270
|
+
Generates authentication credentials using the DID key.
|
|
271
|
+
|
|
272
|
+
**Parameters:**
|
|
273
|
+
- `auth`: Partial authentication credentials with challenge
|
|
274
|
+
|
|
275
|
+
**Returns:** Promise resolving to complete authentication credentials
|
|
276
|
+
|
|
277
|
+
**Process:**
|
|
278
|
+
1. Sets `userId` to DID address
|
|
279
|
+
2. Sets `publicKey` to DID public key
|
|
280
|
+
3. Signs the challenge and sets `credential`
|
|
281
|
+
|
|
282
|
+
**Example:**
|
|
283
|
+
```typescript
|
|
284
|
+
const account = makeDidAccountModel(didKeyModel)
|
|
285
|
+
|
|
286
|
+
// Authenticate with challenge
|
|
287
|
+
const authResult = await account.authenticate({
|
|
288
|
+
challenge: 'authentication-challenge-string',
|
|
289
|
+
type: 'ed25519'
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
console.log('User ID:', authResult.userId)
|
|
293
|
+
console.log('Public Key:', authResult.publicKey)
|
|
294
|
+
console.log('Credential:', authResult.credential)
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### Constants
|
|
298
|
+
|
|
299
|
+
#### Service Configuration
|
|
300
|
+
```typescript
|
|
301
|
+
const DEFAULT_ALIAS = 'did-wallet' // Default service alias
|
|
302
|
+
|
|
303
|
+
const DEF_KEYS_RESOURCE = 'did-wallet-keys' // Default keys resource
|
|
304
|
+
const DEF_META_RESOURCE = 'did-wallet-meta' // Default meta resource
|
|
305
|
+
const DEF_MASTER_RESOURCE = 'did-wallet-master' // Default master resource
|
|
306
|
+
|
|
307
|
+
const defDeps: DIDServiceDeps = {
|
|
308
|
+
keys: DEF_KEYS_RESOURCE,
|
|
309
|
+
meta: DEF_META_RESOURCE,
|
|
310
|
+
master: DEF_MASTER_RESOURCE
|
|
311
|
+
}
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
## Usage Examples
|
|
315
|
+
|
|
316
|
+
### Basic DID Wallet Setup
|
|
317
|
+
|
|
318
|
+
```typescript
|
|
319
|
+
import { appendDidService } from '@owlmeans/client-did'
|
|
320
|
+
import { makeClientContext } from '@owlmeans/client-context'
|
|
321
|
+
|
|
322
|
+
// Create context with DID capabilities
|
|
323
|
+
const context = makeClientContext({
|
|
324
|
+
service: 'my-app',
|
|
325
|
+
// ... other config
|
|
326
|
+
})
|
|
327
|
+
|
|
328
|
+
const contextWithDid = appendDidService(context)
|
|
329
|
+
|
|
330
|
+
// Initialize context
|
|
331
|
+
await contextWithDid.configure().init()
|
|
332
|
+
|
|
333
|
+
// Access DID service
|
|
334
|
+
const didService = contextWithDid.getDidService()
|
|
335
|
+
|
|
336
|
+
// Check if wallet exists
|
|
337
|
+
if (await didService.exists()) {
|
|
338
|
+
await didService.intialize()
|
|
339
|
+
console.log('Wallet loaded')
|
|
340
|
+
} else {
|
|
341
|
+
await didService.create()
|
|
342
|
+
console.log('New wallet created')
|
|
343
|
+
}
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
### DID-Based Authentication
|
|
347
|
+
|
|
348
|
+
```typescript
|
|
349
|
+
import { makeDidAccountModel } from '@owlmeans/client-did'
|
|
350
|
+
|
|
351
|
+
// Create account from wallet
|
|
352
|
+
const didService = context.getDidService()
|
|
353
|
+
const wallet = didService.get()
|
|
354
|
+
const account = makeDidAccountModel(wallet.master)
|
|
355
|
+
|
|
356
|
+
// Authenticate with server challenge
|
|
357
|
+
const challenge = 'server-provided-challenge'
|
|
358
|
+
const authCredentials = await account.authenticate({
|
|
359
|
+
challenge,
|
|
360
|
+
type: 'ed25519'
|
|
361
|
+
})
|
|
362
|
+
|
|
363
|
+
// Send credentials to server
|
|
364
|
+
const response = await fetch('/api/authenticate', {
|
|
365
|
+
method: 'POST',
|
|
366
|
+
headers: { 'Content-Type': 'application/json' },
|
|
367
|
+
body: JSON.stringify(authCredentials)
|
|
368
|
+
})
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
### Multiple DID Wallets
|
|
372
|
+
|
|
373
|
+
```typescript
|
|
374
|
+
// Create multiple wallet services
|
|
375
|
+
const primaryContext = appendDidService(context, 'primary', {
|
|
376
|
+
keys: 'primary-keys',
|
|
377
|
+
meta: 'primary-meta',
|
|
378
|
+
master: 'primary-master'
|
|
379
|
+
})
|
|
380
|
+
|
|
381
|
+
const backupContext = appendDidService(primaryContext, 'backup', {
|
|
382
|
+
keys: 'backup-keys',
|
|
383
|
+
meta: 'backup-meta',
|
|
384
|
+
master: 'backup-master'
|
|
385
|
+
})
|
|
386
|
+
|
|
387
|
+
await backupContext.configure().init()
|
|
388
|
+
|
|
389
|
+
// Use different wallets
|
|
390
|
+
const primaryDid = backupContext.getDidService('primary')
|
|
391
|
+
const backupDid = backupContext.getDidService('backup')
|
|
392
|
+
|
|
393
|
+
// Create both wallets
|
|
394
|
+
if (!await primaryDid.exists()) {
|
|
395
|
+
await primaryDid.create()
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
if (!await backupDid.exists()) {
|
|
399
|
+
await backupDid.create()
|
|
400
|
+
}
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
### Wallet Recovery and Import
|
|
404
|
+
|
|
405
|
+
```typescript
|
|
406
|
+
import { makeDidAccountModel } from '@owlmeans/client-did'
|
|
407
|
+
|
|
408
|
+
// Recovery from private key
|
|
409
|
+
const recoverWallet = async (privateKeyString: string) => {
|
|
410
|
+
const account = makeDidAccountModel(privateKeyString)
|
|
411
|
+
console.log('Recovered wallet address:', account.did.exportAddress())
|
|
412
|
+
|
|
413
|
+
return account
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// Import from existing key pair
|
|
417
|
+
const importWallet = async (keyPair: KeyPair) => {
|
|
418
|
+
const account = makeDidAccountModel(keyPair)
|
|
419
|
+
|
|
420
|
+
// Authenticate to verify ownership
|
|
421
|
+
const authTest = await account.authenticate({
|
|
422
|
+
challenge: 'ownership-verification'
|
|
423
|
+
})
|
|
424
|
+
|
|
425
|
+
return account
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// Usage
|
|
429
|
+
const recovered = await recoverWallet('ed25519:private-key-string')
|
|
430
|
+
const imported = await importWallet(existingKeyPair)
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
### Signing and Verification
|
|
434
|
+
|
|
435
|
+
```typescript
|
|
436
|
+
// Sign messages with DID wallet
|
|
437
|
+
const didService = context.getDidService()
|
|
438
|
+
const wallet = didService.get()
|
|
439
|
+
|
|
440
|
+
// Sign arbitrary data
|
|
441
|
+
const signature = await wallet.sign('important message')
|
|
442
|
+
console.log('Signature:', signature)
|
|
443
|
+
|
|
444
|
+
// Verify signature
|
|
445
|
+
const isValid = await wallet.verify('important message', signature)
|
|
446
|
+
console.log('Signature valid:', isValid)
|
|
447
|
+
|
|
448
|
+
// Account-based signing
|
|
449
|
+
const account = makeDidAccountModel(wallet.master)
|
|
450
|
+
const authSig = await account.authenticate({
|
|
451
|
+
challenge: 'server-challenge'
|
|
452
|
+
})
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
### Integration with Authentication Flow
|
|
456
|
+
|
|
457
|
+
```typescript
|
|
458
|
+
import { AuthenticationStage } from '@owlmeans/auth'
|
|
459
|
+
|
|
460
|
+
class DIDAuthenticationFlow {
|
|
461
|
+
private account: DIDAccountModel
|
|
462
|
+
|
|
463
|
+
constructor(didService: DIDService) {
|
|
464
|
+
this.account = makeDidAccountModel(didService.get().master)
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
async initialize() {
|
|
468
|
+
return {
|
|
469
|
+
stage: AuthenticationStage.Init,
|
|
470
|
+
publicKey: this.account.did.exportPublic(),
|
|
471
|
+
address: this.account.did.exportAddress()
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
async authenticate(challenge: string) {
|
|
476
|
+
const credentials = await this.account.authenticate({
|
|
477
|
+
challenge,
|
|
478
|
+
type: 'ed25519'
|
|
479
|
+
})
|
|
480
|
+
|
|
481
|
+
return {
|
|
482
|
+
stage: AuthenticationStage.Authenticated,
|
|
483
|
+
...credentials
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// Usage
|
|
489
|
+
const authFlow = new DIDAuthenticationFlow(didService)
|
|
490
|
+
const initResult = await authFlow.initialize()
|
|
491
|
+
|
|
492
|
+
// Send init to server, receive challenge
|
|
493
|
+
const challenge = await sendToServer('/auth/init', initResult)
|
|
494
|
+
const authResult = await authFlow.authenticate(challenge.challenge)
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
### State Management Integration
|
|
498
|
+
|
|
499
|
+
```typescript
|
|
500
|
+
// The service automatically integrates with state debugging
|
|
501
|
+
const contextWithDid = appendDidService(context)
|
|
502
|
+
|
|
503
|
+
// State changes are tracked for resources
|
|
504
|
+
contextWithDid.getDidService() // State debugging enabled for did-wallet-*
|
|
505
|
+
|
|
506
|
+
// Monitor wallet state changes
|
|
507
|
+
const stateService = contextWithDid.service('state')
|
|
508
|
+
stateService.subscribe('did-wallet-master', (change) => {
|
|
509
|
+
console.log('Wallet state changed:', change)
|
|
510
|
+
})
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
### Error Handling
|
|
514
|
+
|
|
515
|
+
```typescript
|
|
516
|
+
import { DIDInitializationError } from '@owlmeans/did'
|
|
517
|
+
|
|
518
|
+
try {
|
|
519
|
+
const didService = makeWalletService()
|
|
520
|
+
|
|
521
|
+
// Try to create wallet
|
|
522
|
+
await didService.create()
|
|
523
|
+
} catch (error) {
|
|
524
|
+
if (error instanceof DIDInitializationError) {
|
|
525
|
+
if (error.message.includes('exists:service')) {
|
|
526
|
+
console.log('Wallet already exists, initializing instead')
|
|
527
|
+
await didService.intialize()
|
|
528
|
+
} else {
|
|
529
|
+
console.error('DID initialization failed:', error.message)
|
|
530
|
+
}
|
|
531
|
+
} else {
|
|
532
|
+
console.error('Unexpected error:', error)
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
### Custom Resource Configuration
|
|
538
|
+
|
|
539
|
+
```typescript
|
|
540
|
+
// Custom resource aliases for different use cases
|
|
541
|
+
const customDeps: DIDServiceDeps = {
|
|
542
|
+
keys: 'secure-keys',
|
|
543
|
+
meta: 'wallet-metadata',
|
|
544
|
+
master: 'master-wallet'
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
const secureDidService = makeWalletService('secure-wallet', customDeps)
|
|
548
|
+
|
|
549
|
+
// Or use with appendDidService
|
|
550
|
+
const contextWithCustomDid = appendDidService(context, 'custom', {
|
|
551
|
+
keys: 'custom-keys-resource',
|
|
552
|
+
meta: 'custom-meta-resource'
|
|
553
|
+
// master will default to 'custom-master'
|
|
554
|
+
})
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
### Cross-Platform Considerations
|
|
558
|
+
|
|
559
|
+
```typescript
|
|
560
|
+
// Browser-specific initialization
|
|
561
|
+
if (typeof window !== 'undefined') {
|
|
562
|
+
// Browser environment
|
|
563
|
+
const context = makeClientContext(browserConfig)
|
|
564
|
+
const contextWithDid = appendDidService(context)
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// React Native-specific initialization
|
|
568
|
+
if (typeof global !== 'undefined' && global.navigator?.product === 'ReactNative') {
|
|
569
|
+
// React Native environment
|
|
570
|
+
const context = makeClientContext(reactNativeConfig)
|
|
571
|
+
const contextWithDid = appendDidService(context)
|
|
572
|
+
}
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
## Advanced Features
|
|
576
|
+
|
|
577
|
+
### Wallet Export and Backup
|
|
578
|
+
|
|
579
|
+
```typescript
|
|
580
|
+
// Export wallet for backup
|
|
581
|
+
const didService = context.getDidService()
|
|
582
|
+
const wallet = didService.get()
|
|
583
|
+
|
|
584
|
+
const exportData = {
|
|
585
|
+
address: wallet.exportAddress(),
|
|
586
|
+
publicKey: wallet.exportPublic(),
|
|
587
|
+
// Note: private key export depends on wallet implementation
|
|
588
|
+
masterKey: wallet.master?.export?.() // If available
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
// Store backup securely
|
|
592
|
+
localStorage.setItem('wallet-backup', JSON.stringify(exportData))
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
### Multi-Signature Support
|
|
596
|
+
|
|
597
|
+
```typescript
|
|
598
|
+
// Create multiple accounts for multi-sig
|
|
599
|
+
const wallet = didService.get()
|
|
600
|
+
const accounts = [
|
|
601
|
+
makeDidAccountModel(wallet.master),
|
|
602
|
+
makeDidAccountModel(wallet.createDerived?.(1) || wallet.master),
|
|
603
|
+
makeDidAccountModel(wallet.createDerived?.(2) || wallet.master)
|
|
604
|
+
]
|
|
605
|
+
|
|
606
|
+
// Multi-signature authentication
|
|
607
|
+
const multiAuth = async (challenge: string) => {
|
|
608
|
+
const signatures = await Promise.all(
|
|
609
|
+
accounts.map(account =>
|
|
610
|
+
account.authenticate({ challenge, type: 'ed25519' })
|
|
611
|
+
)
|
|
612
|
+
)
|
|
613
|
+
|
|
614
|
+
return {
|
|
615
|
+
type: 'multi-sig',
|
|
616
|
+
signatures,
|
|
617
|
+
threshold: 2 // Require 2 of 3 signatures
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
### Hierarchical Deterministic Support
|
|
623
|
+
|
|
624
|
+
```typescript
|
|
625
|
+
// If wallet supports HD derivation
|
|
626
|
+
const wallet = didService.get()
|
|
627
|
+
|
|
628
|
+
// Create derived accounts for different purposes
|
|
629
|
+
const tradingAccount = wallet.deriveAccount?.('m/44\'/60\'/0\'/0/0')
|
|
630
|
+
const savingsAccount = wallet.deriveAccount?.('m/44\'/60\'/0\'/0/1')
|
|
631
|
+
|
|
632
|
+
if (tradingAccount && savingsAccount) {
|
|
633
|
+
const tradingDid = makeDidAccountModel(tradingAccount)
|
|
634
|
+
const savingsDid = makeDidAccountModel(savingsAccount)
|
|
635
|
+
|
|
636
|
+
console.log('Trading address:', tradingDid.did.exportAddress())
|
|
637
|
+
console.log('Savings address:', savingsDid.did.exportAddress())
|
|
638
|
+
}
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
## Security Considerations
|
|
642
|
+
|
|
643
|
+
### Private Key Protection
|
|
644
|
+
- Private keys are stored using client resource system
|
|
645
|
+
- Use appropriate security measures for key storage
|
|
646
|
+
- Consider hardware security modules for high-value applications
|
|
647
|
+
|
|
648
|
+
### Authentication Security
|
|
649
|
+
- Always verify challenges come from trusted sources
|
|
650
|
+
- Implement replay attack protection
|
|
651
|
+
- Use secure communication channels for credential exchange
|
|
652
|
+
|
|
653
|
+
### Wallet Management
|
|
654
|
+
- Implement proper wallet backup and recovery procedures
|
|
655
|
+
- Use strong entropy for wallet generation
|
|
656
|
+
- Consider multi-factor authentication for wallet access
|
|
657
|
+
|
|
658
|
+
## Best Practices
|
|
659
|
+
|
|
660
|
+
1. **Initialization**: Check wallet existence before creation
|
|
661
|
+
2. **Error Handling**: Properly handle DID initialization errors
|
|
662
|
+
3. **Resource Management**: Use meaningful resource aliases
|
|
663
|
+
4. **State Integration**: Leverage state debugging for development
|
|
664
|
+
5. **Security**: Never expose private keys in logs or error messages
|
|
665
|
+
6. **Backup**: Implement secure wallet backup procedures
|
|
666
|
+
7. **Testing**: Test authentication flows thoroughly
|
|
667
|
+
|
|
668
|
+
## Integration with OwlMeans Ecosystem
|
|
669
|
+
|
|
670
|
+
### Authentication Integration
|
|
671
|
+
```typescript
|
|
672
|
+
import { AuthService } from '@owlmeans/client-auth'
|
|
673
|
+
|
|
674
|
+
// Use DID for OwlMeans authentication
|
|
675
|
+
const authService = context.service<AuthService>('auth')
|
|
676
|
+
const didService = context.getDidService()
|
|
677
|
+
|
|
678
|
+
// Custom DID-based authentication
|
|
679
|
+
const authenticateWithDid = async (challenge: string) => {
|
|
680
|
+
const account = makeDidAccountModel(didService.get().master)
|
|
681
|
+
const credentials = await account.authenticate({ challenge })
|
|
682
|
+
|
|
683
|
+
await authService.authenticate({ token: credentials.credential })
|
|
684
|
+
}
|
|
685
|
+
```
|
|
686
|
+
|
|
687
|
+
### Context Integration
|
|
688
|
+
```typescript
|
|
689
|
+
import { makeClientContext } from '@owlmeans/client-context'
|
|
690
|
+
|
|
691
|
+
// DID service integrates seamlessly with client context
|
|
692
|
+
const context = makeClientContext(config)
|
|
693
|
+
const contextWithDid = appendDidService(context)
|
|
694
|
+
|
|
695
|
+
// All OwlMeans services work together
|
|
696
|
+
await contextWithDid.configure().init()
|
|
697
|
+
```
|
|
698
|
+
|
|
699
|
+
## Performance Considerations
|
|
700
|
+
|
|
701
|
+
- **Lazy Initialization**: Service initializes only when needed
|
|
702
|
+
- **Resource Caching**: Resources are cached after first access
|
|
703
|
+
- **Cryptographic Operations**: Ed25519 operations are computationally efficient
|
|
704
|
+
- **State Updates**: State changes are optimized for performance
|
|
705
|
+
|
|
706
|
+
## Related Packages
|
|
707
|
+
|
|
708
|
+
- [`@owlmeans/did`](../did) - Core DID functionality and wallet implementation
|
|
709
|
+
- [`@owlmeans/basic-keys`](../basic-keys) - Cryptographic key management
|
|
710
|
+
- [`@owlmeans/client-context`](../client-context) - Client context management
|
|
711
|
+
- [`@owlmeans/client-resource`](../client-resource) - Client resource system
|
|
712
|
+
- [`@owlmeans/auth`](../auth) - Authentication types and interfaces
|
|
713
|
+
- [`@owlmeans/state`](../state) - State management system
|
package/build/.gitkeep
ADDED
|
File without changes
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { DIDKeyModel } from '@owlmeans/did';
|
|
2
|
+
import type { DIDAccountModel } from './types.js';
|
|
3
|
+
import { KeyPair } from '@owlmeans/basic-keys';
|
|
4
|
+
export declare const makeDidAccountModel: (did: KeyPair | DIDKeyModel | string, isPub?: boolean) => DIDAccountModel;
|
|
5
|
+
//# sourceMappingURL=account.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAI,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,EAAc,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAE1D,eAAO,MAAM,mBAAmB,QAAS,OAAO,GAAE,WAAW,GAAG,MAAM,UAAS,OAAO,KAAW,eAuBhG,CAAA"}
|
package/build/account.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { makeDidKeyModel } from '@owlmeans/did';
|
|
2
|
+
import { fromPubKey } from '@owlmeans/basic-keys';
|
|
3
|
+
export const makeDidAccountModel = (did, isPub = false) => {
|
|
4
|
+
if (typeof did === 'string') {
|
|
5
|
+
if (isPub) {
|
|
6
|
+
did = makeDidKeyModel(fromPubKey(did).keyPair);
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
did = makeDidKeyModel(did);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
else if (!("keyPair" in did)) {
|
|
13
|
+
did = makeDidKeyModel(did);
|
|
14
|
+
}
|
|
15
|
+
const model = {
|
|
16
|
+
did,
|
|
17
|
+
authenticate: async (auth) => {
|
|
18
|
+
auth.userId = model.did.exportAddress();
|
|
19
|
+
auth.publicKey = model.did.exportPublic();
|
|
20
|
+
auth.credential = await model.did.sign(auth.challenge);
|
|
21
|
+
return auth;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
return model;
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=account.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAE/C,OAAO,EAAE,UAAU,EAAW,MAAM,sBAAsB,CAAA;AAE1D,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,GAAkC,EAAE,QAAiB,KAAK,EAAmB,EAAE;IACjH,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,IAAI,KAAK,EAAE,CAAC;YACV,GAAG,GAAG,eAAe,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAA;QAChD,CAAC;aAAM,CAAC;YACN,GAAG,GAAG,eAAe,CAAC,GAAG,CAAC,CAAA;QAC5B,CAAC;IACH,CAAC;SAAM,IAAI,CAAC,CAAC,SAAS,IAAI,GAAG,CAAC,EAAE,CAAC;QAC/B,GAAG,GAAG,eAAe,CAAC,GAAc,CAAC,CAAA;IACvC,CAAC;IACD,MAAM,KAAK,GAAoB;QAC7B,GAAG;QAEH,YAAY,EAAE,KAAK,EAAC,IAAI,EAAC,EAAE;YACzB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,aAAa,EAAE,CAAA;YACvC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,GAAG,CAAC,YAAY,EAAE,CAAA;YACzC,IAAI,CAAC,UAAU,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;YAEtD,OAAO,IAAI,CAAA;QACb,CAAC;KACF,CAAA;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DIDServiceDeps } from './types.js';
|
|
2
|
+
export declare const DEFAULT_ALIAS = "did-wallet";
|
|
3
|
+
export declare const DEF_KEYS_RESOURCE = "did-wallet-keys";
|
|
4
|
+
export declare const DEF_META_RESOURCE = "did-wallet-meta";
|
|
5
|
+
export declare const DEF_MASTER_RESOURCE = "did-wallet-master";
|
|
6
|
+
export declare const defDeps: DIDServiceDeps;
|
|
7
|
+
//# sourceMappingURL=consts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhD,eAAO,MAAM,aAAa,eAAe,CAAA;AAEzC,eAAO,MAAM,iBAAiB,oBAA0B,CAAA;AACxD,eAAO,MAAM,iBAAiB,oBAA0B,CAAA;AACxD,eAAO,MAAM,mBAAmB,sBAA4B,CAAA;AAE5D,eAAO,MAAM,OAAO,EAAE,cAIrB,CAAA"}
|
package/build/consts.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const DEFAULT_ALIAS = 'did-wallet';
|
|
2
|
+
export const DEF_KEYS_RESOURCE = `${DEFAULT_ALIAS}-keys`;
|
|
3
|
+
export const DEF_META_RESOURCE = `${DEFAULT_ALIAS}-meta`;
|
|
4
|
+
export const DEF_MASTER_RESOURCE = `${DEFAULT_ALIAS}-master`;
|
|
5
|
+
export const defDeps = {
|
|
6
|
+
keys: DEF_KEYS_RESOURCE,
|
|
7
|
+
meta: DEF_META_RESOURCE,
|
|
8
|
+
master: DEF_MASTER_RESOURCE
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=consts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,aAAa,GAAG,YAAY,CAAA;AAEzC,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,aAAa,OAAO,CAAA;AACxD,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,aAAa,OAAO,CAAA;AACxD,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,aAAa,SAAS,CAAA;AAE5D,MAAM,CAAC,MAAM,OAAO,GAAmB;IACrC,IAAI,EAAE,iBAAiB;IACvB,IAAI,EAAE,iBAAiB;IACvB,MAAM,EAAE,mBAAmB;CAC5B,CAAA"}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA"}
|
package/build/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { DIDService, DIDServiceAppend, DIDServiceDeps } from './types.js';
|
|
2
|
+
import type { ClientConfig } from '@owlmeans/client-context';
|
|
3
|
+
import type { ClientContext } from '@owlmeans/client';
|
|
4
|
+
export declare const makeWalletService: (alias?: string, deps?: DIDServiceDeps) => DIDService;
|
|
5
|
+
export declare const appendDidService: <C extends ClientConfig, T extends ClientContext<C>>(ctx: T, alias?: string, customDeps?: Partial<DIDServiceDeps>) => T & DIDServiceAppend;
|
|
6
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC9E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAK5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAErD,eAAO,MAAM,iBAAiB,WAAW,MAAM,SAAyB,cAAc,KAAG,UAoDxF,CAAA;AAED,eAAO,MAAM,gBAAgB,GAC3B,CAAC,SAAS,YAAY,EAAE,CAAC,SAAS,aAAa,CAAC,CAAC,CAAC,OAC7C,CAAC,UAAS,MAAM,eAA+B,OAAO,CAAC,cAAc,CAAC,KAAG,CAAC,GAAG,gBAoBnF,CAAA"}
|
package/build/service.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { assertContext, createLazyService } from '@owlmeans/context';
|
|
2
|
+
import { DEFAULT_ALIAS, defDeps } from './consts.js';
|
|
3
|
+
import { DIDInitializationError, makeWallet, MASTER } from '@owlmeans/did';
|
|
4
|
+
import { appendClientResource } from '@owlmeans/client-resource';
|
|
5
|
+
import { appendStateDebug } from '@owlmeans/client';
|
|
6
|
+
export const makeWalletService = (alias = DEFAULT_ALIAS, deps) => {
|
|
7
|
+
const location = `did-service:${alias}`;
|
|
8
|
+
deps = deps ?? defDeps;
|
|
9
|
+
const service = createLazyService(alias, {
|
|
10
|
+
exists: async () => {
|
|
11
|
+
const context = assertContext(service.ctx, location);
|
|
12
|
+
const resource = context.resource(deps.master);
|
|
13
|
+
return null != await resource.load(MASTER);
|
|
14
|
+
},
|
|
15
|
+
create: async (opts) => {
|
|
16
|
+
const context = assertContext(service.ctx, location);
|
|
17
|
+
if (await service.exists()) {
|
|
18
|
+
throw new DIDInitializationError('exists:service');
|
|
19
|
+
}
|
|
20
|
+
return service.wallet = await makeWallet({
|
|
21
|
+
keys: context.resource(deps.keys),
|
|
22
|
+
meta: context.resource(deps.meta),
|
|
23
|
+
master: context.resource(deps.master)
|
|
24
|
+
}, { force: true, ...opts });
|
|
25
|
+
},
|
|
26
|
+
intialize: async () => {
|
|
27
|
+
const context = assertContext(service.ctx, location);
|
|
28
|
+
return service.wallet = await makeWallet({
|
|
29
|
+
keys: context.resource(deps.keys),
|
|
30
|
+
meta: context.resource(deps.meta),
|
|
31
|
+
master: context.resource(deps.master)
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
get: () => service.wallet
|
|
35
|
+
}, service => async () => {
|
|
36
|
+
try {
|
|
37
|
+
const context = assertContext(service.ctx, location);
|
|
38
|
+
await context.resource(deps.keys).init?.();
|
|
39
|
+
if (service.wallet == null && await service.exists()) {
|
|
40
|
+
await service.intialize();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
console.error('DID Service initialization error', e);
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
service.initialized = true;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return service;
|
|
51
|
+
};
|
|
52
|
+
export const appendDidService = (ctx, alias = DEFAULT_ALIAS, customDeps) => {
|
|
53
|
+
const context = ctx;
|
|
54
|
+
const deps = {
|
|
55
|
+
keys: customDeps?.keys ?? `${alias}-keys`,
|
|
56
|
+
meta: customDeps?.meta ?? `${alias}-meta`,
|
|
57
|
+
master: customDeps?.master ?? `${alias}-master`
|
|
58
|
+
};
|
|
59
|
+
Object.values(deps).forEach(dep => !context.hasResource(dep) && appendClientResource(context, dep));
|
|
60
|
+
const service = makeWalletService(alias, deps);
|
|
61
|
+
context.registerService(service);
|
|
62
|
+
if (context.getDidService == null) {
|
|
63
|
+
context.getDidService = (_alias) => context.service(_alias ?? alias);
|
|
64
|
+
Object.values(deps).forEach(dep => appendStateDebug(ctx, dep));
|
|
65
|
+
}
|
|
66
|
+
return context;
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"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"}
|
package/build/types.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AuthCredentials } from '@owlmeans/auth';
|
|
2
|
+
import type { LazyService } from '@owlmeans/context';
|
|
3
|
+
import type { DIDKeyModel, DIDWallet, MakeDIDWalletOptions } from '@owlmeans/did';
|
|
4
|
+
export interface DIDService extends LazyService {
|
|
5
|
+
wallet: DIDWallet;
|
|
6
|
+
exists: () => Promise<boolean>;
|
|
7
|
+
create: (opts?: MakeDIDWalletOptions) => Promise<DIDWallet>;
|
|
8
|
+
intialize: () => Promise<DIDWallet>;
|
|
9
|
+
get: () => DIDWallet;
|
|
10
|
+
}
|
|
11
|
+
export interface DIDServiceAppend {
|
|
12
|
+
getDidService: (alias?: string) => DIDService;
|
|
13
|
+
}
|
|
14
|
+
export interface DIDServiceDeps {
|
|
15
|
+
keys: string;
|
|
16
|
+
meta: string;
|
|
17
|
+
master: string;
|
|
18
|
+
}
|
|
19
|
+
export interface DIDAccountModel {
|
|
20
|
+
did: DIDKeyModel;
|
|
21
|
+
authenticate: <T extends Partial<AuthCredentials>>(auth: T) => Promise<T>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AAEjF,MAAM,WAAW,UAAW,SAAQ,WAAW;IAC7C,MAAM,EAAE,SAAS,CAAA;IACjB,MAAM,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;IAC9B,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,oBAAoB,KAAK,OAAO,CAAC,SAAS,CAAC,CAAA;IAC3D,SAAS,EAAE,MAAM,OAAO,CAAC,SAAS,CAAC,CAAA;IACnC,GAAG,EAAE,MAAM,SAAS,CAAA;CACrB;AAED,MAAM,WAAW,gBAAgB;IAC/B,aAAa,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,UAAU,CAAA;CAC9C;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,WAAW,CAAA;IAChB,YAAY,EAAE,CAAC,CAAC,SAAS,OAAO,CAAC,eAAe,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAA;CAC1E"}
|
package/build/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@owlmeans/client-did",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "tsc -b",
|
|
7
|
+
"dev": "sleep 84 && nodemon -e ts,tsx,json --watch src --exec \"tsc -p ./tsconfig.json\"",
|
|
8
|
+
"watch": "tsc -b -w --preserveWatchOutput --pretty"
|
|
9
|
+
},
|
|
10
|
+
"main": "build/index.js",
|
|
11
|
+
"module": "build/index.js",
|
|
12
|
+
"types": "build/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"import": "./build/index.js",
|
|
16
|
+
"require": "./build/index.js",
|
|
17
|
+
"default": "./build/index.js",
|
|
18
|
+
"module": "./build/index.js",
|
|
19
|
+
"types": "./build/index.d.ts"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@owlmeans/auth": "^0.1.0",
|
|
24
|
+
"@owlmeans/client": "^0.1.0",
|
|
25
|
+
"@owlmeans/client-context": "^0.1.0",
|
|
26
|
+
"@owlmeans/client-resource": "^0.1.0",
|
|
27
|
+
"@owlmeans/context": "^0.1.0",
|
|
28
|
+
"@owlmeans/did": "^0.1.0",
|
|
29
|
+
"@owlmeans/state": "^0.1.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"nodemon": "^3.1.7",
|
|
33
|
+
"typescript": "^5.6.3"
|
|
34
|
+
},
|
|
35
|
+
"private": false,
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/src/account.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type{ DIDKeyModel } from '@owlmeans/did'
|
|
2
|
+
import { makeDidKeyModel } from '@owlmeans/did'
|
|
3
|
+
import type { DIDAccountModel } from './types.js'
|
|
4
|
+
import { fromPubKey, KeyPair } from '@owlmeans/basic-keys'
|
|
5
|
+
|
|
6
|
+
export const makeDidAccountModel = (did: KeyPair| DIDKeyModel | string, isPub: boolean = false): DIDAccountModel => {
|
|
7
|
+
if (typeof did === 'string') {
|
|
8
|
+
if (isPub) {
|
|
9
|
+
did = makeDidKeyModel(fromPubKey(did).keyPair)
|
|
10
|
+
} else {
|
|
11
|
+
did = makeDidKeyModel(did)
|
|
12
|
+
}
|
|
13
|
+
} else if (!("keyPair" in did)) {
|
|
14
|
+
did = makeDidKeyModel(did as KeyPair)
|
|
15
|
+
}
|
|
16
|
+
const model: DIDAccountModel = {
|
|
17
|
+
did,
|
|
18
|
+
|
|
19
|
+
authenticate: async auth => {
|
|
20
|
+
auth.userId = model.did.exportAddress()
|
|
21
|
+
auth.publicKey = model.did.exportPublic()
|
|
22
|
+
auth.credential = await model.did.sign(auth.challenge)
|
|
23
|
+
|
|
24
|
+
return auth
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return model
|
|
29
|
+
}
|
package/src/consts.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DIDServiceDeps } from './types.js'
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_ALIAS = 'did-wallet'
|
|
4
|
+
|
|
5
|
+
export const DEF_KEYS_RESOURCE = `${DEFAULT_ALIAS}-keys`
|
|
6
|
+
export const DEF_META_RESOURCE = `${DEFAULT_ALIAS}-meta`
|
|
7
|
+
export const DEF_MASTER_RESOURCE = `${DEFAULT_ALIAS}-master`
|
|
8
|
+
|
|
9
|
+
export const defDeps: DIDServiceDeps = {
|
|
10
|
+
keys: DEF_KEYS_RESOURCE,
|
|
11
|
+
meta: DEF_META_RESOURCE,
|
|
12
|
+
master: DEF_MASTER_RESOURCE
|
|
13
|
+
}
|
package/src/index.ts
ADDED
package/src/service.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { assertContext, createLazyService } from '@owlmeans/context'
|
|
2
|
+
import { DEFAULT_ALIAS, defDeps } from './consts.js'
|
|
3
|
+
import type { DIDService, DIDServiceAppend, DIDServiceDeps } from './types.js'
|
|
4
|
+
import type { ClientConfig } from '@owlmeans/client-context'
|
|
5
|
+
import type { KeyMetaResource, KeyPairResource, MasterResource } from '@owlmeans/did'
|
|
6
|
+
import { DIDInitializationError, makeWallet, MASTER } from '@owlmeans/did'
|
|
7
|
+
import { appendClientResource } from '@owlmeans/client-resource'
|
|
8
|
+
import { appendStateDebug } from '@owlmeans/client'
|
|
9
|
+
import type { ClientContext } from '@owlmeans/client'
|
|
10
|
+
|
|
11
|
+
export const makeWalletService = (alias: string = DEFAULT_ALIAS, deps?: DIDServiceDeps): DIDService => {
|
|
12
|
+
const location = `did-service:${alias}`
|
|
13
|
+
deps = deps ?? defDeps
|
|
14
|
+
|
|
15
|
+
const service: DIDService = createLazyService<DIDService>(alias, {
|
|
16
|
+
exists: async () => {
|
|
17
|
+
const context = assertContext(service.ctx, location) as ClientContext
|
|
18
|
+
const resource = context.resource<MasterResource>(deps.master)
|
|
19
|
+
|
|
20
|
+
return null != await resource.load(MASTER)
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
create: async opts => {
|
|
24
|
+
const context = assertContext(service.ctx, location) as ClientContext
|
|
25
|
+
|
|
26
|
+
if (await service.exists()) {
|
|
27
|
+
throw new DIDInitializationError('exists:service')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return service.wallet = await makeWallet({
|
|
31
|
+
keys: context.resource<KeyPairResource>(deps.keys),
|
|
32
|
+
meta: context.resource<KeyMetaResource>(deps.meta),
|
|
33
|
+
master: context.resource<MasterResource>(deps.master)
|
|
34
|
+
}, { force: true, ...opts })
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
intialize: async () => {
|
|
38
|
+
const context = assertContext(service.ctx, location) as ClientContext
|
|
39
|
+
|
|
40
|
+
return service.wallet = await makeWallet({
|
|
41
|
+
keys: context.resource<KeyPairResource>(deps.keys),
|
|
42
|
+
meta: context.resource<KeyMetaResource>(deps.meta),
|
|
43
|
+
master: context.resource<MasterResource>(deps.master)
|
|
44
|
+
})
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
get: () => service.wallet
|
|
48
|
+
}, service => async () => {
|
|
49
|
+
try {
|
|
50
|
+
const context = assertContext(service.ctx, location) as ClientContext
|
|
51
|
+
await context.resource(deps.keys).init?.()
|
|
52
|
+
if (service.wallet == null && await service.exists()) {
|
|
53
|
+
await service.intialize()
|
|
54
|
+
}
|
|
55
|
+
} catch (e) {
|
|
56
|
+
console.error('DID Service initialization error', e)
|
|
57
|
+
} finally {
|
|
58
|
+
service.initialized = true
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
return service
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const appendDidService = <
|
|
66
|
+
C extends ClientConfig, T extends ClientContext<C>
|
|
67
|
+
>(ctx: T, alias: string = DEFAULT_ALIAS, customDeps?: Partial<DIDServiceDeps>): T & DIDServiceAppend => {
|
|
68
|
+
const context = ctx as T & DIDServiceAppend
|
|
69
|
+
|
|
70
|
+
const deps: DIDServiceDeps = {
|
|
71
|
+
keys: customDeps?.keys ?? `${alias}-keys`,
|
|
72
|
+
meta: customDeps?.meta ?? `${alias}-meta`,
|
|
73
|
+
master: customDeps?.master ?? `${alias}-master`
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
Object.values(deps).forEach(dep => !context.hasResource(dep) && appendClientResource<C, T>(context, dep))
|
|
77
|
+
|
|
78
|
+
const service = makeWalletService(alias, deps)
|
|
79
|
+
context.registerService(service)
|
|
80
|
+
|
|
81
|
+
if (context.getDidService == null) {
|
|
82
|
+
context.getDidService = (_alias?: string) => context.service<DIDService>(_alias ?? alias)
|
|
83
|
+
Object.values(deps).forEach(dep => appendStateDebug<C, T>(ctx, dep))
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return context
|
|
87
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AuthCredentials } from '@owlmeans/auth'
|
|
2
|
+
import type { LazyService } from '@owlmeans/context'
|
|
3
|
+
import type { DIDKeyModel, DIDWallet, MakeDIDWalletOptions } from '@owlmeans/did'
|
|
4
|
+
|
|
5
|
+
export interface DIDService extends LazyService {
|
|
6
|
+
wallet: DIDWallet
|
|
7
|
+
exists: () => Promise<boolean>
|
|
8
|
+
create: (opts?: MakeDIDWalletOptions) => Promise<DIDWallet>
|
|
9
|
+
intialize: () => Promise<DIDWallet>
|
|
10
|
+
get: () => DIDWallet
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface DIDServiceAppend {
|
|
14
|
+
getDidService: (alias?: string) => DIDService
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface DIDServiceDeps {
|
|
18
|
+
keys: string
|
|
19
|
+
meta: string
|
|
20
|
+
master: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface DIDAccountModel {
|
|
24
|
+
did: DIDKeyModel
|
|
25
|
+
authenticate: <T extends Partial<AuthCredentials>>(auth: T) => Promise<T>
|
|
26
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": [
|
|
3
|
+
"../tsconfig.default.json",
|
|
4
|
+
"../tsconfig.react.json",
|
|
5
|
+
],
|
|
6
|
+
"compilerOptions": {
|
|
7
|
+
"rootDir": "./src/", /* Specify the root folder within your source files. */
|
|
8
|
+
"outDir": "./build/", /* Specify an output folder for all emitted files. */
|
|
9
|
+
},
|
|
10
|
+
"exclude": [
|
|
11
|
+
"./dist/**/*",
|
|
12
|
+
"./build/**/*",
|
|
13
|
+
"./*.ts"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["./src/account.ts","./src/consts.ts","./src/index.ts","./src/service.ts","./src/types.ts"],"version":"5.6.3"}
|