@openfort/openfort-js 0.7.4 → 0.7.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.
- package/dist/index.cjs +201 -48
- package/dist/index.d.ts +13 -5
- package/dist/index.js +182 -48
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -9,10 +9,30 @@ var bytes = require('@ethersproject/bytes');
|
|
|
9
9
|
var events = require('events');
|
|
10
10
|
var uuid = require('uuid');
|
|
11
11
|
var jose = require('jose');
|
|
12
|
+
var crypto = require('crypto');
|
|
12
13
|
var secp256k1 = require('@noble/curves/secp256k1');
|
|
13
14
|
var signingKey = require('@ethersproject/signing-key');
|
|
14
15
|
var transactions = require('@ethersproject/transactions');
|
|
15
16
|
|
|
17
|
+
function _interopNamespaceDefault(e) {
|
|
18
|
+
var n = Object.create(null);
|
|
19
|
+
if (e) {
|
|
20
|
+
Object.keys(e).forEach(function (k) {
|
|
21
|
+
if (k !== 'default') {
|
|
22
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
23
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () { return e[k]; }
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
n.default = e;
|
|
31
|
+
return Object.freeze(n);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var crypto__namespace = /*#__PURE__*/_interopNamespaceDefault(crypto);
|
|
35
|
+
|
|
16
36
|
exports.EmbeddedState = void 0;
|
|
17
37
|
(function (EmbeddedState) {
|
|
18
38
|
EmbeddedState[EmbeddedState["NONE"] = 0] = "NONE";
|
|
@@ -61,6 +81,11 @@ exports.OAuthProvider = void 0;
|
|
|
61
81
|
OAuthProvider["TWITTER"] = "twitter";
|
|
62
82
|
OAuthProvider["FACEBOOK"] = "facebook";
|
|
63
83
|
})(exports.OAuthProvider || (exports.OAuthProvider = {}));
|
|
84
|
+
var CodeChallengeMethodEnum;
|
|
85
|
+
(function (CodeChallengeMethodEnum) {
|
|
86
|
+
CodeChallengeMethodEnum["PLAIN"] = "plain";
|
|
87
|
+
CodeChallengeMethodEnum["S256"] = "S256";
|
|
88
|
+
})(CodeChallengeMethodEnum || (CodeChallengeMethodEnum = {}));
|
|
64
89
|
|
|
65
90
|
/* tslint:disable */
|
|
66
91
|
/* eslint-disable */
|
|
@@ -1287,13 +1312,13 @@ const AuthenticationApiAxiosParamCreator = function (configuration) {
|
|
|
1287
1312
|
/**
|
|
1288
1313
|
* Start the Email Verification process for a player.
|
|
1289
1314
|
* @summary Request an Email Verification.
|
|
1290
|
-
* @param {
|
|
1315
|
+
* @param {RequestVerifyEmailRequest} requestVerifyEmailRequest
|
|
1291
1316
|
* @param {*} [options] Override http request option.
|
|
1292
1317
|
* @throws {RequiredError}
|
|
1293
1318
|
*/
|
|
1294
|
-
requestEmailVerification: async (
|
|
1295
|
-
// verify required parameter '
|
|
1296
|
-
assertParamExists('requestEmailVerification', '
|
|
1319
|
+
requestEmailVerification: async (requestVerifyEmailRequest, options = {}) => {
|
|
1320
|
+
// verify required parameter 'requestVerifyEmailRequest' is not null or undefined
|
|
1321
|
+
assertParamExists('requestEmailVerification', 'requestVerifyEmailRequest', requestVerifyEmailRequest);
|
|
1297
1322
|
const localVarPath = `/iam/v1/password/email/request_verification`;
|
|
1298
1323
|
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
1299
1324
|
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
@@ -1311,7 +1336,7 @@ const AuthenticationApiAxiosParamCreator = function (configuration) {
|
|
|
1311
1336
|
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
1312
1337
|
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
1313
1338
|
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
1314
|
-
localVarRequestOptions.data = serializeDataIfNeeded(
|
|
1339
|
+
localVarRequestOptions.data = serializeDataIfNeeded(requestVerifyEmailRequest, localVarRequestOptions, configuration);
|
|
1315
1340
|
return {
|
|
1316
1341
|
url: toPathString(localVarUrlObj),
|
|
1317
1342
|
options: localVarRequestOptions,
|
|
@@ -1512,13 +1537,13 @@ const AuthenticationApiAxiosParamCreator = function (configuration) {
|
|
|
1512
1537
|
/**
|
|
1513
1538
|
* Verify a player\'s email address.
|
|
1514
1539
|
* @summary Verify an email.
|
|
1515
|
-
* @param {
|
|
1540
|
+
* @param {VerifyEmailRequest} verifyEmailRequest
|
|
1516
1541
|
* @param {*} [options] Override http request option.
|
|
1517
1542
|
* @throws {RequiredError}
|
|
1518
1543
|
*/
|
|
1519
|
-
verifyEmail: async (
|
|
1520
|
-
// verify required parameter '
|
|
1521
|
-
assertParamExists('verifyEmail', '
|
|
1544
|
+
verifyEmail: async (verifyEmailRequest, options = {}) => {
|
|
1545
|
+
// verify required parameter 'verifyEmailRequest' is not null or undefined
|
|
1546
|
+
assertParamExists('verifyEmail', 'verifyEmailRequest', verifyEmailRequest);
|
|
1522
1547
|
const localVarPath = `/iam/v1/password/email/verify`;
|
|
1523
1548
|
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
1524
1549
|
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
@@ -1536,7 +1561,7 @@ const AuthenticationApiAxiosParamCreator = function (configuration) {
|
|
|
1536
1561
|
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
1537
1562
|
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
1538
1563
|
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
1539
|
-
localVarRequestOptions.data = serializeDataIfNeeded(
|
|
1564
|
+
localVarRequestOptions.data = serializeDataIfNeeded(verifyEmailRequest, localVarRequestOptions, configuration);
|
|
1540
1565
|
return {
|
|
1541
1566
|
url: toPathString(localVarUrlObj),
|
|
1542
1567
|
options: localVarRequestOptions,
|
|
@@ -1768,12 +1793,12 @@ const AuthenticationApiFp = function (configuration) {
|
|
|
1768
1793
|
/**
|
|
1769
1794
|
* Start the Email Verification process for a player.
|
|
1770
1795
|
* @summary Request an Email Verification.
|
|
1771
|
-
* @param {
|
|
1796
|
+
* @param {RequestVerifyEmailRequest} requestVerifyEmailRequest
|
|
1772
1797
|
* @param {*} [options] Override http request option.
|
|
1773
1798
|
* @throws {RequiredError}
|
|
1774
1799
|
*/
|
|
1775
|
-
async requestEmailVerification(
|
|
1776
|
-
const localVarAxiosArgs = await localVarAxiosParamCreator.requestEmailVerification(
|
|
1800
|
+
async requestEmailVerification(requestVerifyEmailRequest, options) {
|
|
1801
|
+
const localVarAxiosArgs = await localVarAxiosParamCreator.requestEmailVerification(requestVerifyEmailRequest, options);
|
|
1777
1802
|
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
1778
1803
|
},
|
|
1779
1804
|
/**
|
|
@@ -1845,12 +1870,12 @@ const AuthenticationApiFp = function (configuration) {
|
|
|
1845
1870
|
/**
|
|
1846
1871
|
* Verify a player\'s email address.
|
|
1847
1872
|
* @summary Verify an email.
|
|
1848
|
-
* @param {
|
|
1873
|
+
* @param {VerifyEmailRequest} verifyEmailRequest
|
|
1849
1874
|
* @param {*} [options] Override http request option.
|
|
1850
1875
|
* @throws {RequiredError}
|
|
1851
1876
|
*/
|
|
1852
|
-
async verifyEmail(
|
|
1853
|
-
const localVarAxiosArgs = await localVarAxiosParamCreator.verifyEmail(
|
|
1877
|
+
async verifyEmail(verifyEmailRequest, options) {
|
|
1878
|
+
const localVarAxiosArgs = await localVarAxiosParamCreator.verifyEmail(verifyEmailRequest, options);
|
|
1854
1879
|
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
1855
1880
|
},
|
|
1856
1881
|
/**
|
|
@@ -2037,7 +2062,7 @@ class AuthenticationApi extends BaseAPI {
|
|
|
2037
2062
|
* @memberof AuthenticationApi
|
|
2038
2063
|
*/
|
|
2039
2064
|
requestEmailVerification(requestParameters, options) {
|
|
2040
|
-
return AuthenticationApiFp(this.configuration).requestEmailVerification(requestParameters.
|
|
2065
|
+
return AuthenticationApiFp(this.configuration).requestEmailVerification(requestParameters.requestVerifyEmailRequest, options).then((request) => request(this.axios, this.basePath));
|
|
2041
2066
|
}
|
|
2042
2067
|
/**
|
|
2043
2068
|
* Start the Reset process for a player\'s password.
|
|
@@ -2114,7 +2139,7 @@ class AuthenticationApi extends BaseAPI {
|
|
|
2114
2139
|
* @memberof AuthenticationApi
|
|
2115
2140
|
*/
|
|
2116
2141
|
verifyEmail(requestParameters, options) {
|
|
2117
|
-
return AuthenticationApiFp(this.configuration).verifyEmail(requestParameters.
|
|
2142
|
+
return AuthenticationApiFp(this.configuration).verifyEmail(requestParameters.verifyEmailRequest, options).then((request) => request(this.axios, this.basePath));
|
|
2118
2143
|
}
|
|
2119
2144
|
/**
|
|
2120
2145
|
* The endpoint verifies the token generated by OAuth provider and retrieves a corresponding player. Returns the latest 10 transaction intents for the player.
|
|
@@ -4505,12 +4530,42 @@ var SignerType;
|
|
|
4505
4530
|
|
|
4506
4531
|
const isBrowser = () => typeof document !== 'undefined';
|
|
4507
4532
|
|
|
4533
|
+
const KEY_PKCE_STATE = 'pkce_state';
|
|
4534
|
+
const KEY_PKCE_VERIFIER = 'pkce_verifier';
|
|
4535
|
+
class DeviceCredentialsManager {
|
|
4536
|
+
savePKCEData(data) {
|
|
4537
|
+
localStorage.setItem(KEY_PKCE_STATE, data.state);
|
|
4538
|
+
localStorage.setItem(KEY_PKCE_VERIFIER, data.verifier);
|
|
4539
|
+
}
|
|
4540
|
+
getPKCEData() {
|
|
4541
|
+
const state = localStorage.getItem(KEY_PKCE_STATE);
|
|
4542
|
+
const verifier = localStorage.getItem(KEY_PKCE_VERIFIER);
|
|
4543
|
+
if (state && verifier) {
|
|
4544
|
+
return { state, verifier };
|
|
4545
|
+
}
|
|
4546
|
+
return null;
|
|
4547
|
+
}
|
|
4548
|
+
}
|
|
4549
|
+
|
|
4550
|
+
function base64URLEncode(str) {
|
|
4551
|
+
return str.toString('base64')
|
|
4552
|
+
.replace(/\+/g, '-')
|
|
4553
|
+
.replace(/\//g, '_')
|
|
4554
|
+
.replace(/=/g, '');
|
|
4555
|
+
}
|
|
4556
|
+
function sha256(buffer) {
|
|
4557
|
+
return crypto__namespace.createHash('sha256').update(buffer).digest();
|
|
4558
|
+
}
|
|
4508
4559
|
class AuthManager {
|
|
4509
4560
|
config;
|
|
4561
|
+
deviceCredentialsManager;
|
|
4562
|
+
instanceManager;
|
|
4510
4563
|
backendApiClients;
|
|
4511
|
-
constructor(config, backendApiClients) {
|
|
4564
|
+
constructor(config, backendApiClients, instanceManager) {
|
|
4512
4565
|
this.config = config;
|
|
4566
|
+
this.deviceCredentialsManager = new DeviceCredentialsManager();
|
|
4513
4567
|
this.backendApiClients = backendApiClients;
|
|
4568
|
+
this.instanceManager = instanceManager;
|
|
4514
4569
|
}
|
|
4515
4570
|
async initOAuth(provider, usePooling, options) {
|
|
4516
4571
|
const request = {
|
|
@@ -4521,7 +4576,7 @@ class AuthManager {
|
|
|
4521
4576
|
},
|
|
4522
4577
|
};
|
|
4523
4578
|
const result = await this.backendApiClients.authenticationApi.initOAuth(request);
|
|
4524
|
-
if (isBrowser() &&
|
|
4579
|
+
if (isBrowser() && options?.skipBrowserRedirect) {
|
|
4525
4580
|
window.location.assign(result.data.url);
|
|
4526
4581
|
}
|
|
4527
4582
|
return {
|
|
@@ -4558,6 +4613,13 @@ class AuthManager {
|
|
|
4558
4613
|
// eslint-disable-next-line no-await-in-loop
|
|
4559
4614
|
const response = await this.backendApiClients.authenticationApi.poolOAuth(request);
|
|
4560
4615
|
if (response.status === 200) {
|
|
4616
|
+
this.instanceManager.setAccessToken({
|
|
4617
|
+
token: response.data.token,
|
|
4618
|
+
thirdPartyProvider: null,
|
|
4619
|
+
thirdPartyTokenType: null,
|
|
4620
|
+
});
|
|
4621
|
+
this.instanceManager.setRefreshToken(response.data.refreshToken);
|
|
4622
|
+
this.instanceManager.setPlayerID(response.data.player.id);
|
|
4561
4623
|
return response.data;
|
|
4562
4624
|
}
|
|
4563
4625
|
}
|
|
@@ -4574,7 +4636,7 @@ class AuthManager {
|
|
|
4574
4636
|
}
|
|
4575
4637
|
throw new Error('Failed to pool OAuth, try again later');
|
|
4576
4638
|
}
|
|
4577
|
-
//
|
|
4639
|
+
// @deprecated
|
|
4578
4640
|
async authenticateOAuth(provider, token, tokenType) {
|
|
4579
4641
|
const request = {
|
|
4580
4642
|
authenticateOAuthRequest: {
|
|
@@ -4632,6 +4694,83 @@ class AuthManager {
|
|
|
4632
4694
|
const response = await this.backendApiClients.authenticationApi.loginEmailPassword(request);
|
|
4633
4695
|
return response.data;
|
|
4634
4696
|
}
|
|
4697
|
+
async requestResetPassword(email, redirectUrl) {
|
|
4698
|
+
const verifier = base64URLEncode(crypto__namespace.randomBytes(32));
|
|
4699
|
+
const challenge = base64URLEncode(sha256(verifier));
|
|
4700
|
+
// https://auth0.com/docs/secure/attack-protection/state-parameters
|
|
4701
|
+
const state = base64URLEncode(crypto__namespace.randomBytes(32));
|
|
4702
|
+
this.deviceCredentialsManager.savePKCEData({ state, verifier });
|
|
4703
|
+
const request = {
|
|
4704
|
+
requestResetPasswordRequest: {
|
|
4705
|
+
email,
|
|
4706
|
+
redirectUrl,
|
|
4707
|
+
challenge: {
|
|
4708
|
+
codeChallenge: challenge,
|
|
4709
|
+
method: CodeChallengeMethodEnum.S256,
|
|
4710
|
+
},
|
|
4711
|
+
},
|
|
4712
|
+
};
|
|
4713
|
+
await this.backendApiClients.authenticationApi.requestResetPassword(request);
|
|
4714
|
+
}
|
|
4715
|
+
async resetPassword(email, password, state) {
|
|
4716
|
+
const pkceData = this.deviceCredentialsManager.getPKCEData();
|
|
4717
|
+
if (!pkceData) {
|
|
4718
|
+
throw new Error('No code verifier or state for PKCE');
|
|
4719
|
+
}
|
|
4720
|
+
if (state !== pkceData.state) {
|
|
4721
|
+
throw new Error('Provided state does not match stored state');
|
|
4722
|
+
}
|
|
4723
|
+
const request = {
|
|
4724
|
+
resetPasswordRequest: {
|
|
4725
|
+
email,
|
|
4726
|
+
password,
|
|
4727
|
+
state,
|
|
4728
|
+
challenge: {
|
|
4729
|
+
codeVerifier: pkceData.verifier,
|
|
4730
|
+
method: CodeChallengeMethodEnum.S256,
|
|
4731
|
+
},
|
|
4732
|
+
},
|
|
4733
|
+
};
|
|
4734
|
+
await this.backendApiClients.authenticationApi.resetPassword(request);
|
|
4735
|
+
}
|
|
4736
|
+
async requestEmailVerification(email, redirectUrl) {
|
|
4737
|
+
const verifier = base64URLEncode(crypto__namespace.randomBytes(32));
|
|
4738
|
+
const challenge = base64URLEncode(sha256(verifier));
|
|
4739
|
+
// https://auth0.com/docs/secure/attack-protection/state-parameters
|
|
4740
|
+
const state = base64URLEncode(crypto__namespace.randomBytes(32));
|
|
4741
|
+
this.deviceCredentialsManager.savePKCEData({ state, verifier });
|
|
4742
|
+
const request = {
|
|
4743
|
+
requestVerifyEmailRequest: {
|
|
4744
|
+
email,
|
|
4745
|
+
redirectUrl,
|
|
4746
|
+
challenge: {
|
|
4747
|
+
codeChallenge: challenge,
|
|
4748
|
+
method: CodeChallengeMethodEnum.S256,
|
|
4749
|
+
},
|
|
4750
|
+
},
|
|
4751
|
+
};
|
|
4752
|
+
await this.backendApiClients.authenticationApi.requestEmailVerification(request);
|
|
4753
|
+
}
|
|
4754
|
+
async verifyEmail(email, state) {
|
|
4755
|
+
const pkceData = this.deviceCredentialsManager.getPKCEData();
|
|
4756
|
+
if (!pkceData) {
|
|
4757
|
+
throw new Error('No code verifier or state for PKCE');
|
|
4758
|
+
}
|
|
4759
|
+
if (state !== pkceData.state) {
|
|
4760
|
+
throw new Error('Provided state does not match stored state');
|
|
4761
|
+
}
|
|
4762
|
+
const request = {
|
|
4763
|
+
verifyEmailRequest: {
|
|
4764
|
+
email,
|
|
4765
|
+
token: state,
|
|
4766
|
+
challenge: {
|
|
4767
|
+
codeVerifier: pkceData.verifier,
|
|
4768
|
+
method: CodeChallengeMethodEnum.S256,
|
|
4769
|
+
},
|
|
4770
|
+
},
|
|
4771
|
+
};
|
|
4772
|
+
await this.backendApiClients.authenticationApi.verifyEmail(request);
|
|
4773
|
+
}
|
|
4635
4774
|
async signupEmailPassword(email, password, name) {
|
|
4636
4775
|
const request = {
|
|
4637
4776
|
signupRequest: {
|
|
@@ -4643,23 +4782,6 @@ class AuthManager {
|
|
|
4643
4782
|
const response = await this.backendApiClients.authenticationApi.signupEmailPassword(request);
|
|
4644
4783
|
return response.data;
|
|
4645
4784
|
}
|
|
4646
|
-
async getJWK() {
|
|
4647
|
-
const request = {
|
|
4648
|
-
publishableKey: this.config.baseConfiguration.publishableKey,
|
|
4649
|
-
};
|
|
4650
|
-
const response = await this.backendApiClients.authenticationApi.getJwks(request);
|
|
4651
|
-
if (response.data.keys.length === 0) {
|
|
4652
|
-
throw new Error('No keys found');
|
|
4653
|
-
}
|
|
4654
|
-
const jwtKey = response.data.keys[0];
|
|
4655
|
-
return {
|
|
4656
|
-
kty: jwtKey.kty,
|
|
4657
|
-
crv: jwtKey.crv,
|
|
4658
|
-
x: jwtKey.x,
|
|
4659
|
-
y: jwtKey.y,
|
|
4660
|
-
alg: jwtKey.alg,
|
|
4661
|
-
};
|
|
4662
|
-
}
|
|
4663
4785
|
async validateCredentials(accessToken, refreshToken, jwk) {
|
|
4664
4786
|
try {
|
|
4665
4787
|
const key = (await jose.importJWK({
|
|
@@ -4722,7 +4844,6 @@ const accountTypeStorageKey = 'openfort.account_type';
|
|
|
4722
4844
|
const accountAddressStorageKey = 'openfort.account_address';
|
|
4723
4845
|
|
|
4724
4846
|
class InstanceManager {
|
|
4725
|
-
authManager;
|
|
4726
4847
|
authToken = null;
|
|
4727
4848
|
refreshToken = null;
|
|
4728
4849
|
signerType = null;
|
|
@@ -4735,12 +4856,15 @@ class InstanceManager {
|
|
|
4735
4856
|
temporalStorage;
|
|
4736
4857
|
persistentStorage;
|
|
4737
4858
|
secureStorage;
|
|
4859
|
+
config;
|
|
4860
|
+
backendApiClients;
|
|
4738
4861
|
playerId = null;
|
|
4739
|
-
constructor(temporalStorage, persistentStorage, secureStorage,
|
|
4862
|
+
constructor(temporalStorage, persistentStorage, secureStorage, config, backendApiClients) {
|
|
4740
4863
|
this.temporalStorage = temporalStorage;
|
|
4741
4864
|
this.persistentStorage = persistentStorage;
|
|
4742
4865
|
this.secureStorage = secureStorage;
|
|
4743
|
-
this.
|
|
4866
|
+
this.config = config;
|
|
4867
|
+
this.backendApiClients = backendApiClients;
|
|
4744
4868
|
}
|
|
4745
4869
|
getAccessToken() {
|
|
4746
4870
|
if (!this.authToken) {
|
|
@@ -4852,7 +4976,21 @@ class InstanceManager {
|
|
|
4852
4976
|
}
|
|
4853
4977
|
}
|
|
4854
4978
|
if (!this.jwk) {
|
|
4855
|
-
|
|
4979
|
+
const request = {
|
|
4980
|
+
publishableKey: this.config.baseConfiguration.publishableKey,
|
|
4981
|
+
};
|
|
4982
|
+
const response = await this.backendApiClients.authenticationApi.getJwks(request);
|
|
4983
|
+
if (response.data.keys.length === 0) {
|
|
4984
|
+
throw new Error('No keys found');
|
|
4985
|
+
}
|
|
4986
|
+
const jwtKey = response.data.keys[0];
|
|
4987
|
+
this.jwk = {
|
|
4988
|
+
kty: jwtKey.kty,
|
|
4989
|
+
crv: jwtKey.crv,
|
|
4990
|
+
x: jwtKey.x,
|
|
4991
|
+
y: jwtKey.y,
|
|
4992
|
+
alg: jwtKey.alg,
|
|
4993
|
+
};
|
|
4856
4994
|
}
|
|
4857
4995
|
return this.jwk;
|
|
4858
4996
|
}
|
|
@@ -5546,15 +5684,15 @@ class Openfort {
|
|
|
5546
5684
|
signer;
|
|
5547
5685
|
authManager;
|
|
5548
5686
|
config;
|
|
5549
|
-
instanceManager;
|
|
5550
5687
|
backendApiClients;
|
|
5688
|
+
instanceManager;
|
|
5551
5689
|
iframeManager;
|
|
5552
5690
|
openfortEventEmitter;
|
|
5553
5691
|
constructor(sdkConfiguration) {
|
|
5554
5692
|
this.config = new SDKConfiguration(sdkConfiguration);
|
|
5555
5693
|
this.backendApiClients = new BackendApiClients(this.config.openfortAPIConfig);
|
|
5556
|
-
this.
|
|
5557
|
-
this.
|
|
5694
|
+
this.instanceManager = new InstanceManager(new SessionStorage(), new LocalStorage(), new LocalStorage(), this.config, this.backendApiClients);
|
|
5695
|
+
this.authManager = new AuthManager(this.config, this.backendApiClients, this.instanceManager);
|
|
5558
5696
|
this.openfortEventEmitter = new TypedEventEmitter();
|
|
5559
5697
|
this.iframeManager = new IframeManager(this.config);
|
|
5560
5698
|
}
|
|
@@ -5691,8 +5829,21 @@ class Openfort {
|
|
|
5691
5829
|
});
|
|
5692
5830
|
return result;
|
|
5693
5831
|
}
|
|
5832
|
+
async requestEmailVerification(email, redirectUrl) {
|
|
5833
|
+
await this.authManager.requestEmailVerification(email, redirectUrl);
|
|
5834
|
+
}
|
|
5835
|
+
async resetPassword(email, password, state) {
|
|
5836
|
+
await this.authManager.resetPassword(email, password, state);
|
|
5837
|
+
}
|
|
5838
|
+
async requestResetPassword(email, redirectUrl) {
|
|
5839
|
+
await this.authManager.requestResetPassword(email, redirectUrl);
|
|
5840
|
+
}
|
|
5841
|
+
async verifyEmail(email, state) {
|
|
5842
|
+
await this.authManager.verifyEmail(email, state);
|
|
5843
|
+
}
|
|
5694
5844
|
async initOAuth(provider, usePooling, options) {
|
|
5695
|
-
|
|
5845
|
+
const authResponse = await this.authManager.initOAuth(provider, usePooling, options);
|
|
5846
|
+
return authResponse;
|
|
5696
5847
|
}
|
|
5697
5848
|
async initLinkOAuth(provider, playerToken, usePooling, options) {
|
|
5698
5849
|
return await this.authManager.initLinkOAuth(provider, playerToken, usePooling, options);
|
|
@@ -5700,6 +5851,7 @@ class Openfort {
|
|
|
5700
5851
|
async poolOAuth(key) {
|
|
5701
5852
|
return await this.authManager.poolOAuth(key);
|
|
5702
5853
|
}
|
|
5854
|
+
// @deprecated
|
|
5703
5855
|
async authenticateWithOAuth(provider, token, tokenType) {
|
|
5704
5856
|
this.instanceManager.removeAccessToken();
|
|
5705
5857
|
this.instanceManager.removeRefreshToken();
|
|
@@ -5773,7 +5925,7 @@ class Openfort {
|
|
|
5773
5925
|
const result = await this.backendApiClients.transactionIntentsApi.signature(request);
|
|
5774
5926
|
return result.data;
|
|
5775
5927
|
}
|
|
5776
|
-
async signMessage(message) {
|
|
5928
|
+
async signMessage(message, options) {
|
|
5777
5929
|
await this.recoverSigner();
|
|
5778
5930
|
if (!this.signer) {
|
|
5779
5931
|
throw new NoSignerConfigured('No signer configured');
|
|
@@ -5781,7 +5933,8 @@ class Openfort {
|
|
|
5781
5933
|
if (this.signer.useCredentials()) {
|
|
5782
5934
|
await this.validateAndRefreshToken();
|
|
5783
5935
|
}
|
|
5784
|
-
|
|
5936
|
+
const { hashMessage = true, arrayifyMessage = false } = options || {};
|
|
5937
|
+
return await this.signer.sign(message, arrayifyMessage, hashMessage);
|
|
5785
5938
|
}
|
|
5786
5939
|
async signTypedData(domain, types, value) {
|
|
5787
5940
|
await this.recoverSigner();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SessionKey, AuthResponse, OAuthProvider as OAuthProvider$1, InitializeOAuthOptions as InitializeOAuthOptions$1, InitAuthResponse, TokenType as TokenType$1, SIWEInitResponse, ThirdPartyOAuthProvider as ThirdPartyOAuthProvider$1, AuthPlayerResponse as AuthPlayerResponse$1, TransactionIntentResponse as TransactionIntentResponse$1, SessionResponse as SessionResponse$1, EmbeddedState as EmbeddedState$1, SDKOverrides as SDKOverrides$1 } from 'types';
|
|
1
|
+
import { SessionKey, AuthResponse, OAuthProvider as OAuthProvider$1, InitializeOAuthOptions as InitializeOAuthOptions$1, InitAuthResponse, TokenType as TokenType$1, SIWEInitResponse, ThirdPartyOAuthProvider as ThirdPartyOAuthProvider$1, AuthPlayerResponse as AuthPlayerResponse$1, Auth, TransactionIntentResponse as TransactionIntentResponse$1, SessionResponse as SessionResponse$1, EmbeddedState as EmbeddedState$1, SDKOverrides as SDKOverrides$1 } from 'types';
|
|
2
2
|
import { SDKConfiguration as SDKConfiguration$1 } from 'config';
|
|
3
3
|
import { Provider as Provider$1 } from 'evm/types';
|
|
4
4
|
|
|
@@ -71,8 +71,8 @@ declare class Openfort {
|
|
|
71
71
|
private signer?;
|
|
72
72
|
private readonly authManager;
|
|
73
73
|
private readonly config;
|
|
74
|
-
private readonly instanceManager;
|
|
75
74
|
private readonly backendApiClients;
|
|
75
|
+
private readonly instanceManager;
|
|
76
76
|
private readonly iframeManager;
|
|
77
77
|
private readonly openfortEventEmitter;
|
|
78
78
|
constructor(sdkConfiguration: SDKConfiguration$1);
|
|
@@ -87,6 +87,10 @@ declare class Openfort {
|
|
|
87
87
|
private newEmbeddedSigner;
|
|
88
88
|
loginWithEmailPassword(email: string, password: string): Promise<AuthResponse>;
|
|
89
89
|
signUpWithEmailPassword(email: string, password: string, name?: string): Promise<AuthResponse>;
|
|
90
|
+
requestEmailVerification(email: string, redirectUrl: string): Promise<void>;
|
|
91
|
+
resetPassword(email: string, password: string, state: string): Promise<void>;
|
|
92
|
+
requestResetPassword(email: string, redirectUrl: string): Promise<void>;
|
|
93
|
+
verifyEmail(email: string, state: string): Promise<void>;
|
|
90
94
|
initOAuth(provider: OAuthProvider$1, usePooling?: boolean, options?: InitializeOAuthOptions$1): Promise<InitAuthResponse>;
|
|
91
95
|
initLinkOAuth(provider: OAuthProvider$1, playerToken: string, usePooling?: boolean, options?: InitializeOAuthOptions$1): Promise<InitAuthResponse>;
|
|
92
96
|
poolOAuth(key: string): Promise<AuthResponse>;
|
|
@@ -94,9 +98,12 @@ declare class Openfort {
|
|
|
94
98
|
initSIWE(address: string): Promise<SIWEInitResponse>;
|
|
95
99
|
authenticateWithThirdPartyProvider(provider: ThirdPartyOAuthProvider$1, token: string, tokenType: TokenType$1): Promise<AuthPlayerResponse$1>;
|
|
96
100
|
authenticateWithSIWE(signature: string, message: string, walletClientType: string, connectorType: string): Promise<AuthResponse>;
|
|
97
|
-
|
|
101
|
+
storeCredentials(auth: Auth): void;
|
|
98
102
|
sendSignatureTransactionIntentRequest(transactionIntentId: string, userOperationHash?: string | null, signature?: string | null): Promise<TransactionIntentResponse$1>;
|
|
99
|
-
signMessage(message: string | Uint8Array
|
|
103
|
+
signMessage(message: string | Uint8Array, options?: {
|
|
104
|
+
hashMessage?: boolean;
|
|
105
|
+
arrayifyMessage?: boolean;
|
|
106
|
+
}): Promise<string>;
|
|
100
107
|
signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): Promise<string>;
|
|
101
108
|
sendRegisterSessionRequest(sessionId: string, signature: string, optimistic?: boolean): Promise<SessionResponse$1>;
|
|
102
109
|
private recoverSigner;
|
|
@@ -106,7 +113,7 @@ declare class Openfort {
|
|
|
106
113
|
isAuthenticated(): Promise<boolean>;
|
|
107
114
|
getAccessToken(): string | null;
|
|
108
115
|
isLoaded(): boolean;
|
|
109
|
-
|
|
116
|
+
validateAndRefreshToken(): Promise<void>;
|
|
110
117
|
}
|
|
111
118
|
|
|
112
119
|
declare enum ShieldAuthProvider {
|
|
@@ -357,6 +364,7 @@ interface LinkedAccountResponse {
|
|
|
357
364
|
'provider': AuthProvider;
|
|
358
365
|
'email'?: string;
|
|
359
366
|
'externalUserId'?: string;
|
|
367
|
+
'verified'?: boolean;
|
|
360
368
|
'disabled': boolean;
|
|
361
369
|
'updatedAt'?: number;
|
|
362
370
|
'address'?: string;
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { hexlify, joinSignature, arrayify } from '@ethersproject/bytes';
|
|
|
5
5
|
import { EventEmitter } from 'events';
|
|
6
6
|
import { v4 } from 'uuid';
|
|
7
7
|
import { importJWK, jwtVerify, errors } from 'jose';
|
|
8
|
+
import * as crypto from 'crypto';
|
|
8
9
|
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
9
10
|
import { SigningKey } from '@ethersproject/signing-key';
|
|
10
11
|
import { computeAddress } from '@ethersproject/transactions';
|
|
@@ -57,6 +58,11 @@ var OAuthProvider;
|
|
|
57
58
|
OAuthProvider["TWITTER"] = "twitter";
|
|
58
59
|
OAuthProvider["FACEBOOK"] = "facebook";
|
|
59
60
|
})(OAuthProvider || (OAuthProvider = {}));
|
|
61
|
+
var CodeChallengeMethodEnum;
|
|
62
|
+
(function (CodeChallengeMethodEnum) {
|
|
63
|
+
CodeChallengeMethodEnum["PLAIN"] = "plain";
|
|
64
|
+
CodeChallengeMethodEnum["S256"] = "S256";
|
|
65
|
+
})(CodeChallengeMethodEnum || (CodeChallengeMethodEnum = {}));
|
|
60
66
|
|
|
61
67
|
/* tslint:disable */
|
|
62
68
|
/* eslint-disable */
|
|
@@ -1283,13 +1289,13 @@ const AuthenticationApiAxiosParamCreator = function (configuration) {
|
|
|
1283
1289
|
/**
|
|
1284
1290
|
* Start the Email Verification process for a player.
|
|
1285
1291
|
* @summary Request an Email Verification.
|
|
1286
|
-
* @param {
|
|
1292
|
+
* @param {RequestVerifyEmailRequest} requestVerifyEmailRequest
|
|
1287
1293
|
* @param {*} [options] Override http request option.
|
|
1288
1294
|
* @throws {RequiredError}
|
|
1289
1295
|
*/
|
|
1290
|
-
requestEmailVerification: async (
|
|
1291
|
-
// verify required parameter '
|
|
1292
|
-
assertParamExists('requestEmailVerification', '
|
|
1296
|
+
requestEmailVerification: async (requestVerifyEmailRequest, options = {}) => {
|
|
1297
|
+
// verify required parameter 'requestVerifyEmailRequest' is not null or undefined
|
|
1298
|
+
assertParamExists('requestEmailVerification', 'requestVerifyEmailRequest', requestVerifyEmailRequest);
|
|
1293
1299
|
const localVarPath = `/iam/v1/password/email/request_verification`;
|
|
1294
1300
|
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
1295
1301
|
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
@@ -1307,7 +1313,7 @@ const AuthenticationApiAxiosParamCreator = function (configuration) {
|
|
|
1307
1313
|
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
1308
1314
|
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
1309
1315
|
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
1310
|
-
localVarRequestOptions.data = serializeDataIfNeeded(
|
|
1316
|
+
localVarRequestOptions.data = serializeDataIfNeeded(requestVerifyEmailRequest, localVarRequestOptions, configuration);
|
|
1311
1317
|
return {
|
|
1312
1318
|
url: toPathString(localVarUrlObj),
|
|
1313
1319
|
options: localVarRequestOptions,
|
|
@@ -1508,13 +1514,13 @@ const AuthenticationApiAxiosParamCreator = function (configuration) {
|
|
|
1508
1514
|
/**
|
|
1509
1515
|
* Verify a player\'s email address.
|
|
1510
1516
|
* @summary Verify an email.
|
|
1511
|
-
* @param {
|
|
1517
|
+
* @param {VerifyEmailRequest} verifyEmailRequest
|
|
1512
1518
|
* @param {*} [options] Override http request option.
|
|
1513
1519
|
* @throws {RequiredError}
|
|
1514
1520
|
*/
|
|
1515
|
-
verifyEmail: async (
|
|
1516
|
-
// verify required parameter '
|
|
1517
|
-
assertParamExists('verifyEmail', '
|
|
1521
|
+
verifyEmail: async (verifyEmailRequest, options = {}) => {
|
|
1522
|
+
// verify required parameter 'verifyEmailRequest' is not null or undefined
|
|
1523
|
+
assertParamExists('verifyEmail', 'verifyEmailRequest', verifyEmailRequest);
|
|
1518
1524
|
const localVarPath = `/iam/v1/password/email/verify`;
|
|
1519
1525
|
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
1520
1526
|
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
@@ -1532,7 +1538,7 @@ const AuthenticationApiAxiosParamCreator = function (configuration) {
|
|
|
1532
1538
|
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
1533
1539
|
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
1534
1540
|
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
1535
|
-
localVarRequestOptions.data = serializeDataIfNeeded(
|
|
1541
|
+
localVarRequestOptions.data = serializeDataIfNeeded(verifyEmailRequest, localVarRequestOptions, configuration);
|
|
1536
1542
|
return {
|
|
1537
1543
|
url: toPathString(localVarUrlObj),
|
|
1538
1544
|
options: localVarRequestOptions,
|
|
@@ -1764,12 +1770,12 @@ const AuthenticationApiFp = function (configuration) {
|
|
|
1764
1770
|
/**
|
|
1765
1771
|
* Start the Email Verification process for a player.
|
|
1766
1772
|
* @summary Request an Email Verification.
|
|
1767
|
-
* @param {
|
|
1773
|
+
* @param {RequestVerifyEmailRequest} requestVerifyEmailRequest
|
|
1768
1774
|
* @param {*} [options] Override http request option.
|
|
1769
1775
|
* @throws {RequiredError}
|
|
1770
1776
|
*/
|
|
1771
|
-
async requestEmailVerification(
|
|
1772
|
-
const localVarAxiosArgs = await localVarAxiosParamCreator.requestEmailVerification(
|
|
1777
|
+
async requestEmailVerification(requestVerifyEmailRequest, options) {
|
|
1778
|
+
const localVarAxiosArgs = await localVarAxiosParamCreator.requestEmailVerification(requestVerifyEmailRequest, options);
|
|
1773
1779
|
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
1774
1780
|
},
|
|
1775
1781
|
/**
|
|
@@ -1841,12 +1847,12 @@ const AuthenticationApiFp = function (configuration) {
|
|
|
1841
1847
|
/**
|
|
1842
1848
|
* Verify a player\'s email address.
|
|
1843
1849
|
* @summary Verify an email.
|
|
1844
|
-
* @param {
|
|
1850
|
+
* @param {VerifyEmailRequest} verifyEmailRequest
|
|
1845
1851
|
* @param {*} [options] Override http request option.
|
|
1846
1852
|
* @throws {RequiredError}
|
|
1847
1853
|
*/
|
|
1848
|
-
async verifyEmail(
|
|
1849
|
-
const localVarAxiosArgs = await localVarAxiosParamCreator.verifyEmail(
|
|
1854
|
+
async verifyEmail(verifyEmailRequest, options) {
|
|
1855
|
+
const localVarAxiosArgs = await localVarAxiosParamCreator.verifyEmail(verifyEmailRequest, options);
|
|
1850
1856
|
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
1851
1857
|
},
|
|
1852
1858
|
/**
|
|
@@ -2033,7 +2039,7 @@ class AuthenticationApi extends BaseAPI {
|
|
|
2033
2039
|
* @memberof AuthenticationApi
|
|
2034
2040
|
*/
|
|
2035
2041
|
requestEmailVerification(requestParameters, options) {
|
|
2036
|
-
return AuthenticationApiFp(this.configuration).requestEmailVerification(requestParameters.
|
|
2042
|
+
return AuthenticationApiFp(this.configuration).requestEmailVerification(requestParameters.requestVerifyEmailRequest, options).then((request) => request(this.axios, this.basePath));
|
|
2037
2043
|
}
|
|
2038
2044
|
/**
|
|
2039
2045
|
* Start the Reset process for a player\'s password.
|
|
@@ -2110,7 +2116,7 @@ class AuthenticationApi extends BaseAPI {
|
|
|
2110
2116
|
* @memberof AuthenticationApi
|
|
2111
2117
|
*/
|
|
2112
2118
|
verifyEmail(requestParameters, options) {
|
|
2113
|
-
return AuthenticationApiFp(this.configuration).verifyEmail(requestParameters.
|
|
2119
|
+
return AuthenticationApiFp(this.configuration).verifyEmail(requestParameters.verifyEmailRequest, options).then((request) => request(this.axios, this.basePath));
|
|
2114
2120
|
}
|
|
2115
2121
|
/**
|
|
2116
2122
|
* The endpoint verifies the token generated by OAuth provider and retrieves a corresponding player. Returns the latest 10 transaction intents for the player.
|
|
@@ -4501,12 +4507,42 @@ var SignerType;
|
|
|
4501
4507
|
|
|
4502
4508
|
const isBrowser = () => typeof document !== 'undefined';
|
|
4503
4509
|
|
|
4510
|
+
const KEY_PKCE_STATE = 'pkce_state';
|
|
4511
|
+
const KEY_PKCE_VERIFIER = 'pkce_verifier';
|
|
4512
|
+
class DeviceCredentialsManager {
|
|
4513
|
+
savePKCEData(data) {
|
|
4514
|
+
localStorage.setItem(KEY_PKCE_STATE, data.state);
|
|
4515
|
+
localStorage.setItem(KEY_PKCE_VERIFIER, data.verifier);
|
|
4516
|
+
}
|
|
4517
|
+
getPKCEData() {
|
|
4518
|
+
const state = localStorage.getItem(KEY_PKCE_STATE);
|
|
4519
|
+
const verifier = localStorage.getItem(KEY_PKCE_VERIFIER);
|
|
4520
|
+
if (state && verifier) {
|
|
4521
|
+
return { state, verifier };
|
|
4522
|
+
}
|
|
4523
|
+
return null;
|
|
4524
|
+
}
|
|
4525
|
+
}
|
|
4526
|
+
|
|
4527
|
+
function base64URLEncode(str) {
|
|
4528
|
+
return str.toString('base64')
|
|
4529
|
+
.replace(/\+/g, '-')
|
|
4530
|
+
.replace(/\//g, '_')
|
|
4531
|
+
.replace(/=/g, '');
|
|
4532
|
+
}
|
|
4533
|
+
function sha256(buffer) {
|
|
4534
|
+
return crypto.createHash('sha256').update(buffer).digest();
|
|
4535
|
+
}
|
|
4504
4536
|
class AuthManager {
|
|
4505
4537
|
config;
|
|
4538
|
+
deviceCredentialsManager;
|
|
4539
|
+
instanceManager;
|
|
4506
4540
|
backendApiClients;
|
|
4507
|
-
constructor(config, backendApiClients) {
|
|
4541
|
+
constructor(config, backendApiClients, instanceManager) {
|
|
4508
4542
|
this.config = config;
|
|
4543
|
+
this.deviceCredentialsManager = new DeviceCredentialsManager();
|
|
4509
4544
|
this.backendApiClients = backendApiClients;
|
|
4545
|
+
this.instanceManager = instanceManager;
|
|
4510
4546
|
}
|
|
4511
4547
|
async initOAuth(provider, usePooling, options) {
|
|
4512
4548
|
const request = {
|
|
@@ -4517,7 +4553,7 @@ class AuthManager {
|
|
|
4517
4553
|
},
|
|
4518
4554
|
};
|
|
4519
4555
|
const result = await this.backendApiClients.authenticationApi.initOAuth(request);
|
|
4520
|
-
if (isBrowser() &&
|
|
4556
|
+
if (isBrowser() && options?.skipBrowserRedirect) {
|
|
4521
4557
|
window.location.assign(result.data.url);
|
|
4522
4558
|
}
|
|
4523
4559
|
return {
|
|
@@ -4554,6 +4590,13 @@ class AuthManager {
|
|
|
4554
4590
|
// eslint-disable-next-line no-await-in-loop
|
|
4555
4591
|
const response = await this.backendApiClients.authenticationApi.poolOAuth(request);
|
|
4556
4592
|
if (response.status === 200) {
|
|
4593
|
+
this.instanceManager.setAccessToken({
|
|
4594
|
+
token: response.data.token,
|
|
4595
|
+
thirdPartyProvider: null,
|
|
4596
|
+
thirdPartyTokenType: null,
|
|
4597
|
+
});
|
|
4598
|
+
this.instanceManager.setRefreshToken(response.data.refreshToken);
|
|
4599
|
+
this.instanceManager.setPlayerID(response.data.player.id);
|
|
4557
4600
|
return response.data;
|
|
4558
4601
|
}
|
|
4559
4602
|
}
|
|
@@ -4570,7 +4613,7 @@ class AuthManager {
|
|
|
4570
4613
|
}
|
|
4571
4614
|
throw new Error('Failed to pool OAuth, try again later');
|
|
4572
4615
|
}
|
|
4573
|
-
//
|
|
4616
|
+
// @deprecated
|
|
4574
4617
|
async authenticateOAuth(provider, token, tokenType) {
|
|
4575
4618
|
const request = {
|
|
4576
4619
|
authenticateOAuthRequest: {
|
|
@@ -4628,6 +4671,83 @@ class AuthManager {
|
|
|
4628
4671
|
const response = await this.backendApiClients.authenticationApi.loginEmailPassword(request);
|
|
4629
4672
|
return response.data;
|
|
4630
4673
|
}
|
|
4674
|
+
async requestResetPassword(email, redirectUrl) {
|
|
4675
|
+
const verifier = base64URLEncode(crypto.randomBytes(32));
|
|
4676
|
+
const challenge = base64URLEncode(sha256(verifier));
|
|
4677
|
+
// https://auth0.com/docs/secure/attack-protection/state-parameters
|
|
4678
|
+
const state = base64URLEncode(crypto.randomBytes(32));
|
|
4679
|
+
this.deviceCredentialsManager.savePKCEData({ state, verifier });
|
|
4680
|
+
const request = {
|
|
4681
|
+
requestResetPasswordRequest: {
|
|
4682
|
+
email,
|
|
4683
|
+
redirectUrl,
|
|
4684
|
+
challenge: {
|
|
4685
|
+
codeChallenge: challenge,
|
|
4686
|
+
method: CodeChallengeMethodEnum.S256,
|
|
4687
|
+
},
|
|
4688
|
+
},
|
|
4689
|
+
};
|
|
4690
|
+
await this.backendApiClients.authenticationApi.requestResetPassword(request);
|
|
4691
|
+
}
|
|
4692
|
+
async resetPassword(email, password, state) {
|
|
4693
|
+
const pkceData = this.deviceCredentialsManager.getPKCEData();
|
|
4694
|
+
if (!pkceData) {
|
|
4695
|
+
throw new Error('No code verifier or state for PKCE');
|
|
4696
|
+
}
|
|
4697
|
+
if (state !== pkceData.state) {
|
|
4698
|
+
throw new Error('Provided state does not match stored state');
|
|
4699
|
+
}
|
|
4700
|
+
const request = {
|
|
4701
|
+
resetPasswordRequest: {
|
|
4702
|
+
email,
|
|
4703
|
+
password,
|
|
4704
|
+
state,
|
|
4705
|
+
challenge: {
|
|
4706
|
+
codeVerifier: pkceData.verifier,
|
|
4707
|
+
method: CodeChallengeMethodEnum.S256,
|
|
4708
|
+
},
|
|
4709
|
+
},
|
|
4710
|
+
};
|
|
4711
|
+
await this.backendApiClients.authenticationApi.resetPassword(request);
|
|
4712
|
+
}
|
|
4713
|
+
async requestEmailVerification(email, redirectUrl) {
|
|
4714
|
+
const verifier = base64URLEncode(crypto.randomBytes(32));
|
|
4715
|
+
const challenge = base64URLEncode(sha256(verifier));
|
|
4716
|
+
// https://auth0.com/docs/secure/attack-protection/state-parameters
|
|
4717
|
+
const state = base64URLEncode(crypto.randomBytes(32));
|
|
4718
|
+
this.deviceCredentialsManager.savePKCEData({ state, verifier });
|
|
4719
|
+
const request = {
|
|
4720
|
+
requestVerifyEmailRequest: {
|
|
4721
|
+
email,
|
|
4722
|
+
redirectUrl,
|
|
4723
|
+
challenge: {
|
|
4724
|
+
codeChallenge: challenge,
|
|
4725
|
+
method: CodeChallengeMethodEnum.S256,
|
|
4726
|
+
},
|
|
4727
|
+
},
|
|
4728
|
+
};
|
|
4729
|
+
await this.backendApiClients.authenticationApi.requestEmailVerification(request);
|
|
4730
|
+
}
|
|
4731
|
+
async verifyEmail(email, state) {
|
|
4732
|
+
const pkceData = this.deviceCredentialsManager.getPKCEData();
|
|
4733
|
+
if (!pkceData) {
|
|
4734
|
+
throw new Error('No code verifier or state for PKCE');
|
|
4735
|
+
}
|
|
4736
|
+
if (state !== pkceData.state) {
|
|
4737
|
+
throw new Error('Provided state does not match stored state');
|
|
4738
|
+
}
|
|
4739
|
+
const request = {
|
|
4740
|
+
verifyEmailRequest: {
|
|
4741
|
+
email,
|
|
4742
|
+
token: state,
|
|
4743
|
+
challenge: {
|
|
4744
|
+
codeVerifier: pkceData.verifier,
|
|
4745
|
+
method: CodeChallengeMethodEnum.S256,
|
|
4746
|
+
},
|
|
4747
|
+
},
|
|
4748
|
+
};
|
|
4749
|
+
await this.backendApiClients.authenticationApi.verifyEmail(request);
|
|
4750
|
+
}
|
|
4631
4751
|
async signupEmailPassword(email, password, name) {
|
|
4632
4752
|
const request = {
|
|
4633
4753
|
signupRequest: {
|
|
@@ -4639,23 +4759,6 @@ class AuthManager {
|
|
|
4639
4759
|
const response = await this.backendApiClients.authenticationApi.signupEmailPassword(request);
|
|
4640
4760
|
return response.data;
|
|
4641
4761
|
}
|
|
4642
|
-
async getJWK() {
|
|
4643
|
-
const request = {
|
|
4644
|
-
publishableKey: this.config.baseConfiguration.publishableKey,
|
|
4645
|
-
};
|
|
4646
|
-
const response = await this.backendApiClients.authenticationApi.getJwks(request);
|
|
4647
|
-
if (response.data.keys.length === 0) {
|
|
4648
|
-
throw new Error('No keys found');
|
|
4649
|
-
}
|
|
4650
|
-
const jwtKey = response.data.keys[0];
|
|
4651
|
-
return {
|
|
4652
|
-
kty: jwtKey.kty,
|
|
4653
|
-
crv: jwtKey.crv,
|
|
4654
|
-
x: jwtKey.x,
|
|
4655
|
-
y: jwtKey.y,
|
|
4656
|
-
alg: jwtKey.alg,
|
|
4657
|
-
};
|
|
4658
|
-
}
|
|
4659
4762
|
async validateCredentials(accessToken, refreshToken, jwk) {
|
|
4660
4763
|
try {
|
|
4661
4764
|
const key = (await importJWK({
|
|
@@ -4718,7 +4821,6 @@ const accountTypeStorageKey = 'openfort.account_type';
|
|
|
4718
4821
|
const accountAddressStorageKey = 'openfort.account_address';
|
|
4719
4822
|
|
|
4720
4823
|
class InstanceManager {
|
|
4721
|
-
authManager;
|
|
4722
4824
|
authToken = null;
|
|
4723
4825
|
refreshToken = null;
|
|
4724
4826
|
signerType = null;
|
|
@@ -4731,12 +4833,15 @@ class InstanceManager {
|
|
|
4731
4833
|
temporalStorage;
|
|
4732
4834
|
persistentStorage;
|
|
4733
4835
|
secureStorage;
|
|
4836
|
+
config;
|
|
4837
|
+
backendApiClients;
|
|
4734
4838
|
playerId = null;
|
|
4735
|
-
constructor(temporalStorage, persistentStorage, secureStorage,
|
|
4839
|
+
constructor(temporalStorage, persistentStorage, secureStorage, config, backendApiClients) {
|
|
4736
4840
|
this.temporalStorage = temporalStorage;
|
|
4737
4841
|
this.persistentStorage = persistentStorage;
|
|
4738
4842
|
this.secureStorage = secureStorage;
|
|
4739
|
-
this.
|
|
4843
|
+
this.config = config;
|
|
4844
|
+
this.backendApiClients = backendApiClients;
|
|
4740
4845
|
}
|
|
4741
4846
|
getAccessToken() {
|
|
4742
4847
|
if (!this.authToken) {
|
|
@@ -4848,7 +4953,21 @@ class InstanceManager {
|
|
|
4848
4953
|
}
|
|
4849
4954
|
}
|
|
4850
4955
|
if (!this.jwk) {
|
|
4851
|
-
|
|
4956
|
+
const request = {
|
|
4957
|
+
publishableKey: this.config.baseConfiguration.publishableKey,
|
|
4958
|
+
};
|
|
4959
|
+
const response = await this.backendApiClients.authenticationApi.getJwks(request);
|
|
4960
|
+
if (response.data.keys.length === 0) {
|
|
4961
|
+
throw new Error('No keys found');
|
|
4962
|
+
}
|
|
4963
|
+
const jwtKey = response.data.keys[0];
|
|
4964
|
+
this.jwk = {
|
|
4965
|
+
kty: jwtKey.kty,
|
|
4966
|
+
crv: jwtKey.crv,
|
|
4967
|
+
x: jwtKey.x,
|
|
4968
|
+
y: jwtKey.y,
|
|
4969
|
+
alg: jwtKey.alg,
|
|
4970
|
+
};
|
|
4852
4971
|
}
|
|
4853
4972
|
return this.jwk;
|
|
4854
4973
|
}
|
|
@@ -5542,15 +5661,15 @@ class Openfort {
|
|
|
5542
5661
|
signer;
|
|
5543
5662
|
authManager;
|
|
5544
5663
|
config;
|
|
5545
|
-
instanceManager;
|
|
5546
5664
|
backendApiClients;
|
|
5665
|
+
instanceManager;
|
|
5547
5666
|
iframeManager;
|
|
5548
5667
|
openfortEventEmitter;
|
|
5549
5668
|
constructor(sdkConfiguration) {
|
|
5550
5669
|
this.config = new SDKConfiguration(sdkConfiguration);
|
|
5551
5670
|
this.backendApiClients = new BackendApiClients(this.config.openfortAPIConfig);
|
|
5552
|
-
this.
|
|
5553
|
-
this.
|
|
5671
|
+
this.instanceManager = new InstanceManager(new SessionStorage(), new LocalStorage(), new LocalStorage(), this.config, this.backendApiClients);
|
|
5672
|
+
this.authManager = new AuthManager(this.config, this.backendApiClients, this.instanceManager);
|
|
5554
5673
|
this.openfortEventEmitter = new TypedEventEmitter();
|
|
5555
5674
|
this.iframeManager = new IframeManager(this.config);
|
|
5556
5675
|
}
|
|
@@ -5687,8 +5806,21 @@ class Openfort {
|
|
|
5687
5806
|
});
|
|
5688
5807
|
return result;
|
|
5689
5808
|
}
|
|
5809
|
+
async requestEmailVerification(email, redirectUrl) {
|
|
5810
|
+
await this.authManager.requestEmailVerification(email, redirectUrl);
|
|
5811
|
+
}
|
|
5812
|
+
async resetPassword(email, password, state) {
|
|
5813
|
+
await this.authManager.resetPassword(email, password, state);
|
|
5814
|
+
}
|
|
5815
|
+
async requestResetPassword(email, redirectUrl) {
|
|
5816
|
+
await this.authManager.requestResetPassword(email, redirectUrl);
|
|
5817
|
+
}
|
|
5818
|
+
async verifyEmail(email, state) {
|
|
5819
|
+
await this.authManager.verifyEmail(email, state);
|
|
5820
|
+
}
|
|
5690
5821
|
async initOAuth(provider, usePooling, options) {
|
|
5691
|
-
|
|
5822
|
+
const authResponse = await this.authManager.initOAuth(provider, usePooling, options);
|
|
5823
|
+
return authResponse;
|
|
5692
5824
|
}
|
|
5693
5825
|
async initLinkOAuth(provider, playerToken, usePooling, options) {
|
|
5694
5826
|
return await this.authManager.initLinkOAuth(provider, playerToken, usePooling, options);
|
|
@@ -5696,6 +5828,7 @@ class Openfort {
|
|
|
5696
5828
|
async poolOAuth(key) {
|
|
5697
5829
|
return await this.authManager.poolOAuth(key);
|
|
5698
5830
|
}
|
|
5831
|
+
// @deprecated
|
|
5699
5832
|
async authenticateWithOAuth(provider, token, tokenType) {
|
|
5700
5833
|
this.instanceManager.removeAccessToken();
|
|
5701
5834
|
this.instanceManager.removeRefreshToken();
|
|
@@ -5769,7 +5902,7 @@ class Openfort {
|
|
|
5769
5902
|
const result = await this.backendApiClients.transactionIntentsApi.signature(request);
|
|
5770
5903
|
return result.data;
|
|
5771
5904
|
}
|
|
5772
|
-
async signMessage(message) {
|
|
5905
|
+
async signMessage(message, options) {
|
|
5773
5906
|
await this.recoverSigner();
|
|
5774
5907
|
if (!this.signer) {
|
|
5775
5908
|
throw new NoSignerConfigured('No signer configured');
|
|
@@ -5777,7 +5910,8 @@ class Openfort {
|
|
|
5777
5910
|
if (this.signer.useCredentials()) {
|
|
5778
5911
|
await this.validateAndRefreshToken();
|
|
5779
5912
|
}
|
|
5780
|
-
|
|
5913
|
+
const { hashMessage = true, arrayifyMessage = false } = options || {};
|
|
5914
|
+
return await this.signer.sign(message, arrayifyMessage, hashMessage);
|
|
5781
5915
|
}
|
|
5782
5916
|
async signTypedData(domain, types, value) {
|
|
5783
5917
|
await this.recoverSigner();
|
package/package.json
CHANGED