@getpara/react-native-wallet 1.0.2-dev.2 → 1.0.2-dev.4
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,10 @@
|
|
|
1
1
|
import { ConstructorOpts, ParaCore, Environment, PlatformUtils } from '@getpara/web-sdk';
|
|
2
|
-
import { webcrypto } from 'crypto';
|
|
3
|
-
import { CountryCallingCode } from 'libphonenumber-js';
|
|
4
2
|
/**
|
|
5
3
|
* Represents a mobile implementation of the Para SDK.
|
|
6
4
|
* @extends ParaCore
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* const para = new ParaMobile(Environment.BETA, "api_key");
|
|
7
8
|
*/
|
|
8
9
|
export declare class ParaMobile extends ParaCore {
|
|
9
10
|
private relyingPartyId;
|
|
@@ -21,31 +22,39 @@ export declare class ParaMobile extends ParaCore {
|
|
|
21
22
|
* @param {string} verificationCode - The verification code sent to the email.
|
|
22
23
|
* @returns {Promise<string>} The biometrics ID.
|
|
23
24
|
*/
|
|
24
|
-
verifyEmailBiometricsId(verificationCode
|
|
25
|
+
verifyEmailBiometricsId({ verificationCode }: {
|
|
26
|
+
verificationCode: string;
|
|
27
|
+
}): Promise<string>;
|
|
25
28
|
/**
|
|
26
29
|
* Verifies a phone number and returns the biometrics ID.
|
|
27
30
|
* @param {string} verificationCode - The verification code sent to the phone.
|
|
28
31
|
* @returns {Promise<string>} The biometrics ID.
|
|
29
32
|
*/
|
|
30
|
-
verifyPhoneBiometricsId(verificationCode
|
|
33
|
+
verifyPhoneBiometricsId({ verificationCode }: {
|
|
34
|
+
verificationCode: string;
|
|
35
|
+
}): Promise<string>;
|
|
31
36
|
/**
|
|
32
37
|
* Registers a passkey for the user.
|
|
33
38
|
* @param {string} identifier - The user's email or phone number.
|
|
34
39
|
* @param {string} biometricsId - The biometrics ID obtained from verification.
|
|
35
|
-
* @param {webcrypto.Crypto} crypto - The Web Crypto API instance.
|
|
36
40
|
* @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
|
|
43
|
+
registerPasskey({ identifier, biometricsId, identifierType, countryCode, }: {
|
|
44
|
+
identifier: string;
|
|
45
|
+
biometricsId: string;
|
|
46
|
+
identifierType?: 'email' | 'phone';
|
|
47
|
+
countryCode?: string;
|
|
48
|
+
}): Promise<void>;
|
|
41
49
|
/**
|
|
42
50
|
* Logs in the user using either email or phone number.
|
|
43
51
|
* @param {string} [email] - The user's email address.
|
|
44
52
|
* @param {string} [phone] - The user's phone number.
|
|
45
|
-
* @param {CountryCallingCode} [countryCode] - The country calling code for phone numbers.
|
|
46
53
|
* @returns {Promise<Wallet[]>} An array of user wallets.
|
|
47
54
|
*/
|
|
48
|
-
login(email
|
|
49
|
-
|
|
50
|
-
|
|
55
|
+
login({ email, phone, countryCode }: {
|
|
56
|
+
email?: string;
|
|
57
|
+
phone?: string;
|
|
58
|
+
countryCode?: string;
|
|
59
|
+
}): Promise<void>;
|
|
51
60
|
}
|
|
@@ -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) {
|
|
@@ -14,11 +13,15 @@ import { Passkey, } from 'react-native-passkey';
|
|
|
14
13
|
import { extractAuthInfo, 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(
|
|
64
|
+
verifyEmailBiometricsId(_a) {
|
|
62
65
|
const _super = Object.create(null, {
|
|
63
66
|
verifyEmail: { get: () => super.verifyEmail }
|
|
64
67
|
});
|
|
65
|
-
return __awaiter(this,
|
|
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(
|
|
81
|
+
verifyPhoneBiometricsId(_a) {
|
|
79
82
|
const _super = Object.create(null, {
|
|
80
83
|
verifyPhone: { get: () => super.verifyPhone }
|
|
81
84
|
});
|
|
82
|
-
return __awaiter(this,
|
|
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('?');
|
|
@@ -91,15 +94,16 @@ export class ParaMobile extends ParaCore {
|
|
|
91
94
|
* Registers a passkey for the user.
|
|
92
95
|
* @param {string} identifier - The user's email or phone number.
|
|
93
96
|
* @param {string} biometricsId - The biometrics ID obtained from verification.
|
|
94
|
-
* @param {webcrypto.Crypto} crypto - The Web Crypto API instance.
|
|
95
97
|
* @param {'email' | 'phone'} [identifierType='email'] - The type of identifier used.
|
|
96
|
-
* @param {CountryCallingCode} [countryCode] - The country calling code for phone numbers.
|
|
97
98
|
* @returns {Promise<void>}
|
|
98
99
|
*/
|
|
99
|
-
registerPasskey(
|
|
100
|
-
return __awaiter(this, arguments, void 0, function* (identifier, biometricsId,
|
|
100
|
+
registerPasskey(_a) {
|
|
101
|
+
return __awaiter(this, arguments, void 0, function* ({ identifier, biometricsId, identifierType = 'email', countryCode, }) {
|
|
102
|
+
if (!webcrypto || !webcrypto.getRandomValues) {
|
|
103
|
+
throw new Error('Web crypto is not available. Ensure you have imported the shim from @getpara/react-native-wallet.');
|
|
104
|
+
}
|
|
101
105
|
const userHandle = new Uint8Array(32);
|
|
102
|
-
|
|
106
|
+
webcrypto.getRandomValues(userHandle);
|
|
103
107
|
const userHandleEncoded = base64url.encode(userHandle);
|
|
104
108
|
const displayIdentifier = identifierType === 'email' ? identifier : `${countryCode}${identifier}`;
|
|
105
109
|
const requestJson = {
|
|
@@ -160,14 +164,13 @@ export class ParaMobile extends ParaCore {
|
|
|
160
164
|
* Logs in the user using either email or phone number.
|
|
161
165
|
* @param {string} [email] - The user's email address.
|
|
162
166
|
* @param {string} [phone] - The user's phone number.
|
|
163
|
-
* @param {CountryCallingCode} [countryCode] - The country calling code for phone numbers.
|
|
164
167
|
* @returns {Promise<Wallet[]>} An array of user wallets.
|
|
165
168
|
*/
|
|
166
|
-
login(
|
|
167
|
-
return __awaiter(this,
|
|
168
|
-
var
|
|
169
|
+
login(_a) {
|
|
170
|
+
return __awaiter(this, arguments, void 0, function* ({ email, phone, countryCode }) {
|
|
171
|
+
var _b;
|
|
169
172
|
yield this.logout();
|
|
170
|
-
const auth = (
|
|
173
|
+
const auth = (_b = extractAuthInfo({ email, phone, countryCode })) === null || _b === void 0 ? void 0 : _b.auth;
|
|
171
174
|
if (!auth) {
|
|
172
175
|
throw new Error('No auth provided');
|
|
173
176
|
}
|
|
@@ -238,10 +241,4 @@ export class ParaMobile extends ParaCore {
|
|
|
238
241
|
yield this.setWallets(walletsToInsert);
|
|
239
242
|
});
|
|
240
243
|
}
|
|
241
|
-
isPortal() {
|
|
242
|
-
return false;
|
|
243
|
-
}
|
|
244
|
-
isParaConnect() {
|
|
245
|
-
return false;
|
|
246
|
-
}
|
|
247
244
|
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// Copyright (c) Para Labs Inc. All rights reserved.
|
|
2
|
-
|
|
3
1
|
import {
|
|
4
2
|
ConstructorOpts,
|
|
5
3
|
ParaCore,
|
|
@@ -26,7 +24,6 @@ import { extractAuthInfo, PublicKeyStatus, WalletScheme } from '@getpara/user-ma
|
|
|
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('?');
|
|
@@ -104,20 +104,25 @@ export class ParaMobile extends ParaCore {
|
|
|
104
104
|
* Registers a passkey for the user.
|
|
105
105
|
* @param {string} identifier - The user's email or phone number.
|
|
106
106
|
* @param {string} biometricsId - The biometrics ID obtained from verification.
|
|
107
|
-
* @param {webcrypto.Crypto} crypto - The Web Crypto API instance.
|
|
108
107
|
* @param {'email' | 'phone'} [identifierType='email'] - The type of identifier used.
|
|
109
|
-
* @param {CountryCallingCode} [countryCode] - The country calling code for phone numbers.
|
|
110
108
|
* @returns {Promise<void>}
|
|
111
109
|
*/
|
|
112
|
-
async registerPasskey(
|
|
113
|
-
identifier
|
|
114
|
-
biometricsId
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
+
}) {
|
|
121
|
+
if (!webcrypto || !webcrypto.getRandomValues) {
|
|
122
|
+
throw new Error('Web crypto is not available. Ensure you have imported the shim from @getpara/react-native-wallet.');
|
|
123
|
+
}
|
|
119
124
|
const userHandle = new Uint8Array(32);
|
|
120
|
-
|
|
125
|
+
webcrypto.getRandomValues(userHandle);
|
|
121
126
|
const userHandleEncoded = base64url.encode(userHandle as any);
|
|
122
127
|
|
|
123
128
|
const displayIdentifier = identifierType === 'email' ? identifier : `${countryCode}${identifier}`;
|
|
@@ -191,10 +196,9 @@ export class ParaMobile extends ParaCore {
|
|
|
191
196
|
* Logs in the user using either email or phone number.
|
|
192
197
|
* @param {string} [email] - The user's email address.
|
|
193
198
|
* @param {string} [phone] - The user's phone number.
|
|
194
|
-
* @param {CountryCallingCode} [countryCode] - The country calling code for phone numbers.
|
|
195
199
|
* @returns {Promise<Wallet[]>} An array of user wallets.
|
|
196
200
|
*/
|
|
197
|
-
async login(email?: string
|
|
201
|
+
async login({ email, phone, countryCode }: { email?: string; phone?: string; countryCode?: string }): Promise<void> {
|
|
198
202
|
await this.logout();
|
|
199
203
|
const auth = extractAuthInfo({ email, phone, countryCode })?.auth;
|
|
200
204
|
|
|
@@ -296,12 +300,4 @@ export class ParaMobile extends ParaCore {
|
|
|
296
300
|
|
|
297
301
|
await this.setWallets(walletsToInsert);
|
|
298
302
|
}
|
|
299
|
-
|
|
300
|
-
protected isPortal(): boolean {
|
|
301
|
-
return false;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
protected isParaConnect(): boolean {
|
|
305
|
-
return false;
|
|
306
|
-
}
|
|
307
303
|
}
|