@openfort/openfort-js 0.8.2 → 0.8.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.
package/dist/index.cjs CHANGED
@@ -3207,7 +3207,7 @@ class KeyPair extends signingKey.SigningKey {
3207
3207
  }
3208
3208
  }
3209
3209
 
3210
- const VERSION = '0.8.2';
3210
+ const VERSION = '0.8.4';
3211
3211
 
3212
3212
  var Event;
3213
3213
  (function (Event) {
@@ -6105,10 +6105,13 @@ class Openfort {
6105
6105
  * Logs the user out by flushing the signer and removing credentials.
6106
6106
  */
6107
6107
  async logout() {
6108
- await SignerManager.fromStorage()?.logout();
6108
+ const signer = SignerManager.fromStorage();
6109
6109
  this.storage.remove(StorageKeys.AUTHENTICATION);
6110
6110
  this.storage.remove(StorageKeys.SIGNER);
6111
6111
  this.storage.remove(StorageKeys.ACCOUNT);
6112
+ if (signer) {
6113
+ await signer.logout();
6114
+ }
6112
6115
  }
6113
6116
  /**
6114
6117
  * Returns an Ethereum provider using the configured signer.
@@ -6275,9 +6278,9 @@ class Openfort {
6275
6278
  * @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
6276
6279
  * @returns An AuthResponse object containing authentication details.
6277
6280
  */
6278
- async signUpWithEmailPassword({ email, password, ecosystemGame }) {
6281
+ async signUpWithEmailPassword({ email, password, options, ecosystemGame, }) {
6279
6282
  const previousAuth = Authentication.fromStorage(this.storage);
6280
- const result = await this.authManager.signupEmailPassword(email, password, ecosystemGame);
6283
+ const result = await this.authManager.signupEmailPassword(email, password, options?.data.name, ecosystemGame);
6281
6284
  if (previousAuth && previousAuth.player !== result.player.id) {
6282
6285
  this.logout();
6283
6286
  }
@@ -6404,10 +6407,14 @@ class Openfort {
6404
6407
  async authenticateWithThirdPartyProvider({ provider, token, tokenType, ecosystemGame, }) {
6405
6408
  const previousAuth = Authentication.fromStorage(this.storage);
6406
6409
  const result = await this.authManager.authenticateThirdParty(provider, token, tokenType, ecosystemGame);
6410
+ let loggedOut = false;
6407
6411
  if (previousAuth && previousAuth.player !== result.id) {
6408
6412
  this.logout();
6413
+ loggedOut = true;
6409
6414
  }
6410
6415
  new Authentication('third_party', token, result.id, null, provider, tokenType).save(this.storage);
6416
+ if (loggedOut)
6417
+ return result;
6411
6418
  const signer = SignerManager.fromStorage();
6412
6419
  try {
6413
6420
  await signer?.updateAuthentication();
@@ -6520,6 +6527,17 @@ class Openfort {
6520
6527
  const result = await this.backendApiClients.transactionIntentsApi.signature(request);
6521
6528
  return result.data;
6522
6529
  }
6530
+ async getAccount() {
6531
+ const account = Account.fromStorage(this.storage);
6532
+ if (!account) {
6533
+ throw new OpenfortError('No signer configured', exports.OpenfortErrorType.MISSING_SIGNER_ERROR);
6534
+ }
6535
+ return {
6536
+ chainId: account.chainId,
6537
+ address: account.address,
6538
+ accountType: account.type,
6539
+ };
6540
+ }
6523
6541
  // eslint-disable-next-line class-methods-use-this
6524
6542
  get backendApiClients() {
6525
6543
  const configuration = Configuration.fromStorage();
package/dist/index.d.ts CHANGED
@@ -75,6 +75,20 @@ type SessionKey = {
75
75
  address: string;
76
76
  isRegistered: boolean;
77
77
  };
78
+ type CurrentAccount = {
79
+ address: string;
80
+ accountType: AccountType;
81
+ chainId: number;
82
+ };
83
+ declare enum AccountType {
84
+ UPGRADEABLE_V4 = "Upgradeable_v04",
85
+ MANAGED_V4 = "Managed_v04",
86
+ ERC6551_V4 = "ERC6551_v04",
87
+ ERC6551_V5 = "ERC6551_v05",
88
+ RECOVERABLE_V4 = "Recoverable_v04",
89
+ MANAGED_V5 = "Managed_v05",
90
+ UPGRADEABLE_V5 = "Upgradeable_v05"
91
+ }
78
92
  declare enum AuthType {
79
93
  OPENFORT = "openfort",
80
94
  THIRD_PARTY = "thirdParty"
@@ -603,9 +617,14 @@ declare class Openfort {
603
617
  * @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
604
618
  * @returns An AuthResponse object containing authentication details.
605
619
  */
606
- signUpWithEmailPassword({ email, password, ecosystemGame }: {
620
+ signUpWithEmailPassword({ email, password, options, ecosystemGame, }: {
607
621
  email: string;
608
622
  password: string;
623
+ options?: {
624
+ data: {
625
+ name: string;
626
+ };
627
+ };
609
628
  ecosystemGame?: string;
610
629
  }): Promise<AuthResponse>;
611
630
  /**
@@ -808,6 +827,7 @@ declare class Openfort {
808
827
  * @throws {OpenfortError} If no userOperationHash or signature is provided.
809
828
  */
810
829
  sendSignatureTransactionIntentRequest(transactionIntentId: string, userOperationHash?: string | null, signature?: string | null, optimistic?: boolean): Promise<TransactionIntentResponse>;
830
+ getAccount(): Promise<CurrentAccount>;
811
831
  private get backendApiClients();
812
832
  /**
813
833
  * Sends a transaction signed with a session request.
package/dist/index.js CHANGED
@@ -3184,7 +3184,7 @@ class KeyPair extends SigningKey {
3184
3184
  }
3185
3185
  }
3186
3186
 
3187
- const VERSION = '0.8.2';
3187
+ const VERSION = '0.8.4';
3188
3188
 
3189
3189
  var Event;
3190
3190
  (function (Event) {
@@ -6082,10 +6082,13 @@ class Openfort {
6082
6082
  * Logs the user out by flushing the signer and removing credentials.
6083
6083
  */
6084
6084
  async logout() {
6085
- await SignerManager.fromStorage()?.logout();
6085
+ const signer = SignerManager.fromStorage();
6086
6086
  this.storage.remove(StorageKeys.AUTHENTICATION);
6087
6087
  this.storage.remove(StorageKeys.SIGNER);
6088
6088
  this.storage.remove(StorageKeys.ACCOUNT);
6089
+ if (signer) {
6090
+ await signer.logout();
6091
+ }
6089
6092
  }
6090
6093
  /**
6091
6094
  * Returns an Ethereum provider using the configured signer.
@@ -6252,9 +6255,9 @@ class Openfort {
6252
6255
  * @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
6253
6256
  * @returns An AuthResponse object containing authentication details.
6254
6257
  */
6255
- async signUpWithEmailPassword({ email, password, ecosystemGame }) {
6258
+ async signUpWithEmailPassword({ email, password, options, ecosystemGame, }) {
6256
6259
  const previousAuth = Authentication.fromStorage(this.storage);
6257
- const result = await this.authManager.signupEmailPassword(email, password, ecosystemGame);
6260
+ const result = await this.authManager.signupEmailPassword(email, password, options?.data.name, ecosystemGame);
6258
6261
  if (previousAuth && previousAuth.player !== result.player.id) {
6259
6262
  this.logout();
6260
6263
  }
@@ -6381,10 +6384,14 @@ class Openfort {
6381
6384
  async authenticateWithThirdPartyProvider({ provider, token, tokenType, ecosystemGame, }) {
6382
6385
  const previousAuth = Authentication.fromStorage(this.storage);
6383
6386
  const result = await this.authManager.authenticateThirdParty(provider, token, tokenType, ecosystemGame);
6387
+ let loggedOut = false;
6384
6388
  if (previousAuth && previousAuth.player !== result.id) {
6385
6389
  this.logout();
6390
+ loggedOut = true;
6386
6391
  }
6387
6392
  new Authentication('third_party', token, result.id, null, provider, tokenType).save(this.storage);
6393
+ if (loggedOut)
6394
+ return result;
6388
6395
  const signer = SignerManager.fromStorage();
6389
6396
  try {
6390
6397
  await signer?.updateAuthentication();
@@ -6497,6 +6504,17 @@ class Openfort {
6497
6504
  const result = await this.backendApiClients.transactionIntentsApi.signature(request);
6498
6505
  return result.data;
6499
6506
  }
6507
+ async getAccount() {
6508
+ const account = Account.fromStorage(this.storage);
6509
+ if (!account) {
6510
+ throw new OpenfortError('No signer configured', OpenfortErrorType.MISSING_SIGNER_ERROR);
6511
+ }
6512
+ return {
6513
+ chainId: account.chainId,
6514
+ address: account.address,
6515
+ accountType: account.type,
6516
+ };
6517
+ }
6500
6518
  // eslint-disable-next-line class-methods-use-this
6501
6519
  get backendApiClients() {
6502
6520
  const configuration = Configuration.fromStorage();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfort/openfort-js",
3
- "version": "0.8.2",
3
+ "version": "0.8.4",
4
4
  "author": "Openfort (https://www.openfort.xyz)",
5
5
  "bugs": "https://github.com/openfort-xyz/openfort-js/issues",
6
6
  "repository": "openfort-xyz/openfort-js.git",