@getpara/react-native-wallet 1.0.2-dev.4 → 1.0.2-dev.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  import { ConstructorOpts, ParaCore, Environment, PlatformUtils } from '@getpara/web-sdk';
2
+ import { Auth } from '@getpara/user-management-client';
2
3
  /**
3
4
  * Represents a mobile implementation of the Para SDK.
4
5
  * @extends ParaCore
@@ -35,26 +36,17 @@ export declare class ParaMobile extends ParaCore {
35
36
  }): Promise<string>;
36
37
  /**
37
38
  * Registers a passkey for the user.
38
- * @param {string} identifier - The user's email or phone number.
39
+ * @param {Auth<'email'> | Auth<'phone'>} auth - The user's authentication details
39
40
  * @param {string} biometricsId - The biometrics ID obtained from verification.
40
- * @param {'email' | 'phone'} [identifierType='email'] - The type of identifier used.
41
41
  * @returns {Promise<void>}
42
42
  */
43
- registerPasskey({ identifier, biometricsId, identifierType, countryCode, }: {
44
- identifier: string;
43
+ registerPasskey({ biometricsId, ...auth }: {
45
44
  biometricsId: string;
46
- identifierType?: 'email' | 'phone';
47
- countryCode?: string;
48
- }): Promise<void>;
45
+ } & (Auth<'email'> | Auth<'phone'>)): Promise<void>;
49
46
  /**
50
- * Logs in the user using either email or phone number.
51
- * @param {string} [email] - The user's email address.
52
- * @param {string} [phone] - The user's phone number.
53
- * @returns {Promise<Wallet[]>} An array of user wallets.
47
+ * Logs in the user using their authentication credentials.
48
+ * @param {AuthParams} params - The authentication parameters.
49
+ * @returns {Promise<void>}
54
50
  */
55
- login({ email, phone, countryCode }: {
56
- email?: string;
57
- phone?: string;
58
- countryCode?: string;
59
- }): Promise<void>;
51
+ login({ ...auth }: Auth<'email'> | Auth<'phone'>): Promise<void>;
60
52
  }
@@ -7,10 +7,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ var __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
10
21
  import { ParaCore, Environment, decryptPrivateKeyAndDecryptShare, encryptPrivateKey, getAsymmetricKeyPair, getDerivedPrivateKeyAndDecrypt, getPublicKeyHex, getSHA256HashHex, parseCredentialCreationRes, } from '@getpara/web-sdk';
11
22
  import { ReactNativeUtils } from './ReactNativeUtils.js';
12
23
  import { Passkey, } from 'react-native-passkey';
13
- import { extractAuthInfo, PublicKeyStatus } from '@getpara/user-management-client';
24
+ import { PublicKeyStatus } from '@getpara/user-management-client';
14
25
  import { setEnv } from '../config.js';
15
26
  import base64url from 'base64url';
16
27
  import { webcrypto } from 'crypto';
@@ -92,20 +103,20 @@ export class ParaMobile extends ParaCore {
92
103
  }
93
104
  /**
94
105
  * Registers a passkey for the user.
95
- * @param {string} identifier - The user's email or phone number.
106
+ * @param {Auth<'email'> | Auth<'phone'>} auth - The user's authentication details
96
107
  * @param {string} biometricsId - The biometrics ID obtained from verification.
97
- * @param {'email' | 'phone'} [identifierType='email'] - The type of identifier used.
98
108
  * @returns {Promise<void>}
99
109
  */
100
110
  registerPasskey(_a) {
101
- return __awaiter(this, arguments, void 0, function* ({ identifier, biometricsId, identifierType = 'email', countryCode, }) {
111
+ return __awaiter(this, void 0, void 0, function* () {
112
+ var { biometricsId } = _a, auth = __rest(_a, ["biometricsId"]);
102
113
  if (!webcrypto || !webcrypto.getRandomValues) {
103
114
  throw new Error('Web crypto is not available. Ensure you have imported the shim from @getpara/react-native-wallet.');
104
115
  }
105
116
  const userHandle = new Uint8Array(32);
106
117
  webcrypto.getRandomValues(userHandle);
107
118
  const userHandleEncoded = base64url.encode(userHandle);
108
- const displayIdentifier = identifierType === 'email' ? identifier : `${countryCode}${identifier}`;
119
+ const displayIdentifier = 'email' in auth ? auth.email : `${auth.countryCode}${auth.phone}`;
109
120
  const requestJson = {
110
121
  authenticatorSelection: {
111
122
  authenticatorAttachment: 'platform',
@@ -161,19 +172,14 @@ export class ParaMobile extends ParaCore {
161
172
  });
162
173
  }
163
174
  /**
164
- * Logs in the user using either email or phone number.
165
- * @param {string} [email] - The user's email address.
166
- * @param {string} [phone] - The user's phone number.
167
- * @returns {Promise<Wallet[]>} An array of user wallets.
175
+ * Logs in the user using their authentication credentials.
176
+ * @param {AuthParams} params - The authentication parameters.
177
+ * @returns {Promise<void>}
168
178
  */
169
179
  login(_a) {
170
- return __awaiter(this, arguments, void 0, function* ({ email, phone, countryCode }) {
171
- var _b;
180
+ return __awaiter(this, void 0, void 0, function* () {
181
+ var auth = __rest(_a, []);
172
182
  yield this.logout();
173
- const auth = (_b = extractAuthInfo({ email, phone, countryCode })) === null || _b === void 0 ? void 0 : _b.auth;
174
- if (!auth) {
175
- throw new Error('No auth provided');
176
- }
177
183
  const { challenge, allowedPublicKeys } = yield this.ctx.client.getWebChallenge(auth);
178
184
  const requestJson = {
179
185
  challenge,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getpara/react-native-wallet",
3
- "version": "1.0.2-dev.4",
3
+ "version": "1.0.2-dev.6",
4
4
  "description": "Para Wallet for React Native",
5
5
  "homepage": "https://getpara.com",
6
6
  "author": "Para Team <hello@getpara.com> (https://getpara.com)",
@@ -20,7 +20,7 @@ import {
20
20
  PasskeyGetRequest,
21
21
  PasskeyGetResult,
22
22
  } from 'react-native-passkey';
23
- import { extractAuthInfo, PublicKeyStatus, WalletScheme } from '@getpara/user-management-client';
23
+ import { Auth, PublicKeyStatus, WalletScheme } from '@getpara/user-management-client';
24
24
  import { setEnv } from '../config.js';
25
25
  import base64url from 'base64url';
26
26
  import { webcrypto } from 'crypto';
@@ -99,25 +99,13 @@ export class ParaMobile extends ParaCore {
99
99
 
100
100
  return biometricsId;
101
101
  }
102
-
103
102
  /**
104
103
  * Registers a passkey for the user.
105
- * @param {string} identifier - The user's email or phone number.
104
+ * @param {Auth<'email'> | Auth<'phone'>} auth - The user's authentication details
106
105
  * @param {string} biometricsId - The biometrics ID obtained from verification.
107
- * @param {'email' | 'phone'} [identifierType='email'] - The type of identifier used.
108
106
  * @returns {Promise<void>}
109
107
  */
110
- async registerPasskey({
111
- identifier,
112
- biometricsId,
113
- identifierType = 'email',
114
- countryCode,
115
- }: {
116
- identifier: string;
117
- biometricsId: string;
118
- identifierType?: 'email' | 'phone';
119
- countryCode?: string;
120
- }) {
108
+ async registerPasskey({ biometricsId, ...auth }: { biometricsId: string } & (Auth<'email'> | Auth<'phone'>)) {
121
109
  if (!webcrypto || !webcrypto.getRandomValues) {
122
110
  throw new Error('Web crypto is not available. Ensure you have imported the shim from @getpara/react-native-wallet.');
123
111
  }
@@ -125,7 +113,7 @@ export class ParaMobile extends ParaCore {
125
113
  webcrypto.getRandomValues(userHandle);
126
114
  const userHandleEncoded = base64url.encode(userHandle as any);
127
115
 
128
- const displayIdentifier = identifierType === 'email' ? identifier : `${countryCode}${identifier}`;
116
+ const displayIdentifier = 'email' in auth ? auth.email : `${auth.countryCode}${auth.phone}`;
129
117
 
130
118
  const requestJson: PasskeyCreateRequest = {
131
119
  authenticatorSelection: {
@@ -193,19 +181,12 @@ export class ParaMobile extends ParaCore {
193
181
  }
194
182
 
195
183
  /**
196
- * Logs in the user using either email or phone number.
197
- * @param {string} [email] - The user's email address.
198
- * @param {string} [phone] - The user's phone number.
199
- * @returns {Promise<Wallet[]>} An array of user wallets.
184
+ * Logs in the user using their authentication credentials.
185
+ * @param {AuthParams} params - The authentication parameters.
186
+ * @returns {Promise<void>}
200
187
  */
201
- async login({ email, phone, countryCode }: { email?: string; phone?: string; countryCode?: string }): Promise<void> {
188
+ async login({ ...auth }: Auth<'email'> | Auth<'phone'>): Promise<void> {
202
189
  await this.logout();
203
- const auth = extractAuthInfo({ email, phone, countryCode })?.auth;
204
-
205
- if (!auth) {
206
- throw new Error('No auth provided');
207
- }
208
-
209
190
  const { challenge, allowedPublicKeys } = await this.ctx.client.getWebChallenge(auth);
210
191
 
211
192
  const requestJson: PasskeyGetRequest = {