@getpara/react-native-wallet 1.0.2-dev.3 → 1.0.2-dev.5

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,9 +1,11 @@
1
1
  import { ConstructorOpts, ParaCore, Environment, PlatformUtils } from '@getpara/web-sdk';
2
- import { webcrypto } from 'crypto';
3
- import { CountryCallingCode } from 'libphonenumber-js';
2
+ import { Auth } from '@getpara/user-management-client';
4
3
  /**
5
4
  * Represents a mobile implementation of the Para SDK.
6
5
  * @extends ParaCore
6
+ *
7
+ * @example
8
+ * const para = new ParaMobile(Environment.BETA, "api_key");
7
9
  */
8
10
  export declare class ParaMobile extends ParaCore {
9
11
  private relyingPartyId;
@@ -21,29 +23,31 @@ export declare class ParaMobile extends ParaCore {
21
23
  * @param {string} verificationCode - The verification code sent to the email.
22
24
  * @returns {Promise<string>} The biometrics ID.
23
25
  */
24
- verifyEmailBiometricsId(verificationCode: string): Promise<string>;
26
+ verifyEmailBiometricsId({ verificationCode }: {
27
+ verificationCode: string;
28
+ }): Promise<string>;
25
29
  /**
26
30
  * Verifies a phone number and returns the biometrics ID.
27
31
  * @param {string} verificationCode - The verification code sent to the phone.
28
32
  * @returns {Promise<string>} The biometrics ID.
29
33
  */
30
- verifyPhoneBiometricsId(verificationCode: string): Promise<string>;
34
+ verifyPhoneBiometricsId({ verificationCode }: {
35
+ verificationCode: string;
36
+ }): Promise<string>;
31
37
  /**
32
38
  * Registers a passkey for the user.
33
- * @param {string} identifier - The user's email or phone number.
39
+ * @param {Auth<'email'> | Auth<'phone'>} auth - The user's authentication details
34
40
  * @param {string} biometricsId - The biometrics ID obtained from verification.
35
- * @param {webcrypto.Crypto} crypto - The Web Crypto API instance.
36
- * @param {'email' | 'phone'} [identifierType='email'] - The type of identifier used.
37
- * @param {CountryCallingCode} [countryCode] - The country calling code for phone numbers.
38
41
  * @returns {Promise<void>}
39
42
  */
40
- registerPasskey(identifier: string, biometricsId: string, crypto: webcrypto.Crypto, identifierType?: 'email' | 'phone', countryCode?: CountryCallingCode): Promise<void>;
43
+ registerPasskey({ auth, biometricsId }: {
44
+ auth: Auth<'email'> | Auth<'phone'>;
45
+ biometricsId: string;
46
+ }): Promise<void>;
41
47
  /**
42
- * Logs in the user using either email or phone number.
43
- * @param {string} [email] - The user's email address.
44
- * @param {string} [phone] - The user's phone number.
45
- * @param {CountryCallingCode} [countryCode] - The country calling code for phone numbers.
46
- * @returns {Promise<Wallet[]>} An array of user wallets.
48
+ * Logs in the user using their authentication credentials.
49
+ * @param {AuthParams} params - The authentication parameters.
50
+ * @returns {Promise<void>}
47
51
  */
48
- login(email?: string, phone?: string, countryCode?: CountryCallingCode): Promise<void>;
52
+ login(auth: Auth<'email'> | Auth<'phone'>): Promise<void>;
49
53
  }
@@ -1,4 +1,3 @@
1
- // Copyright (c) Para Labs Inc. All rights reserved.
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -11,14 +10,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
10
  import { ParaCore, Environment, decryptPrivateKeyAndDecryptShare, encryptPrivateKey, getAsymmetricKeyPair, getDerivedPrivateKeyAndDecrypt, getPublicKeyHex, getSHA256HashHex, parseCredentialCreationRes, } from '@getpara/web-sdk';
12
11
  import { ReactNativeUtils } from './ReactNativeUtils.js';
13
12
  import { Passkey, } from 'react-native-passkey';
14
- import { extractAuthInfo, PublicKeyStatus } from '@getpara/user-management-client';
13
+ import { PublicKeyStatus } from '@getpara/user-management-client';
15
14
  import { setEnv } from '../config.js';
16
15
  import base64url from 'base64url';
16
+ import { webcrypto } from 'crypto';
17
17
  const ES256_ALGORITHM = -7;
18
18
  const RS256_ALGORITHM = -257;
19
19
  /**
20
20
  * Represents a mobile implementation of the Para SDK.
21
21
  * @extends ParaCore
22
+ *
23
+ * @example
24
+ * const para = new ParaMobile(Environment.BETA, "api_key");
22
25
  */
23
26
  export class ParaMobile extends ParaCore {
24
27
  /**
@@ -58,11 +61,11 @@ export class ParaMobile extends ParaCore {
58
61
  * @param {string} verificationCode - The verification code sent to the email.
59
62
  * @returns {Promise<string>} The biometrics ID.
60
63
  */
61
- verifyEmailBiometricsId(verificationCode) {
64
+ verifyEmailBiometricsId(_a) {
62
65
  const _super = Object.create(null, {
63
66
  verifyEmail: { get: () => super.verifyEmail }
64
67
  });
65
- return __awaiter(this, void 0, void 0, function* () {
68
+ return __awaiter(this, arguments, void 0, function* ({ verificationCode }) {
66
69
  const webAuthCreateUrl = yield _super.verifyEmail.call(this, { verificationCode });
67
70
  const segments = webAuthCreateUrl.split('/');
68
71
  const segments2 = segments[segments.length - 1].split('?');
@@ -75,11 +78,11 @@ export class ParaMobile extends ParaCore {
75
78
  * @param {string} verificationCode - The verification code sent to the phone.
76
79
  * @returns {Promise<string>} The biometrics ID.
77
80
  */
78
- verifyPhoneBiometricsId(verificationCode) {
81
+ verifyPhoneBiometricsId(_a) {
79
82
  const _super = Object.create(null, {
80
83
  verifyPhone: { get: () => super.verifyPhone }
81
84
  });
82
- return __awaiter(this, void 0, void 0, function* () {
85
+ return __awaiter(this, arguments, void 0, function* ({ verificationCode }) {
83
86
  const webAuthCreateUrl = yield _super.verifyPhone.call(this, { verificationCode });
84
87
  const segments = webAuthCreateUrl.split('/');
85
88
  const segments2 = segments[segments.length - 1].split('?');
@@ -89,19 +92,19 @@ export class ParaMobile extends ParaCore {
89
92
  }
90
93
  /**
91
94
  * Registers a passkey for the user.
92
- * @param {string} identifier - The user's email or phone number.
95
+ * @param {Auth<'email'> | Auth<'phone'>} auth - The user's authentication details
93
96
  * @param {string} biometricsId - The biometrics ID obtained from verification.
94
- * @param {webcrypto.Crypto} crypto - The Web Crypto API instance.
95
- * @param {'email' | 'phone'} [identifierType='email'] - The type of identifier used.
96
- * @param {CountryCallingCode} [countryCode] - The country calling code for phone numbers.
97
97
  * @returns {Promise<void>}
98
98
  */
99
- registerPasskey(identifier_1, biometricsId_1, crypto_1) {
100
- return __awaiter(this, arguments, void 0, function* (identifier, biometricsId, crypto, identifierType = 'email', countryCode) {
99
+ registerPasskey(_a) {
100
+ return __awaiter(this, arguments, void 0, function* ({ auth, biometricsId }) {
101
+ if (!webcrypto || !webcrypto.getRandomValues) {
102
+ throw new Error('Web crypto is not available. Ensure you have imported the shim from @getpara/react-native-wallet.');
103
+ }
101
104
  const userHandle = new Uint8Array(32);
102
- crypto.getRandomValues(userHandle);
105
+ webcrypto.getRandomValues(userHandle);
103
106
  const userHandleEncoded = base64url.encode(userHandle);
104
- const displayIdentifier = identifierType === 'email' ? identifier : `${countryCode}${identifier}`;
107
+ const displayIdentifier = 'email' in auth ? auth.email : `${auth.countryCode}${auth.phone}`;
105
108
  const requestJson = {
106
109
  authenticatorSelection: {
107
110
  authenticatorAttachment: 'platform',
@@ -157,20 +160,13 @@ export class ParaMobile extends ParaCore {
157
160
  });
158
161
  }
159
162
  /**
160
- * Logs in the user using either email or phone number.
161
- * @param {string} [email] - The user's email address.
162
- * @param {string} [phone] - The user's phone number.
163
- * @param {CountryCallingCode} [countryCode] - The country calling code for phone numbers.
164
- * @returns {Promise<Wallet[]>} An array of user wallets.
163
+ * Logs in the user using their authentication credentials.
164
+ * @param {AuthParams} params - The authentication parameters.
165
+ * @returns {Promise<void>}
165
166
  */
166
- login(email, phone, countryCode) {
167
+ login(auth) {
167
168
  return __awaiter(this, void 0, void 0, function* () {
168
- var _a;
169
169
  yield this.logout();
170
- const auth = (_a = extractAuthInfo({ email, phone, countryCode })) === null || _a === void 0 ? void 0 : _a.auth;
171
- if (!auth) {
172
- throw new Error('No auth provided');
173
- }
174
170
  const { challenge, allowedPublicKeys } = yield this.ctx.client.getWebChallenge(auth);
175
171
  const requestJson = {
176
172
  challenge,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getpara/react-native-wallet",
3
- "version": "1.0.2-dev.3",
3
+ "version": "1.0.2-dev.5",
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)",
@@ -1,5 +1,3 @@
1
- // Copyright (c) Para Labs Inc. All rights reserved.
2
-
3
1
  import {
4
2
  ConstructorOpts,
5
3
  ParaCore,
@@ -22,11 +20,10 @@ import {
22
20
  PasskeyGetRequest,
23
21
  PasskeyGetResult,
24
22
  } from 'react-native-passkey';
25
- import { extractAuthInfo, PublicKeyStatus, WalletScheme } from '@getpara/user-management-client';
23
+ import { Auth, PublicKeyStatus, WalletScheme } from '@getpara/user-management-client';
26
24
  import { setEnv } from '../config.js';
27
25
  import base64url from 'base64url';
28
26
  import { webcrypto } from 'crypto';
29
- import { CountryCallingCode } from 'libphonenumber-js';
30
27
 
31
28
  const ES256_ALGORITHM = -7;
32
29
  const RS256_ALGORITHM = -257;
@@ -34,6 +31,9 @@ const RS256_ALGORITHM = -257;
34
31
  /**
35
32
  * Represents a mobile implementation of the Para SDK.
36
33
  * @extends ParaCore
34
+ *
35
+ * @example
36
+ * const para = new ParaMobile(Environment.BETA, "api_key");
37
37
  */
38
38
  export class ParaMobile extends ParaCore {
39
39
  private relyingPartyId: string;
@@ -77,7 +77,7 @@ export class ParaMobile extends ParaCore {
77
77
  * @param {string} verificationCode - The verification code sent to the email.
78
78
  * @returns {Promise<string>} The biometrics ID.
79
79
  */
80
- async verifyEmailBiometricsId(verificationCode: string): Promise<string> {
80
+ async verifyEmailBiometricsId({ verificationCode }: { verificationCode: string }): Promise<string> {
81
81
  const webAuthCreateUrl = await super.verifyEmail({ verificationCode });
82
82
  const segments = webAuthCreateUrl.split('/');
83
83
  const segments2 = segments[segments.length - 1]!.split('?');
@@ -91,7 +91,7 @@ export class ParaMobile extends ParaCore {
91
91
  * @param {string} verificationCode - The verification code sent to the phone.
92
92
  * @returns {Promise<string>} The biometrics ID.
93
93
  */
94
- async verifyPhoneBiometricsId(verificationCode: string): Promise<string> {
94
+ async verifyPhoneBiometricsId({ verificationCode }: { verificationCode: string }): Promise<string> {
95
95
  const webAuthCreateUrl = await super.verifyPhone({ verificationCode });
96
96
  const segments = webAuthCreateUrl.split('/');
97
97
  const segments2 = segments[segments.length - 1]!.split('?');
@@ -99,28 +99,21 @@ 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 {webcrypto.Crypto} crypto - The Web Crypto API instance.
108
- * @param {'email' | 'phone'} [identifierType='email'] - The type of identifier used.
109
- * @param {CountryCallingCode} [countryCode] - The country calling code for phone numbers.
110
106
  * @returns {Promise<void>}
111
107
  */
112
- async registerPasskey(
113
- identifier: string,
114
- biometricsId: string,
115
- crypto: webcrypto.Crypto,
116
- identifierType: 'email' | 'phone' = 'email',
117
- countryCode?: CountryCallingCode,
118
- ) {
108
+ async registerPasskey({ auth, biometricsId }: { auth: Auth<'email'> | Auth<'phone'>; biometricsId: string }) {
109
+ if (!webcrypto || !webcrypto.getRandomValues) {
110
+ throw new Error('Web crypto is not available. Ensure you have imported the shim from @getpara/react-native-wallet.');
111
+ }
119
112
  const userHandle = new Uint8Array(32);
120
- crypto.getRandomValues(userHandle);
113
+ webcrypto.getRandomValues(userHandle);
121
114
  const userHandleEncoded = base64url.encode(userHandle as any);
122
115
 
123
- const displayIdentifier = identifierType === 'email' ? identifier : `${countryCode}${identifier}`;
116
+ const displayIdentifier = 'email' in auth ? auth.email : `${auth.countryCode}${auth.phone}`;
124
117
 
125
118
  const requestJson: PasskeyCreateRequest = {
126
119
  authenticatorSelection: {
@@ -188,20 +181,12 @@ export class ParaMobile extends ParaCore {
188
181
  }
189
182
 
190
183
  /**
191
- * Logs in the user using either email or phone number.
192
- * @param {string} [email] - The user's email address.
193
- * @param {string} [phone] - The user's phone number.
194
- * @param {CountryCallingCode} [countryCode] - The country calling code for phone numbers.
195
- * @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>}
196
187
  */
197
- async login(email?: string, phone?: string, countryCode?: CountryCallingCode): Promise<void> {
188
+ async login(auth: Auth<'email'> | Auth<'phone'>): Promise<void> {
198
189
  await this.logout();
199
- const auth = extractAuthInfo({ email, phone, countryCode })?.auth;
200
-
201
- if (!auth) {
202
- throw new Error('No auth provided');
203
- }
204
-
205
190
  const { challenge, allowedPublicKeys } = await this.ctx.client.getWebChallenge(auth);
206
191
 
207
192
  const requestJson: PasskeyGetRequest = {