@yourself_id/siwys-react-native 0.38.0 → 0.38.1-jahatch512-docs-keymaster-init.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +167 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,167 @@
1
+ # @yourself_id/siwys-react-native
2
+
3
+ React Native client SDK for **Self ID** and the **Multi-Dimensional Identity Protocol (MDIP)**.
4
+
5
+ This package provides a mobile-native Keymaster implementation optimized for iOS and Android environments, enabling mobile applications (such as wallets and native mobile client apps) to manage keys, Decentralized Identifiers (DIDs), and Verifiable Credentials without relying on Node.js-specific crypto runtimes.
6
+
7
+ ---
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @yourself_id/siwys-react-native
13
+ # or
14
+ yarn add @yourself_id/siwys-react-native
15
+ ```
16
+
17
+ ### Dependencies & Crypto Support
18
+
19
+ This package uses `@noble/secp256k1`, `@noble/hashes`, and `@scure/bip32` for pure JavaScript/TypeScript cryptographic operations.
20
+
21
+ If your React Native environment does not have global `crypto.getRandomValues`, install `react-native-get-random-values` and import it at the top of your app entry point (e.g., `index.js`):
22
+
23
+ ```bash
24
+ npm install react-native-get-random-values
25
+ ```
26
+
27
+ ```javascript
28
+ // index.js (top of file)
29
+ import "react-native-get-random-values";
30
+ ```
31
+
32
+ ---
33
+
34
+ ## Core Classes
35
+
36
+ | Class | Description |
37
+ |---|---|
38
+ | `KeymasterReactNative` | Singleton client providing wallet management, DID creation, challenge responses, and credential operations. |
39
+ | `GatekeeperReactNative` | Gatekeeper client adapter configured for mobile networking. |
40
+ | `CipherReactNative` | Mobile cryptographic provider implementing MDIP cipher interfaces. |
41
+
42
+ ---
43
+
44
+ ## Getting Started
45
+
46
+ ### 1. Initialize `KeymasterReactNative`
47
+
48
+ Provide a custom persistence layer (`walletDb`) such as `react-native-mmkv`, `AsyncStorage`, or `react-native-keychain` to securely store the encrypted wallet on the mobile device:
49
+
50
+ ```typescript
51
+ import { KeymasterReactNative, KeymasterReactNativeConfig } from "@yourself_id/siwys-react-native";
52
+ import AsyncStorage from "@react-native-async-storage/async-storage";
53
+
54
+ const WALLET_STORAGE_KEY = "@selfid/wallet";
55
+
56
+ const walletDb = {
57
+ saveWallet: async (wallet: any, overwrite = false) => {
58
+ const existing = await AsyncStorage.getItem(WALLET_STORAGE_KEY);
59
+ if (existing && !overwrite) return true;
60
+ await AsyncStorage.setItem(WALLET_STORAGE_KEY, JSON.stringify(wallet));
61
+ return true;
62
+ },
63
+ loadWallet: async () => {
64
+ const raw = await AsyncStorage.getItem(WALLET_STORAGE_KEY);
65
+ return raw ? JSON.parse(raw) : null;
66
+ },
67
+ updateWallet: async (mutator: (wallet: any) => void | Promise<void>) => {
68
+ const raw = await AsyncStorage.getItem(WALLET_STORAGE_KEY);
69
+ if (!raw) throw new Error("No wallet found");
70
+ const wallet = JSON.parse(raw);
71
+ await mutator(wallet);
72
+ await AsyncStorage.setItem(WALLET_STORAGE_KEY, JSON.stringify(wallet));
73
+ },
74
+ };
75
+
76
+ const config: KeymasterReactNativeConfig = {
77
+ gatekeeperConfig: {
78
+ url: "https://gatekeeper.example.com", // Gatekeeper service endpoint
79
+ waitUntilReady: true,
80
+ },
81
+ walletDb,
82
+ walletConfig: {
83
+ id: "user-mobile-wallet",
84
+ registry: "hyperswarm",
85
+ // mnemonic: "twelve word seed phrase...", // optional mnemonic to restore an existing wallet
86
+ },
87
+ passphrase: "device-specific-secure-passphrase", // typically protected via Keychain/Keystore or user PIN
88
+ didPrefix: "did:test",
89
+ };
90
+
91
+ KeymasterReactNative.initialize(config);
92
+ await KeymasterReactNative.start();
93
+ ```
94
+
95
+ ---
96
+
97
+ ## Common Mobile Use Cases
98
+
99
+ ### 1. Responding to an Authentication Challenge (Sign In)
100
+
101
+ When a mobile app scans a SIWYS QR code or receives a deep-link containing a challenge DID, generate a signed response and submit it to the backend callback URL:
102
+
103
+ ```typescript
104
+ import { KeymasterReactNative } from "@yourself_id/siwys-react-native";
105
+
106
+ async function handleAuthentication(challengeDID: string, callbackUrl: string) {
107
+ // 1. Generate cryptographic response signed by the active mobile identity
108
+ const responseDID = await KeymasterReactNative.createResponse(challengeDID);
109
+
110
+ // 2. Post the response to the partner backend callback endpoint
111
+ const res = await fetch(callbackUrl, {
112
+ method: "POST",
113
+ headers: { "Content-Type": "application/json" },
114
+ body: JSON.stringify({ response: responseDID }),
115
+ });
116
+
117
+ const data = await res.json();
118
+ if (data.authenticated) {
119
+ console.log("Authentication successful!");
120
+ }
121
+ }
122
+ ```
123
+
124
+ ### 2. Creating and Managing DIDs
125
+
126
+ ```typescript
127
+ // Create a new decentralized identifier on the configured registry
128
+ const newDid = await KeymasterReactNative.createId("my-persona", {
129
+ registry: "hyperswarm",
130
+ });
131
+
132
+ // Set active ID
133
+ await KeymasterReactNative.setCurrentId("my-persona");
134
+
135
+ // Resolve a DID document
136
+ const doc = await KeymasterReactNative.resolveDID(newDid);
137
+ ```
138
+
139
+ ### 3. Accepting and Storing Verifiable Credentials
140
+
141
+ When your app receives an issued credential from an issuer:
142
+
143
+ ```typescript
144
+ // Accept a credential issued to this identity
145
+ const success = await KeymasterReactNative.acceptCredential(credentialDid);
146
+
147
+ // Retrieve stored credential details
148
+ const credential = await KeymasterReactNative.getCredential(credentialId);
149
+ ```
150
+
151
+ ### 4. Wallet Backup & Recovery
152
+
153
+ ```typescript
154
+ // Export seed phrase to allow the user to back up their wallet
155
+ const mnemonic = await KeymasterReactNative.showMnemonic();
156
+
157
+ // Create a new wallet from an existing recovery phrase
158
+ await KeymasterReactNative.newWallet(mnemonic, true);
159
+ ```
160
+
161
+ ---
162
+
163
+ ## Related Documentation
164
+
165
+ - [Backend SDK (`@yourself_id/siwys-api-js`)](../api-js/README.md)
166
+ - [React Web SDK (`@yourself_id/siwys-react-js`)](../react-js/README.md)
167
+ - [Keymaster Integration Guide](../../demo/README.md#integrating-keymaster)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yourself_id/siwys-react-native",
3
- "version": "0.38.0",
3
+ "version": "0.38.1-jahatch512-docs-keymaster-init.49.0",
4
4
  "description": "A React Native component library",
5
5
  "repository": {
6
6
  "type": "git",
@@ -53,5 +53,5 @@
53
53
  "tsup": "^8.3.0",
54
54
  "typescript": "4.9.4"
55
55
  },
56
- "gitHead": "a5268cb7eae9996ade955c413ae20bc674da683b"
56
+ "gitHead": "a07a6e39d3dec57ed2da137800488e3badad717c"
57
57
  }