@credebl/ssi-mobile-core 2.0.3-alpha-20260331140428 → 2.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/README.md +441 -122
- package/build/MobileSDK.d.mts +9 -2
- package/build/MobileSDK.d.mts.map +1 -1
- package/build/MobileSDK.mjs +12 -4
- package/build/MobileSDK.mjs.map +1 -1
- package/build/index.d.mts +2 -2
- package/build/index.mjs +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,194 +1,513 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @credebl/ssi-mobile-core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Core package for the CREDEBL Mobile SDK. Handles wallet initialization, DID operations, credential storage, key management, and React context integration.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
See the [root README](../../README.md) for prerequisites and project-level setup.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- **Type Safety**: Full TypeScript support with proper typing
|
|
9
|
-
- **State Management**: Built-in state management for SDK initialization
|
|
10
|
-
- **React Integration**: Follows React best practices and patterns
|
|
7
|
+
---
|
|
11
8
|
|
|
12
9
|
## Installation
|
|
13
10
|
|
|
14
11
|
```bash
|
|
15
|
-
npm install @credebl/mobile-
|
|
12
|
+
npm install @credebl/ssi-mobile-core @openwallet-foundation/askar-react-native
|
|
16
13
|
# or
|
|
17
|
-
yarn add @credebl/mobile-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
yarn add @credebl/ssi-mobile-core @openwallet-foundation/askar-react-native
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
**iOS:**
|
|
18
|
+
```bash
|
|
19
|
+
cd ios && pod install
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
**Android** — ensure `minSdkVersion` >= 24 in `android/app/build.gradle`.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## API Reference
|
|
27
|
+
|
|
28
|
+
### Setup
|
|
29
|
+
|
|
30
|
+
#### `MobileSDKProvider`
|
|
23
31
|
|
|
24
|
-
|
|
32
|
+
Wrap your entire app with this provider. Every hook in this package must be used inside it.
|
|
25
33
|
|
|
26
34
|
```tsx
|
|
27
|
-
import {
|
|
35
|
+
import { MobileSDKProvider } from '@credebl/ssi-mobile-core'
|
|
28
36
|
|
|
29
|
-
function App() {
|
|
37
|
+
export default function App() {
|
|
30
38
|
return (
|
|
31
|
-
<
|
|
32
|
-
{/*
|
|
33
|
-
</
|
|
34
|
-
)
|
|
39
|
+
<MobileSDKProvider>
|
|
40
|
+
{/* your app */}
|
|
41
|
+
</MobileSDKProvider>
|
|
42
|
+
)
|
|
35
43
|
}
|
|
36
44
|
```
|
|
37
45
|
|
|
38
|
-
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
#### `useMobileSDKInitializer()`
|
|
49
|
+
|
|
50
|
+
Initializes the SDK. Call this once on app startup, inside `MobileSDKProvider`.
|
|
39
51
|
|
|
40
52
|
```tsx
|
|
41
|
-
import {
|
|
53
|
+
import { useEffect } from 'react'
|
|
54
|
+
import { useMobileSDKInitializer, ConsoleLogger, LogLevel } from '@credebl/ssi-mobile-core'
|
|
42
55
|
|
|
43
56
|
function AppInitializer() {
|
|
44
|
-
const { initializeSDK, isInitialized } =
|
|
57
|
+
const { initializeSDK, isInitialized } = useMobileSDKInitializer()
|
|
45
58
|
|
|
46
59
|
useEffect(() => {
|
|
47
60
|
if (!isInitialized) {
|
|
48
|
-
initializeSDK(
|
|
61
|
+
initializeSDK({
|
|
62
|
+
agentConfig: {
|
|
63
|
+
label: 'My Wallet',
|
|
64
|
+
logger: new ConsoleLogger(LogLevel.debug),
|
|
65
|
+
},
|
|
66
|
+
askarConfig: {
|
|
67
|
+
id: 'my-wallet-id',
|
|
68
|
+
key: 'my-wallet-key',
|
|
69
|
+
},
|
|
70
|
+
modules: {},
|
|
71
|
+
})
|
|
49
72
|
}
|
|
50
|
-
}, [
|
|
73
|
+
}, [isInitialized])
|
|
51
74
|
|
|
52
|
-
return null
|
|
75
|
+
return null
|
|
53
76
|
}
|
|
54
77
|
```
|
|
55
78
|
|
|
56
|
-
|
|
79
|
+
| Return value | Type | Description |
|
|
80
|
+
|---|---|---|
|
|
81
|
+
| `initializeSDK` | `(options) => Promise<MobileSDK>` | Call with your config to start the SDK |
|
|
82
|
+
| `isInitialized` | `boolean` | `true` once the SDK is ready |
|
|
83
|
+
| `sdk` | `MobileSDK \| null` | The SDK instance after initialization |
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
#### `useMobileSDK()`
|
|
88
|
+
|
|
89
|
+
Access the SDK instance from any component inside `MobileSDKProvider`.
|
|
57
90
|
|
|
58
91
|
```tsx
|
|
59
|
-
import {
|
|
92
|
+
import { useMobileSDK } from '@credebl/ssi-mobile-core'
|
|
60
93
|
|
|
61
|
-
function
|
|
62
|
-
const { sdk, isInitialized } =
|
|
63
|
-
|
|
64
|
-
if (!isInitialized || !sdk)
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const handleAction = () => {
|
|
69
|
-
// Use sdk methods here
|
|
70
|
-
console.log('SDK is ready:', sdk);
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
return <button onClick={handleAction}>Perform Action</button>;
|
|
94
|
+
function MyComponent() {
|
|
95
|
+
const { sdk, isInitialized } = useMobileSDK()
|
|
96
|
+
|
|
97
|
+
if (!isInitialized || !sdk) return <Text>Loading...</Text>
|
|
98
|
+
|
|
99
|
+
return <Button title="Ready" onPress={() => console.log(sdk)} />
|
|
74
100
|
}
|
|
75
101
|
```
|
|
76
102
|
|
|
77
|
-
|
|
103
|
+
When using extra modules (like DIDComm), pass the module type:
|
|
78
104
|
|
|
79
|
-
|
|
105
|
+
```tsx
|
|
106
|
+
import { DidCommSDK } from '@credebl/ssi-mobile-didcomm'
|
|
107
|
+
|
|
108
|
+
type AppModules = { didcomm: DidCommSDK }
|
|
109
|
+
|
|
110
|
+
const { sdk } = useMobileSDK<AppModules>()
|
|
111
|
+
// sdk.modules.didcomm is now typed correctly
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
| Return value | Type | Description |
|
|
115
|
+
|---|---|---|
|
|
116
|
+
| `sdk` | `MobileSDK<T>` | The initialized SDK instance |
|
|
117
|
+
| `isInitialized` | `boolean` | `true` once the SDK is ready |
|
|
118
|
+
| `initialize` | `(sdk) => void` | Manually set the SDK (advanced use) |
|
|
119
|
+
| `shutdown` | `() => void` | Shut down the SDK |
|
|
80
120
|
|
|
81
|
-
|
|
121
|
+
---
|
|
82
122
|
|
|
83
|
-
|
|
84
|
-
- `children`: React nodes to be wrapped by the provider
|
|
123
|
+
#### `MobileSDK.AppProvider`
|
|
85
124
|
|
|
86
|
-
|
|
125
|
+
Provides the underlying `Agent` to credential and record hooks. Wrap the parts of your app that use credential hooks with this.
|
|
87
126
|
|
|
88
|
-
|
|
127
|
+
```tsx
|
|
128
|
+
import { MobileSDK } from '@credebl/ssi-mobile-core'
|
|
89
129
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
130
|
+
function App() {
|
|
131
|
+
return (
|
|
132
|
+
<MobileSDKProvider>
|
|
133
|
+
<MobileSDK.AppProvider>
|
|
134
|
+
{/* hooks like useW3cCredentialRecords() work here */}
|
|
135
|
+
</MobileSDK.AppProvider>
|
|
136
|
+
</MobileSDKProvider>
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
```
|
|
94
140
|
|
|
95
|
-
|
|
141
|
+
---
|
|
96
142
|
|
|
97
|
-
|
|
143
|
+
### DID Operations
|
|
98
144
|
|
|
99
|
-
|
|
100
|
-
- `initializeSDK`: Function to initialize the SDK
|
|
101
|
-
- `isInitialized`: Boolean indicating if the SDK is initialized
|
|
145
|
+
All methods below are called on the `sdk` instance returned by `useMobileSDK()`.
|
|
102
146
|
|
|
103
|
-
|
|
147
|
+
#### `sdk.createDid(options)`
|
|
104
148
|
|
|
105
|
-
|
|
149
|
+
Create a new DID and store it in the wallet.
|
|
106
150
|
|
|
107
151
|
```tsx
|
|
108
|
-
|
|
109
|
-
|
|
152
|
+
// Create a did:key
|
|
153
|
+
const didRecord = await sdk.createDid({ method: 'key' })
|
|
154
|
+
|
|
155
|
+
// Create a did:jwk with a specific key type
|
|
156
|
+
const didRecord = await sdk.createDid({
|
|
157
|
+
method: 'jwk',
|
|
158
|
+
options: { keyType: 'Ed25519' },
|
|
159
|
+
})
|
|
160
|
+
```
|
|
110
161
|
|
|
111
|
-
|
|
112
|
-
function SDKInitializer() {
|
|
113
|
-
const { initializeSDK, isInitialized } = useSDKInitializer();
|
|
162
|
+
---
|
|
114
163
|
|
|
115
|
-
|
|
116
|
-
if (!isInitialized) {
|
|
117
|
-
initializeSDK();
|
|
118
|
-
}
|
|
119
|
-
}, [initializeSDK, isInitialized]);
|
|
164
|
+
#### `sdk.getDids(options?)`
|
|
120
165
|
|
|
121
|
-
|
|
122
|
-
}
|
|
166
|
+
Retrieve DIDs that were created by this wallet.
|
|
123
167
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
168
|
+
```tsx
|
|
169
|
+
// Get all DIDs
|
|
170
|
+
const dids = await sdk.getDids({})
|
|
127
171
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
172
|
+
// Filter by method
|
|
173
|
+
const keyDids = await sdk.getDids({ method: 'key' })
|
|
131
174
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
<p>SDK instance: {sdk.constructor.name}</p>
|
|
136
|
-
</div>
|
|
137
|
-
);
|
|
138
|
-
}
|
|
175
|
+
// Look up a specific DID
|
|
176
|
+
const dids = await sdk.getDids({ did: 'did:key:z6Mk...' })
|
|
177
|
+
```
|
|
139
178
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
<SDKUser />
|
|
146
|
-
</SDKProvider>
|
|
147
|
-
);
|
|
148
|
-
}
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
#### `sdk.resolveDid({ did })`
|
|
182
|
+
|
|
183
|
+
Resolve a DID document — works for any DID, not just ones in the wallet.
|
|
149
184
|
|
|
150
|
-
|
|
185
|
+
```tsx
|
|
186
|
+
const result = await sdk.resolveDid({ did: 'did:key:z6Mk...' })
|
|
187
|
+
console.log(result.didDocument)
|
|
151
188
|
```
|
|
152
189
|
|
|
153
|
-
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
#### `sdk.addTagToDid({ did, tag, tagValue })`
|
|
154
193
|
|
|
155
|
-
|
|
194
|
+
Attach a custom tag to a DID record so you can look it up later.
|
|
156
195
|
|
|
157
196
|
```tsx
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
197
|
+
await sdk.addTagToDid({
|
|
198
|
+
did: 'did:key:z6Mk...',
|
|
199
|
+
tag: 'purpose',
|
|
200
|
+
tagValue: 'authentication',
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
// Later, find it by tag
|
|
204
|
+
const dids = await sdk.getDids({ tag: 'purpose', tagValue: 'authentication' })
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
### Credential Storage
|
|
210
|
+
|
|
211
|
+
#### `sdk.deleteCredential({ id, format })`
|
|
212
|
+
|
|
213
|
+
Delete a stored credential by ID and format.
|
|
214
|
+
|
|
215
|
+
```tsx
|
|
216
|
+
import { CredentialRecord } from '@credebl/ssi-mobile-core'
|
|
217
|
+
|
|
218
|
+
await sdk.deleteCredential({
|
|
219
|
+
id: 'credential-id',
|
|
220
|
+
format: CredentialRecord.SdJwt, // or CredentialRecord.Mdoc / CredentialRecord.W3c
|
|
221
|
+
})
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
#### `sdk.storeOpenIdCredential(credential)`
|
|
227
|
+
|
|
228
|
+
Manually store a credential record received via OpenID4VC.
|
|
229
|
+
|
|
230
|
+
```tsx
|
|
231
|
+
// credential is a W3cCredentialRecord, SdJwtVcRecord, or MdocRecord
|
|
232
|
+
await sdk.storeOpenIdCredential(credentialRecord)
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
#### `sdk.setTagsToCredential({ credId, tags, format? })`
|
|
238
|
+
|
|
239
|
+
Attach custom tags to a credential for later filtering.
|
|
240
|
+
|
|
241
|
+
```tsx
|
|
242
|
+
await sdk.setTagsToCredential({
|
|
243
|
+
credId: 'credential-id',
|
|
244
|
+
tags: { status: 'active', issuer: 'university' },
|
|
245
|
+
})
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
#### `sdk.getCredentialsByTag({ tags, format? })`
|
|
251
|
+
|
|
252
|
+
Query credentials by their custom tags.
|
|
253
|
+
|
|
254
|
+
```tsx
|
|
255
|
+
const creds = await sdk.getCredentialsByTag({
|
|
256
|
+
tags: { status: 'active' },
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
// Filter by format
|
|
260
|
+
const sdJwtCreds = await sdk.getCredentialsByTag({
|
|
261
|
+
tags: { issuer: 'university' },
|
|
262
|
+
format: CredentialRecord.SdJwt,
|
|
263
|
+
})
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
### Generic Records
|
|
269
|
+
|
|
270
|
+
Use generic records to store arbitrary structured data in the wallet (e.g. app settings, user preferences, custom metadata).
|
|
271
|
+
|
|
272
|
+
#### `sdk.addGenericRecord({ content, tags?, id? })`
|
|
273
|
+
|
|
274
|
+
```tsx
|
|
275
|
+
const record = await sdk.addGenericRecord({
|
|
276
|
+
content: { theme: 'dark', notifications: true },
|
|
277
|
+
tags: { type: 'settings' },
|
|
278
|
+
})
|
|
279
|
+
console.log(record.id)
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
---
|
|
283
|
+
|
|
284
|
+
#### `sdk.getGenericRecord(id)`
|
|
285
|
+
|
|
286
|
+
```tsx
|
|
287
|
+
const record = await sdk.getGenericRecord(record.id)
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
#### `sdk.findGenericRecordsByQuery(query)`
|
|
293
|
+
|
|
294
|
+
```tsx
|
|
295
|
+
const records = await sdk.findGenericRecordsByQuery({ type: 'settings' })
|
|
165
296
|
```
|
|
166
297
|
|
|
167
|
-
|
|
298
|
+
---
|
|
299
|
+
|
|
300
|
+
#### `sdk.updateGenericRecord(record)`
|
|
301
|
+
|
|
302
|
+
```tsx
|
|
303
|
+
record.content.theme = 'light'
|
|
304
|
+
await sdk.updateGenericRecord(record)
|
|
305
|
+
```
|
|
168
306
|
|
|
169
|
-
|
|
170
|
-
2. **Error Boundaries**: Wrap your app with error boundaries to handle SDK initialization errors
|
|
171
|
-
3. **Loading States**: Always check `isInitialized` before using the SDK
|
|
172
|
-
4. **Type Safety**: Use TypeScript for better development experience and error catching
|
|
307
|
+
---
|
|
173
308
|
|
|
174
|
-
|
|
309
|
+
#### `sdk.deleteGenericRecord(id)`
|
|
175
310
|
|
|
176
|
-
|
|
311
|
+
```tsx
|
|
312
|
+
await sdk.deleteGenericRecord(record.id)
|
|
313
|
+
```
|
|
177
314
|
|
|
178
|
-
|
|
179
|
-
- Ensure your component is wrapped with SDKProvider
|
|
180
|
-
- Check that the provider is imported correctly
|
|
315
|
+
---
|
|
181
316
|
|
|
182
|
-
|
|
183
|
-
- Verify that `initializeSDK()` is being called
|
|
184
|
-
- Check browser console for any errors
|
|
185
|
-
- Ensure all required dependencies are installed
|
|
317
|
+
### Wallet Management
|
|
186
318
|
|
|
187
|
-
|
|
188
|
-
- Make sure you're using TypeScript
|
|
189
|
-
- Check that all imports are correct
|
|
190
|
-
- Verify that the MobileSDK class is properly exported
|
|
319
|
+
#### `sdk.exportWallet(exportToStore)`
|
|
191
320
|
|
|
192
|
-
|
|
321
|
+
Export the wallet to a different storage location (useful for backup).
|
|
193
322
|
|
|
194
|
-
|
|
323
|
+
```tsx
|
|
324
|
+
await sdk.exportWallet({
|
|
325
|
+
id: 'backup-wallet-id',
|
|
326
|
+
key: 'backup-wallet-key',
|
|
327
|
+
path: '/path/to/backup/file',
|
|
328
|
+
})
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
---
|
|
332
|
+
|
|
333
|
+
### Key Management
|
|
334
|
+
|
|
335
|
+
#### `sdk.createKey(options)`
|
|
336
|
+
|
|
337
|
+
Create a cryptographic key pair stored in the wallet.
|
|
338
|
+
|
|
339
|
+
```tsx
|
|
340
|
+
const keyPair = await sdk.createKey({ keyType: 'Ed25519' })
|
|
341
|
+
console.log(keyPair.keyId)
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
---
|
|
345
|
+
|
|
346
|
+
#### `sdk.signData(options)`
|
|
347
|
+
|
|
348
|
+
Sign data with a key from the wallet.
|
|
349
|
+
|
|
350
|
+
```tsx
|
|
351
|
+
const signature = await sdk.signData({
|
|
352
|
+
keyId: keyPair.keyId,
|
|
353
|
+
data: new Uint8Array([1, 2, 3]),
|
|
354
|
+
})
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
#### `sdk.verifyData(options)`
|
|
360
|
+
|
|
361
|
+
Verify that a signature was produced by a given key.
|
|
362
|
+
|
|
363
|
+
```tsx
|
|
364
|
+
const isValid = await sdk.verifyData({
|
|
365
|
+
keyId: keyPair.keyId,
|
|
366
|
+
data: new Uint8Array([1, 2, 3]),
|
|
367
|
+
signature,
|
|
368
|
+
})
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
---
|
|
372
|
+
|
|
373
|
+
#### `sdk.createJwsCompact({ header, payload, keyId })`
|
|
374
|
+
|
|
375
|
+
Create a compact JWS (JSON Web Signature) token.
|
|
376
|
+
|
|
377
|
+
```tsx
|
|
378
|
+
const jws = await sdk.createJwsCompact({
|
|
379
|
+
header: { alg: 'EdDSA' },
|
|
380
|
+
payload: { sub: 'user-123', iat: Math.floor(Date.now() / 1000) },
|
|
381
|
+
keyId: keyPair.keyId,
|
|
382
|
+
})
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
---
|
|
386
|
+
|
|
387
|
+
### React Hooks — Credential Records
|
|
388
|
+
|
|
389
|
+
These hooks give real-time reactive access to credentials stored in the wallet. They update automatically when credentials are added, updated, or deleted.
|
|
390
|
+
|
|
391
|
+
> Must be used inside `MobileSDK.AppProvider`.
|
|
392
|
+
|
|
393
|
+
#### `useW3cCredentialRecords()`
|
|
394
|
+
|
|
395
|
+
Subscribe to all W3C credential records.
|
|
396
|
+
|
|
397
|
+
```tsx
|
|
398
|
+
import { useW3cCredentialRecords } from '@credebl/ssi-mobile-core'
|
|
399
|
+
|
|
400
|
+
const { w3cCredentialRecords, isLoading } = useW3cCredentialRecords()
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
#### `useW3cCredentialRecordById(id)`
|
|
404
|
+
|
|
405
|
+
```tsx
|
|
406
|
+
const record = useW3cCredentialRecordById('record-id')
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
---
|
|
410
|
+
|
|
411
|
+
#### `useSdJwtVcRecords()`
|
|
412
|
+
|
|
413
|
+
Subscribe to all SD-JWT credential records.
|
|
414
|
+
|
|
415
|
+
```tsx
|
|
416
|
+
import { useSdJwtVcRecords } from '@credebl/ssi-mobile-core'
|
|
417
|
+
|
|
418
|
+
const { sdJwtVcRecords, isLoading } = useSdJwtVcRecords()
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
#### `useSdJwtVcRecordById(id)`
|
|
422
|
+
|
|
423
|
+
```tsx
|
|
424
|
+
const record = useSdJwtVcRecordById('record-id')
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
---
|
|
428
|
+
|
|
429
|
+
#### `useMdocRecords()`
|
|
430
|
+
|
|
431
|
+
Subscribe to all mDoc credential records.
|
|
432
|
+
|
|
433
|
+
```tsx
|
|
434
|
+
import { useMdocRecords } from '@credebl/ssi-mobile-core'
|
|
435
|
+
|
|
436
|
+
const { mdocRecords, isLoading } = useMdocRecords()
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
#### `useMdocRecordById(id)`
|
|
440
|
+
|
|
441
|
+
```tsx
|
|
442
|
+
const record = useMdocRecordById('record-id')
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
---
|
|
446
|
+
|
|
447
|
+
#### `useGenericRecords(options?)`
|
|
448
|
+
|
|
449
|
+
Subscribe to generic records, with optional tag filtering.
|
|
450
|
+
|
|
451
|
+
```tsx
|
|
452
|
+
import { useGenericRecords } from '@credebl/ssi-mobile-core'
|
|
453
|
+
|
|
454
|
+
const { genericRecords, isLoading } = useGenericRecords({
|
|
455
|
+
filterByTagKey: 'type',
|
|
456
|
+
filterByTags: { type: 'settings' },
|
|
457
|
+
})
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
#### `useGenericRecordById(id)`
|
|
461
|
+
|
|
462
|
+
```tsx
|
|
463
|
+
const record = useGenericRecordById('record-id')
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
---
|
|
467
|
+
|
|
468
|
+
### Wallet Utilities
|
|
469
|
+
|
|
470
|
+
These are standalone functions — no hook or SDK instance needed.
|
|
471
|
+
|
|
472
|
+
#### `isWalletPinCorrect(storeConfig)`
|
|
473
|
+
|
|
474
|
+
Check if a wallet key is correct before opening. Useful for PIN verification screens.
|
|
475
|
+
|
|
476
|
+
```tsx
|
|
477
|
+
import { isWalletPinCorrect } from '@credebl/ssi-mobile-core'
|
|
478
|
+
|
|
479
|
+
const isCorrect = await isWalletPinCorrect({
|
|
480
|
+
id: 'wallet-id',
|
|
481
|
+
key: 'entered-pin',
|
|
482
|
+
})
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
---
|
|
486
|
+
|
|
487
|
+
#### `isWalletImportable(storeConfig, importFromStore)`
|
|
488
|
+
|
|
489
|
+
Check whether a wallet backup file can be imported before attempting the import.
|
|
490
|
+
|
|
491
|
+
```tsx
|
|
492
|
+
import { isWalletImportable } from '@credebl/ssi-mobile-core'
|
|
493
|
+
|
|
494
|
+
const canImport = await isWalletImportable(
|
|
495
|
+
{ id: 'new-wallet', key: 'new-wallet-key' },
|
|
496
|
+
{ id: 'backup-wallet', key: 'backup-key', path: '/path/to/backup' }
|
|
497
|
+
)
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
---
|
|
501
|
+
|
|
502
|
+
#### `importWalletToStore(storeConfig, importFromStore)`
|
|
503
|
+
|
|
504
|
+
Import a wallet from a backup file.
|
|
505
|
+
|
|
506
|
+
```tsx
|
|
507
|
+
import { importWalletToStore } from '@credebl/ssi-mobile-core'
|
|
508
|
+
|
|
509
|
+
await importWalletToStore(
|
|
510
|
+
{ id: 'new-wallet', key: 'new-wallet-key' },
|
|
511
|
+
{ id: 'backup-wallet', key: 'backup-key', path: '/path/to/backup' }
|
|
512
|
+
)
|
|
513
|
+
```
|
package/build/MobileSDK.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JSX } from "./node_modules/.pnpm/@types_react@19.2.14/node_modules/@types/react/jsx-runtime.mjs";
|
|
2
2
|
import * as _credo_ts_core0 from "@credo-ts/core";
|
|
3
|
-
import { Agent, CacheModule, DidCreateOptions, DidsModule, GenericRecord, GenericRecordTags, InitConfig, JwsProtectedHeaderOptions, JwtPayload, MdocRecord, ModulesMap, Query, QueryOptions, SdJwtVcRecord, TagValue, W3cCredentialRecord } from "@credo-ts/core";
|
|
3
|
+
import { Agent, CacheModule, DidCreateOptions, DidRegistrar, DidResolver, DidsModule, GenericRecord, GenericRecordTags, InitConfig, JwsProtectedHeaderOptions, JwtPayload, MdocRecord, ModulesMap, Query, QueryOptions, SdJwtVcRecord, TagValue, W3cCredentialRecord } from "@credo-ts/core";
|
|
4
4
|
import { AskarModule, AskarModuleConfigStoreOptions } from "@credo-ts/askar";
|
|
5
5
|
import * as _credo_ts_core_kms0 from "@credo-ts/core/kms";
|
|
6
6
|
import { KmsCreateKeyOptions, KmsCreateKeyType, KmsSignOptions, KmsVerifyOptions } from "@credo-ts/core/kms";
|
|
@@ -18,7 +18,10 @@ declare enum CredentialRecord {
|
|
|
18
18
|
Mdoc = "mdoc",
|
|
19
19
|
W3c = "w3c"
|
|
20
20
|
}
|
|
21
|
-
declare const getCoreModules: (askarConfig: AskarModuleConfigStoreOptions
|
|
21
|
+
declare const getCoreModules: (askarConfig: AskarModuleConfigStoreOptions, dids?: {
|
|
22
|
+
registrars?: DidRegistrar[];
|
|
23
|
+
resolvers?: DidResolver[];
|
|
24
|
+
}) => {
|
|
22
25
|
askar: AskarModule;
|
|
23
26
|
dids: DidsModule;
|
|
24
27
|
cache: CacheModule;
|
|
@@ -32,6 +35,10 @@ type MobileSDKOptions<T extends Record<string, MobileSDKModule> = Record<string,
|
|
|
32
35
|
askarConfig: AskarModuleConfigStoreOptions;
|
|
33
36
|
modules: T;
|
|
34
37
|
defaultModules?: ModulesMap;
|
|
38
|
+
dids?: {
|
|
39
|
+
registrars?: DidRegistrar[];
|
|
40
|
+
resolvers?: DidResolver[];
|
|
41
|
+
};
|
|
35
42
|
};
|
|
36
43
|
declare class MobileSDK<T extends Record<string, MobileSDKModule> = Record<string, MobileSDKModule>> {
|
|
37
44
|
private localAgent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileSDK.d.mts","names":[],"sources":["../src/MobileSDK.tsx"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"MobileSDK.d.mts","names":[],"sources":["../src/MobileSDK.tsx"],"mappings":";;;;;;;;KAsCY,WAAA,MAAiB,CAAA;;;;AAA7B;EAKE,OAAA;AAAA;AAAA,aAGU,gBAAA;EACV,KAAA;EACA,IAAA;EACA,GAAA;AAAA;AAAA,cAEI,cAAA,GACJ,WAAA,EAAa,6BAAA,EACb,IAAA;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AM,OAAA,CAAA,mBAAA,CAAA,kBAAA,CAAA,IAAA;EAKxF,QAAA,CAAS,OAAA,EAAS,WAAA,CAAY,cAAA,IAAe,OAAA,CAAhB,mBAAA,CAAgB,aAAA;EAK7C,UAAA,CAAW,OAAA,EAAS,WAAA,CAAY,gBAAA,IAAiB,OAAA,CAAlB,mBAAA,CAAkB,eAAA;EAKjD,gBAAA,CAAA;IACX,MAAA;IACA,OAAA;IACA;EAAA;IAEA,MAAA,EAAQ,yBAAA;IACR,OAAA,EAAS,UAAA;IACT,KAAA;EAAA,IACD,OAAA;AAAA"}
|
package/build/MobileSDK.mjs
CHANGED
|
@@ -14,7 +14,7 @@ let CredentialRecord = /* @__PURE__ */ function(CredentialRecord) {
|
|
|
14
14
|
CredentialRecord["W3c"] = "w3c";
|
|
15
15
|
return CredentialRecord;
|
|
16
16
|
}({});
|
|
17
|
-
const getCoreModules = (askarConfig) => {
|
|
17
|
+
const getCoreModules = (askarConfig, dids) => {
|
|
18
18
|
return {
|
|
19
19
|
askar: new AskarModule({
|
|
20
20
|
askar,
|
|
@@ -25,8 +25,16 @@ const getCoreModules = (askarConfig) => {
|
|
|
25
25
|
}
|
|
26
26
|
}),
|
|
27
27
|
dids: new DidsModule({
|
|
28
|
-
registrars: [
|
|
29
|
-
|
|
28
|
+
registrars: [
|
|
29
|
+
new JwkDidRegistrar(),
|
|
30
|
+
new KeyDidRegistrar(),
|
|
31
|
+
...dids?.registrars ?? []
|
|
32
|
+
],
|
|
33
|
+
resolvers: [
|
|
34
|
+
new JwkDidResolver(),
|
|
35
|
+
new KeyDidResolver(),
|
|
36
|
+
...dids?.resolvers ?? []
|
|
37
|
+
]
|
|
30
38
|
}),
|
|
31
39
|
cache: new CacheModule({ cache: new SingleContextStorageLruCache({ limit: 50 }) })
|
|
32
40
|
};
|
|
@@ -46,7 +54,7 @@ var MobileSDK = class MobileSDK {
|
|
|
46
54
|
}
|
|
47
55
|
async initialize() {
|
|
48
56
|
const defaultModules = this.configuration.defaultModules ?? {};
|
|
49
|
-
const coreModules = getCoreModules(this.configuration.askarConfig);
|
|
57
|
+
const coreModules = getCoreModules(this.configuration.askarConfig, this.configuration.dids);
|
|
50
58
|
Object.assign(defaultModules, coreModules);
|
|
51
59
|
const modules = Object.entries(this.configuration.modules).reduce((acc, [, module]) => {
|
|
52
60
|
const moduleModules = module.getAgentModules();
|
package/build/MobileSDK.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileSDK.mjs","names":["AgentProvider"],"sources":["../src/MobileSDK.tsx"],"sourcesContent":["import { AskarModule, type AskarModuleConfigStoreOptions } from '@credo-ts/askar'\nimport {\n Agent,\n CacheModule,\n type DidCreateOptions,\n DidRepository,\n DidsModule,\n GenericRecord,\n GenericRecordTags,\n type InitConfig,\n JwkDidRegistrar,\n JwkDidResolver,\n JwsProtectedHeaderOptions,\n JwsService,\n JwtPayload,\n KeyDidRegistrar,\n KeyDidResolver,\n MdocRecord,\n MdocRepository,\n type ModulesMap,\n type Query,\n type QueryOptions,\n SdJwtVcRecord,\n SdJwtVcRepository,\n SingleContextStorageLruCache,\n type TagValue,\n W3cCredentialRecord,\n W3cCredentialRepository,\n} from '@credo-ts/core'\nimport { KmsCreateKeyOptions, KmsCreateKeyType, KmsSignOptions, KmsVerifyOptions } from '@credo-ts/core/kms'\nimport { agentDependencies } from '@credo-ts/react-native'\nimport { askar } from '@openwallet-foundation/askar-react-native'\nimport type { PropsWithChildren } from 'react'\nimport { useMobileSDK } from './contexts'\nimport AgentProvider from './providers/AgentProvider'\n\nexport type WithBackend<T> = T & {\n /**\n * The backend to use for creating the key. If not provided the\n * default backend for key operations will be used.\n */\n backend?: string\n}\n\nexport enum CredentialRecord {\n SdJwt = 'sd-jwt',\n Mdoc = 'mdoc',\n W3c = 'w3c',\n}\nconst getCoreModules = (askarConfig: AskarModuleConfigStoreOptions) => {\n return {\n askar: new AskarModule({\n askar,\n store: {\n id: askarConfig.id,\n key: askarConfig.key,\n keyDerivationMethod: askarConfig.keyDerivationMethod === 'raw' ? 'raw' : 'kdf:argon2i:mod',\n },\n }),\n dids: new DidsModule({\n registrars: [new JwkDidRegistrar(), new KeyDidRegistrar()],\n resolvers: [new JwkDidResolver(), new KeyDidResolver()],\n }),\n cache: new CacheModule({\n cache: new SingleContextStorageLruCache({\n limit: 50,\n }),\n }),\n }\n}\n\nexport interface MobileSDKModule {\n initialize(agent: Agent): void\n getAgentModules(): ModulesMap\n}\n\nexport type MobileSDKOptions<T extends Record<string, MobileSDKModule> = Record<string, MobileSDKModule>> = {\n agentConfig: InitConfig\n askarConfig: AskarModuleConfigStoreOptions\n modules: T\n defaultModules?: ModulesMap\n}\nexport class MobileSDK<T extends Record<string, MobileSDKModule> = Record<string, MobileSDKModule>> {\n private localAgent: Agent<ReturnType<typeof getCoreModules>> | null = null\n public readonly configuration: MobileSDKOptions<T>\n public readonly modules: T\n\n public constructor(options: MobileSDKOptions<T>) {\n this.configuration = options\n this.modules = options.modules\n }\n\n public static async initializeSDK(options: MobileSDKOptions<any>): Promise<{ sdk: MobileSDK; agent: Agent }> {\n const sdk = new MobileSDK(options)\n const agent = await sdk.initialize()\n return { sdk, agent }\n }\n\n async initialize() {\n const defaultModules = this.configuration.defaultModules ?? {}\n const coreModules = getCoreModules(this.configuration.askarConfig)\n Object.assign(defaultModules, coreModules)\n\n const modules = Object.entries(this.configuration.modules).reduce((acc, [, module]) => {\n const moduleModules = module.getAgentModules()\n Object.assign(acc, moduleModules)\n return acc\n }, defaultModules)\n\n const agent = new Agent({\n config: this.configuration.agentConfig,\n dependencies: agentDependencies,\n modules,\n })\n await agent.initialize()\n\n // Initialize modules after agent is initialized to ensure all dependencies are available\n for await (const [, module] of Object.entries(this.configuration.modules)) {\n module.initialize(agent)\n }\n\n this.localAgent = agent as Agent<ReturnType<typeof getCoreModules>>\n return this.localAgent\n }\n\n public get agent() {\n return this.localAgent\n }\n\n public assertAndGetAgent(): Agent<ReturnType<typeof getCoreModules>> {\n if (!this.agent) {\n throw new Error('Agent not initialized')\n }\n\n return this.agent\n }\n\n public static AppProvider({ children }: PropsWithChildren) {\n const { sdk } = useMobileSDK()\n\n if (!sdk?.agent) {\n throw new Error('Mobile SDK not initialized')\n }\n\n return <AgentProvider agent={sdk.agent}>{children}</AgentProvider>\n }\n\n public async createDid<T extends DidCreateOptions>(options: T) {\n const agent = this.assertAndGetAgent()\n\n const did = await agent.dids.create<T>(options)\n\n return did\n }\n\n public async getDids({\n method,\n did,\n tag,\n tagValue,\n }: {\n method?: string\n did?: string\n tag?: string\n tagValue?: TagValue\n }) {\n const agent = this.assertAndGetAgent()\n\n if (tag) {\n const didRepository = await agent.dependencyManager.resolve(DidRepository)\n\n const didRecord = await didRepository.findSingleByQuery(agent.context, tagValue ? { [tag]: tagValue } : { tag })\n return didRecord ? [didRecord] : []\n }\n\n const dids = await agent.dids.getCreatedDids({\n method,\n did,\n })\n return dids\n }\n\n public async addTagToDid({ did, tag, tagValue }: { did: string; tag: string; tagValue: TagValue }) {\n const agent = this.assertAndGetAgent()\n const didRecords = await this.getDids({ did })\n\n if (didRecords.length === 0) {\n throw new Error('Did not found')\n }\n\n const didRecord = didRecords[0]\n await didRecord.setTag(tag, tagValue)\n\n const didRepository = await agent.dependencyManager.resolve(DidRepository)\n\n await didRepository.update(agent.context, didRecord)\n\n return didRecord\n }\n\n public async resolveDid({ did }: { did: string }) {\n const agent = this.assertAndGetAgent()\n const didResolutionResult = await agent.dids.resolve(did)\n return didResolutionResult\n }\n\n public async deleteCredential({ id, format }: { id: string; format: CredentialRecord }) {\n const agent = this.assertAndGetAgent()\n\n if (format === CredentialRecord.SdJwt) {\n await agent.sdJwtVc.deleteById(id)\n } else if (format === CredentialRecord.Mdoc) {\n await agent.mdoc.deleteById(id)\n } else if (format === CredentialRecord.W3c) {\n await agent.w3cCredentials.deleteById(id)\n return\n } else {\n throw new Error('Credential format not supported')\n }\n }\n\n public async storeOpenIdCredential(cred: W3cCredentialRecord | SdJwtVcRecord | MdocRecord): Promise<void> {\n const agent = this.assertAndGetAgent()\n if (cred instanceof W3cCredentialRecord) {\n await agent.dependencyManager.resolve(W3cCredentialRepository).save(agent.context, cred)\n } else if (cred instanceof SdJwtVcRecord) {\n await agent.dependencyManager.resolve(SdJwtVcRepository).save(agent.context, cred)\n } else if (cred instanceof MdocRecord) {\n await agent.dependencyManager.resolve(MdocRepository).save(agent.context, cred)\n } else {\n throw new Error('Credential type is not supported')\n }\n }\n\n private getRepositories(\n agent: Agent,\n format?: CredentialRecord\n ): (SdJwtVcRepository | MdocRepository | W3cCredentialRepository)[] {\n if (format === CredentialRecord.SdJwt) {\n return [agent.dependencyManager.resolve(SdJwtVcRepository)]\n } else if (format === CredentialRecord.Mdoc) {\n return [agent.dependencyManager.resolve(MdocRepository)]\n } else if (format === CredentialRecord.W3c) {\n return [agent.dependencyManager.resolve(W3cCredentialRepository)]\n }\n\n return [\n agent.dependencyManager.resolve(SdJwtVcRepository),\n agent.dependencyManager.resolve(MdocRepository),\n agent.dependencyManager.resolve(W3cCredentialRepository),\n ]\n }\n\n public async setTagsToCredential({\n credId,\n tags,\n format,\n }: {\n credId: string\n tags: Record<string, TagValue>\n format?: CredentialRecord\n }) {\n if (!credId?.trim()) {\n throw new Error('credId is required and cannot be empty')\n }\n if (!tags || Object.keys(tags).length === 0) {\n throw new Error('At least one tag must be provided')\n }\n\n const agent = this.assertAndGetAgent()\n const repositories = this.getRepositories(agent, format)\n\n let lastError: Error | null = null\n\n for (const repository of repositories) {\n try {\n const credRecord = await repository.getById(agent.context, credId)\n\n credRecord.setTags(tags)\n\n if (repository instanceof W3cCredentialRepository) {\n await repository.update(agent.context, credRecord as W3cCredentialRecord)\n } else if (repository instanceof SdJwtVcRepository) {\n await repository.update(agent.context, credRecord as SdJwtVcRecord)\n } else if (repository instanceof MdocRepository) {\n await repository.update(agent.context, credRecord as MdocRecord)\n }\n return credRecord\n } catch (error) {\n lastError = error instanceof Error ? error : new Error(String(error))\n }\n }\n\n throw new Error(\n `Credential with id '${credId}' not found in any supported repository${\n lastError ? `. Last error: ${lastError.message}` : ''\n }`\n )\n }\n\n public async getCredentialsByTag({ tags, format }: { tags: Record<string, any>; format?: CredentialRecord }) {\n const agent = this.assertAndGetAgent()\n const repositories = this.getRepositories(agent, format)\n\n const results = []\n\n for (const repository of repositories) {\n const records = await repository.findByQuery(agent.context, tags)\n results.push(...records)\n }\n\n return results\n }\n\n public async exportWallet(exportToStore: AskarModuleConfigStoreOptions) {\n const agent = this.assertAndGetAgent()\n await agent.modules.askar.exportStore({ exportToStore })\n }\n\n public async addGenericRecord({\n content,\n tags,\n id,\n }: {\n content: Record<string, unknown>\n tags?: GenericRecordTags\n id?: string\n }): Promise<GenericRecord> {\n const agent = this.assertAndGetAgent()\n return agent.genericRecords.save({ content, tags, id })\n }\n\n public async updateGenericRecord(record: GenericRecord): Promise<void> {\n const agent = this.assertAndGetAgent()\n return agent.genericRecords.update(record)\n }\n\n public async getGenericRecord(id: string): Promise<GenericRecord | null> {\n const agent = this.assertAndGetAgent()\n return agent.genericRecords.findById(id)\n }\n\n public async findGenericRecordsByQuery(\n query: Query<GenericRecord>,\n queryOptions?: QueryOptions\n ): Promise<GenericRecord[]> {\n const agent = this.assertAndGetAgent()\n return agent.genericRecords.findAllByQuery(query, queryOptions)\n }\n\n public async deleteGenericRecord(id: string): Promise<void> {\n const agent = this.assertAndGetAgent()\n return agent.genericRecords.deleteById(id)\n }\n\n public async createKey<Type extends KmsCreateKeyType>(options: WithBackend<KmsCreateKeyOptions<Type>>) {\n const agent = this.assertAndGetAgent()\n return agent.kms.createKey(options)\n }\n\n public async signData(options: WithBackend<KmsSignOptions>) {\n const agent = this.assertAndGetAgent()\n return agent.kms.sign(options)\n }\n\n public async verifyData(options: WithBackend<KmsVerifyOptions>) {\n const agent = this.assertAndGetAgent()\n return agent.kms.verify(options)\n }\n\n public async createJwsCompact({\n header,\n payload,\n keyId,\n }: {\n header: JwsProtectedHeaderOptions\n payload: JwtPayload\n keyId: string\n }) {\n const agent = this.assertAndGetAgent()\n const jwsService = await agent.dependencyManager.resolve(JwsService)\n const jws = await jwsService.createJwsCompact(agent.context, {\n payload,\n keyId: keyId,\n protectedHeaderOptions: header,\n })\n return jws\n }\n}\n"],"mappings":";;;;;;;;;;AA4CA,IAAY,8DAAL;AACL;AACA;AACA;;;AAEF,MAAM,kBAAkB,gBAA+C;AACrE,QAAO;EACL,OAAO,IAAI,YAAY;GACrB;GACA,OAAO;IACL,IAAI,YAAY;IAChB,KAAK,YAAY;IACjB,qBAAqB,YAAY,wBAAwB,QAAQ,QAAQ;IAC1E;GACF,CAAC;EACF,MAAM,IAAI,WAAW;GACnB,YAAY,CAAC,IAAI,iBAAiB,EAAE,IAAI,iBAAiB,CAAC;GAC1D,WAAW,CAAC,IAAI,gBAAgB,EAAE,IAAI,gBAAgB,CAAC;GACxD,CAAC;EACF,OAAO,IAAI,YAAY,EACrB,OAAO,IAAI,6BAA6B,EACtC,OAAO,IACR,CAAC,EACH,CAAC;EACH;;AAcH,IAAa,YAAb,MAAa,UAAuF;CAKlG,AAAO,YAAY,SAA8B;OAJzC,aAA8D;AAKpE,OAAK,gBAAgB;AACrB,OAAK,UAAU,QAAQ;;CAGzB,aAAoB,cAAc,SAA2E;EAC3G,MAAM,MAAM,IAAI,UAAU,QAAQ;AAElC,SAAO;GAAE;GAAK,OADA,MAAM,IAAI,YAAY;GACf;;CAGvB,MAAM,aAAa;EACjB,MAAM,iBAAiB,KAAK,cAAc,kBAAkB,EAAE;EAC9D,MAAM,cAAc,eAAe,KAAK,cAAc,YAAY;AAClE,SAAO,OAAO,gBAAgB,YAAY;EAE1C,MAAM,UAAU,OAAO,QAAQ,KAAK,cAAc,QAAQ,CAAC,QAAQ,KAAK,GAAG,YAAY;GACrF,MAAM,gBAAgB,OAAO,iBAAiB;AAC9C,UAAO,OAAO,KAAK,cAAc;AACjC,UAAO;KACN,eAAe;EAElB,MAAM,QAAQ,IAAI,MAAM;GACtB,QAAQ,K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;AAErE,SADc,KAAK,mBAAmB,CACzB,eAAe,OAAO,OAAO;;CAG5C,MAAa,iBAAiB,IAA2C;AAEvE,SADc,KAAK,mBAAmB,CACzB,eAAe,SAAS,GAAG;;CAG1C,MAAa,0BACX,OACA,cAC0B;AAE1B,SADc,KAAK,mBAAmB,CACzB,eAAe,eAAe,OAAO,aAAa;;CAGjE,MAAa,oBAAoB,IAA2B;AAE1D,SADc,KAAK,mBAAmB,CACzB,eAAe,WAAW,GAAG;;CAG5C,MAAa,UAAyC,SAAiD;AAErG,SADc,KAAK,mBAAmB,CACzB,IAAI,UAAU,QAAQ;;CAGrC,MAAa,SAAS,SAAsC;AAE1D,SADc,KAAK,mBAAmB,CACzB,IAAI,KAAK,QAAQ;;CAGhC,MAAa,WAAW,SAAwC;AAE9D,SADc,KAAK,mBAAmB,CACzB,IAAI,OAAO,QAAQ;;CAGlC,MAAa,iBAAiB,EAC5B,QACA,SACA,SAKC;EACD,MAAM,QAAQ,KAAK,mBAAmB;AAOtC,SALY,OADO,MAAM,MAAM,kBAAkB,QAAQ,WAAW,EACvC,iBAAiB,MAAM,SAAS;GAC3D;GACO;GACP,wBAAwB;GACzB,CAAC"}
|
|
1
|
+
{"version":3,"file":"MobileSDK.mjs","names":["AgentProvider"],"sources":["../src/MobileSDK.tsx"],"sourcesContent":["import { AskarModule, type AskarModuleConfigStoreOptions } from '@credo-ts/askar'\nimport {\n Agent,\n CacheModule,\n type DidCreateOptions,\n type DidRegistrar,\n DidRepository,\n type DidResolver,\n DidsModule,\n GenericRecord,\n GenericRecordTags,\n type InitConfig,\n JwkDidRegistrar,\n JwkDidResolver,\n JwsProtectedHeaderOptions,\n JwsService,\n JwtPayload,\n KeyDidRegistrar,\n KeyDidResolver,\n MdocRecord,\n MdocRepository,\n type ModulesMap,\n type Query,\n type QueryOptions,\n SdJwtVcRecord,\n SdJwtVcRepository,\n SingleContextStorageLruCache,\n type TagValue,\n W3cCredentialRecord,\n W3cCredentialRepository,\n} from '@credo-ts/core'\nimport { KmsCreateKeyOptions, KmsCreateKeyType, KmsSignOptions, KmsVerifyOptions } from '@credo-ts/core/kms'\nimport { agentDependencies } from '@credo-ts/react-native'\nimport { askar } from '@openwallet-foundation/askar-react-native'\nimport type { PropsWithChildren } from 'react'\nimport { useMobileSDK } from './contexts'\nimport AgentProvider from './providers/AgentProvider'\n\nexport type WithBackend<T> = T & {\n /**\n * The backend to use for creating the key. If not provided the\n * default backend for key operations will be used.\n */\n backend?: string\n}\n\nexport enum CredentialRecord {\n SdJwt = 'sd-jwt',\n Mdoc = 'mdoc',\n W3c = 'w3c',\n}\nconst getCoreModules = (\n askarConfig: AskarModuleConfigStoreOptions,\n dids?: { registrars?: DidRegistrar[]; resolvers?: DidResolver[] }\n) => {\n return {\n askar: new AskarModule({\n askar,\n store: {\n id: askarConfig.id,\n key: askarConfig.key,\n keyDerivationMethod: askarConfig.keyDerivationMethod === 'raw' ? 'raw' : 'kdf:argon2i:mod',\n },\n }),\n dids: new DidsModule({\n registrars: [new JwkDidRegistrar(), new KeyDidRegistrar(), ...(dids?.registrars ?? [])],\n resolvers: [new JwkDidResolver(), new KeyDidResolver(), ...(dids?.resolvers ?? [])],\n }),\n cache: new CacheModule({\n cache: new SingleContextStorageLruCache({\n limit: 50,\n }),\n }),\n }\n}\n\nexport interface MobileSDKModule {\n initialize(agent: Agent): void\n getAgentModules(): ModulesMap\n}\n\nexport type MobileSDKOptions<T extends Record<string, MobileSDKModule> = Record<string, MobileSDKModule>> = {\n agentConfig: InitConfig\n askarConfig: AskarModuleConfigStoreOptions\n modules: T\n defaultModules?: ModulesMap\n dids?: {\n registrars?: DidRegistrar[]\n resolvers?: DidResolver[]\n }\n}\nexport class MobileSDK<T extends Record<string, MobileSDKModule> = Record<string, MobileSDKModule>> {\n private localAgent: Agent<ReturnType<typeof getCoreModules>> | null = null\n public readonly configuration: MobileSDKOptions<T>\n public readonly modules: T\n\n public constructor(options: MobileSDKOptions<T>) {\n this.configuration = options\n this.modules = options.modules\n }\n\n public static async initializeSDK(options: MobileSDKOptions<any>): Promise<{ sdk: MobileSDK; agent: Agent }> {\n const sdk = new MobileSDK(options)\n const agent = await sdk.initialize()\n return { sdk, agent }\n }\n\n async initialize() {\n const defaultModules = this.configuration.defaultModules ?? {}\n const coreModules = getCoreModules(this.configuration.askarConfig, this.configuration.dids)\n Object.assign(defaultModules, coreModules)\n\n const modules = Object.entries(this.configuration.modules).reduce((acc, [, module]) => {\n const moduleModules = module.getAgentModules()\n Object.assign(acc, moduleModules)\n return acc\n }, defaultModules)\n\n const agent = new Agent({\n config: this.configuration.agentConfig,\n dependencies: agentDependencies,\n modules,\n })\n await agent.initialize()\n\n // Initialize modules after agent is initialized to ensure all dependencies are available\n for await (const [, module] of Object.entries(this.configuration.modules)) {\n module.initialize(agent)\n }\n\n this.localAgent = agent as Agent<ReturnType<typeof getCoreModules>>\n return this.localAgent\n }\n\n public get agent() {\n return this.localAgent\n }\n\n public assertAndGetAgent(): Agent<ReturnType<typeof getCoreModules>> {\n if (!this.agent) {\n throw new Error('Agent not initialized')\n }\n\n return this.agent\n }\n\n public static AppProvider({ children }: PropsWithChildren) {\n const { sdk } = useMobileSDK()\n\n if (!sdk?.agent) {\n throw new Error('Mobile SDK not initialized')\n }\n\n return <AgentProvider agent={sdk.agent}>{children}</AgentProvider>\n }\n\n public async createDid<T extends DidCreateOptions>(options: T) {\n const agent = this.assertAndGetAgent()\n\n const did = await agent.dids.create<T>(options)\n\n return did\n }\n\n public async getDids({\n method,\n did,\n tag,\n tagValue,\n }: {\n method?: string\n did?: string\n tag?: string\n tagValue?: TagValue\n }) {\n const agent = this.assertAndGetAgent()\n\n if (tag) {\n const didRepository = await agent.dependencyManager.resolve(DidRepository)\n\n const didRecord = await didRepository.findSingleByQuery(agent.context, tagValue ? { [tag]: tagValue } : { tag })\n return didRecord ? [didRecord] : []\n }\n\n const dids = await agent.dids.getCreatedDids({\n method,\n did,\n })\n return dids\n }\n\n public async addTagToDid({ did, tag, tagValue }: { did: string; tag: string; tagValue: TagValue }) {\n const agent = this.assertAndGetAgent()\n const didRecords = await this.getDids({ did })\n\n if (didRecords.length === 0) {\n throw new Error('Did not found')\n }\n\n const didRecord = didRecords[0]\n await didRecord.setTag(tag, tagValue)\n\n const didRepository = await agent.dependencyManager.resolve(DidRepository)\n\n await didRepository.update(agent.context, didRecord)\n\n return didRecord\n }\n\n public async resolveDid({ did }: { did: string }) {\n const agent = this.assertAndGetAgent()\n const didResolutionResult = await agent.dids.resolve(did)\n return didResolutionResult\n }\n\n public async deleteCredential({ id, format }: { id: string; format: CredentialRecord }) {\n const agent = this.assertAndGetAgent()\n\n if (format === CredentialRecord.SdJwt) {\n await agent.sdJwtVc.deleteById(id)\n } else if (format === CredentialRecord.Mdoc) {\n await agent.mdoc.deleteById(id)\n } else if (format === CredentialRecord.W3c) {\n await agent.w3cCredentials.deleteById(id)\n return\n } else {\n throw new Error('Credential format not supported')\n }\n }\n\n public async storeOpenIdCredential(cred: W3cCredentialRecord | SdJwtVcRecord | MdocRecord): Promise<void> {\n const agent = this.assertAndGetAgent()\n if (cred instanceof W3cCredentialRecord) {\n await agent.dependencyManager.resolve(W3cCredentialRepository).save(agent.context, cred)\n } else if (cred instanceof SdJwtVcRecord) {\n await agent.dependencyManager.resolve(SdJwtVcRepository).save(agent.context, cred)\n } else if (cred instanceof MdocRecord) {\n await agent.dependencyManager.resolve(MdocRepository).save(agent.context, cred)\n } else {\n throw new Error('Credential type is not supported')\n }\n }\n\n private getRepositories(\n agent: Agent,\n format?: CredentialRecord\n ): (SdJwtVcRepository | MdocRepository | W3cCredentialRepository)[] {\n if (format === CredentialRecord.SdJwt) {\n return [agent.dependencyManager.resolve(SdJwtVcRepository)]\n } else if (format === CredentialRecord.Mdoc) {\n return [agent.dependencyManager.resolve(MdocRepository)]\n } else if (format === CredentialRecord.W3c) {\n return [agent.dependencyManager.resolve(W3cCredentialRepository)]\n }\n\n return [\n agent.dependencyManager.resolve(SdJwtVcRepository),\n agent.dependencyManager.resolve(MdocRepository),\n agent.dependencyManager.resolve(W3cCredentialRepository),\n ]\n }\n\n public async setTagsToCredential({\n credId,\n tags,\n format,\n }: {\n credId: string\n tags: Record<string, TagValue>\n format?: CredentialRecord\n }) {\n if (!credId?.trim()) {\n throw new Error('credId is required and cannot be empty')\n }\n if (!tags || Object.keys(tags).length === 0) {\n throw new Error('At least one tag must be provided')\n }\n\n const agent = this.assertAndGetAgent()\n const repositories = this.getRepositories(agent, format)\n\n let lastError: Error | null = null\n\n for (const repository of repositories) {\n try {\n const credRecord = await repository.getById(agent.context, credId)\n\n credRecord.setTags(tags)\n\n if (repository instanceof W3cCredentialRepository) {\n await repository.update(agent.context, credRecord as W3cCredentialRecord)\n } else if (repository instanceof SdJwtVcRepository) {\n await repository.update(agent.context, credRecord as SdJwtVcRecord)\n } else if (repository instanceof MdocRepository) {\n await repository.update(agent.context, credRecord as MdocRecord)\n }\n return credRecord\n } catch (error) {\n lastError = error instanceof Error ? error : new Error(String(error))\n }\n }\n\n throw new Error(\n `Credential with id '${credId}' not found in any supported repository${\n lastError ? `. Last error: ${lastError.message}` : ''\n }`\n )\n }\n\n public async getCredentialsByTag({ tags, format }: { tags: Record<string, any>; format?: CredentialRecord }) {\n const agent = this.assertAndGetAgent()\n const repositories = this.getRepositories(agent, format)\n\n const results = []\n\n for (const repository of repositories) {\n const records = await repository.findByQuery(agent.context, tags)\n results.push(...records)\n }\n\n return results\n }\n\n public async exportWallet(exportToStore: AskarModuleConfigStoreOptions) {\n const agent = this.assertAndGetAgent()\n await agent.modules.askar.exportStore({ exportToStore })\n }\n\n public async addGenericRecord({\n content,\n tags,\n id,\n }: {\n content: Record<string, unknown>\n tags?: GenericRecordTags\n id?: string\n }): Promise<GenericRecord> {\n const agent = this.assertAndGetAgent()\n return agent.genericRecords.save({ content, tags, id })\n }\n\n public async updateGenericRecord(record: GenericRecord): Promise<void> {\n const agent = this.assertAndGetAgent()\n return agent.genericRecords.update(record)\n }\n\n public async getGenericRecord(id: string): Promise<GenericRecord | null> {\n const agent = this.assertAndGetAgent()\n return agent.genericRecords.findById(id)\n }\n\n public async findGenericRecordsByQuery(\n query: Query<GenericRecord>,\n queryOptions?: QueryOptions\n ): Promise<GenericRecord[]> {\n const agent = this.assertAndGetAgent()\n return agent.genericRecords.findAllByQuery(query, queryOptions)\n }\n\n public async deleteGenericRecord(id: string): Promise<void> {\n const agent = this.assertAndGetAgent()\n return agent.genericRecords.deleteById(id)\n }\n\n public async createKey<Type extends KmsCreateKeyType>(options: WithBackend<KmsCreateKeyOptions<Type>>) {\n const agent = this.assertAndGetAgent()\n return agent.kms.createKey(options)\n }\n\n public async signData(options: WithBackend<KmsSignOptions>) {\n const agent = this.assertAndGetAgent()\n return agent.kms.sign(options)\n }\n\n public async verifyData(options: WithBackend<KmsVerifyOptions>) {\n const agent = this.assertAndGetAgent()\n return agent.kms.verify(options)\n }\n\n public async createJwsCompact({\n header,\n payload,\n keyId,\n }: {\n header: JwsProtectedHeaderOptions\n payload: JwtPayload\n keyId: string\n }) {\n const agent = this.assertAndGetAgent()\n const jwsService = await agent.dependencyManager.resolve(JwsService)\n const jws = await jwsService.createJwsCompact(agent.context, {\n payload,\n keyId: keyId,\n protectedHeaderOptions: header,\n })\n return jws\n }\n}\n"],"mappings":";;;;;;;;;;AA8CA,IAAY,8DAAL;AACL;AACA;AACA;;;AAEF,MAAM,kBACJ,aACA,SACG;AACH,QAAO;EACL,OAAO,IAAI,YAAY;GACrB;GACA,OAAO;IACL,IAAI,YAAY;IAChB,KAAK,YAAY;IACjB,qBAAqB,YAAY,wBAAwB,QAAQ,QAAQ;IAC1E;GACF,CAAC;EACF,MAAM,IAAI,WAAW;GACnB,YAAY;IAAC,IAAI,iBAAiB;IAAE,IAAI,iBAAiB;IAAE,GAAI,MAAM,cAAc,EAAE;IAAE;GACvF,WAAW;IAAC,IAAI,gBAAgB;IAAE,IAAI,gBAAgB;IAAE,GAAI,MAAM,aAAa,EAAE;IAAE;GACpF,CAAC;EAC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OAAO,QAAQ;;CAGlC,MAAa,iBAAiB,EAC5B,QACA,SACA,SAKC;EACD,MAAM,QAAQ,KAAK,mBAAmB;AAOtC,SALY,OADO,MAAM,MAAM,kBAAkB,QAAQ,WAAW,EACvC,iBAAiB,MAAM,SAAS;GAC3D;GACO;GACP,wBAAwB;GACzB,CAAC"}
|
package/build/index.d.mts
CHANGED
|
@@ -13,5 +13,5 @@ import { W3cCredentialRecord, W3cCredentialRecordProvider, W3cVerifiableCredenti
|
|
|
13
13
|
import "./providers/index.mjs";
|
|
14
14
|
import { importWalletToStore, isWalletImportable, isWalletPinCorrect } from "./wallet/wallet.mjs";
|
|
15
15
|
import "./wallet/index.mjs";
|
|
16
|
-
import { ConsoleLogger, Hasher, JwsProtectedHeaderOptions, JwtPayload, KeyDidCreateOptions, Kms, LogLevel, TypedArrayEncoder } from "@credo-ts/core";
|
|
17
|
-
export { BaseRecordAny, ConsoleLogger, CredentialRecord, CredentialsProvider, GenericRecord, GenericRecordProvider, Hasher, JwsProtectedHeaderOptions, JwtPayload, KeyDidCreateOptions, Kms, LogLevel, Mdoc, MdocRecord, MdocRecordProvider, MobileSDK, MobileSDKModule, MobileSDKOptions, MobileSDKProvider, RecordsState, SdJwtVc, SdJwtVcRecord, SdJwtVcRecordProvider, TypedArrayEncoder, UseGenericRecordOptions, W3cCredentialRecord, W3cCredentialRecordProvider, W3cVerifiableCredential, WithBackend, addRecord, importWalletToStore, isWalletImportable, isWalletPinCorrect, recordsAddedByType, recordsRemovedByType, recordsUpdatedByType, removeRecord, updateRecord, useAgent, useGenericRecordById, useGenericRecords, useMdocRecordById, useMdocRecords, useMobileSDK, useMobileSDKInitializer, useSdJwtVcRecordById, useSdJwtVcRecords, useW3cCredentialRecordById, useW3cCredentialRecords };
|
|
16
|
+
import { ConsoleLogger, Hasher, JwsProtectedHeaderOptions, JwtPayload, KeyDidCreateOptions, Kms, LogLevel, TypedArrayEncoder, WebDidResolver } from "@credo-ts/core";
|
|
17
|
+
export { BaseRecordAny, ConsoleLogger, CredentialRecord, CredentialsProvider, GenericRecord, GenericRecordProvider, Hasher, JwsProtectedHeaderOptions, JwtPayload, KeyDidCreateOptions, Kms, LogLevel, Mdoc, MdocRecord, MdocRecordProvider, MobileSDK, MobileSDKModule, MobileSDKOptions, MobileSDKProvider, RecordsState, SdJwtVc, SdJwtVcRecord, SdJwtVcRecordProvider, TypedArrayEncoder, UseGenericRecordOptions, W3cCredentialRecord, W3cCredentialRecordProvider, W3cVerifiableCredential, WebDidResolver, WithBackend, addRecord, importWalletToStore, isWalletImportable, isWalletPinCorrect, recordsAddedByType, recordsRemovedByType, recordsUpdatedByType, removeRecord, updateRecord, useAgent, useGenericRecordById, useGenericRecords, useMdocRecordById, useMdocRecords, useMobileSDK, useMobileSDKInitializer, useSdJwtVcRecordById, useSdJwtVcRecords, useW3cCredentialRecordById, useW3cCredentialRecords };
|
package/build/index.mjs
CHANGED
|
@@ -13,6 +13,6 @@ import { GenericRecord, GenericRecordProvider, useGenericRecordById, useGenericR
|
|
|
13
13
|
import "./providers/index.mjs";
|
|
14
14
|
import { importWalletToStore, isWalletImportable, isWalletPinCorrect } from "./wallet/wallet.mjs";
|
|
15
15
|
import "./wallet/index.mjs";
|
|
16
|
-
import { ConsoleLogger, Hasher, JwsProtectedHeaderOptions, JwtPayload, KeyDidCreateOptions, Kms, LogLevel, TypedArrayEncoder } from "@credo-ts/core";
|
|
16
|
+
import { ConsoleLogger, Hasher, JwsProtectedHeaderOptions, JwtPayload, KeyDidCreateOptions, Kms, LogLevel, TypedArrayEncoder, WebDidResolver } from "@credo-ts/core";
|
|
17
17
|
|
|
18
|
-
export { ConsoleLogger, CredentialRecord, CredentialsProvider, GenericRecord, GenericRecordProvider, Hasher, JwsProtectedHeaderOptions, JwtPayload, KeyDidCreateOptions, Kms, LogLevel, Mdoc, MdocRecord, MdocRecordProvider, MobileSDK, MobileSDKProvider, SdJwtVc, SdJwtVcRecord, SdJwtVcRecordProvider, TypedArrayEncoder, W3cCredentialRecord, W3cCredentialRecordProvider, W3cVerifiableCredential, addRecord, importWalletToStore, isWalletImportable, isWalletPinCorrect, recordsAddedByType, recordsRemovedByType, recordsUpdatedByType, removeRecord, updateRecord, useAgent, useGenericRecordById, useGenericRecords, useMdocRecordById, useMdocRecords, useMobileSDK, useMobileSDKInitializer, useSdJwtVcRecordById, useSdJwtVcRecords, useW3cCredentialRecordById, useW3cCredentialRecords };
|
|
18
|
+
export { ConsoleLogger, CredentialRecord, CredentialsProvider, GenericRecord, GenericRecordProvider, Hasher, JwsProtectedHeaderOptions, JwtPayload, KeyDidCreateOptions, Kms, LogLevel, Mdoc, MdocRecord, MdocRecordProvider, MobileSDK, MobileSDKProvider, SdJwtVc, SdJwtVcRecord, SdJwtVcRecordProvider, TypedArrayEncoder, W3cCredentialRecord, W3cCredentialRecordProvider, W3cVerifiableCredential, WebDidResolver, addRecord, importWalletToStore, isWalletImportable, isWalletPinCorrect, recordsAddedByType, recordsRemovedByType, recordsUpdatedByType, removeRecord, updateRecord, useAgent, useGenericRecordById, useGenericRecords, useMdocRecordById, useMdocRecords, useMobileSDK, useMobileSDKInitializer, useSdJwtVcRecordById, useSdJwtVcRecords, useW3cCredentialRecordById, useW3cCredentialRecords };
|