From dd22b2b8b354b72207f614691fec96a4ab716cf0 Mon Sep 17 00:00:00 2001 From: gllm-dev Date: Thu, 18 Jul 2024 16:18:57 +0200 Subject: [PATCH 1/3] fix: handle missing project entropy --- sdk/src/iframe/iframeManager.ts | 10 +++++++++- sdk/src/iframe/types.ts | 1 + sdk/src/openfort.ts | 26 ++++++++++++++++++++++---- sdk/src/version.ts | 2 +- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/sdk/src/iframe/iframeManager.ts b/sdk/src/iframe/iframeManager.ts index ec166b9..ae4cab6 100644 --- a/sdk/src/iframe/iframeManager.ts +++ b/sdk/src/iframe/iframeManager.ts @@ -19,7 +19,7 @@ import { RequestConfiguration, MISSING_USER_ENTROPY_ERROR, INCORRECT_USER_ENTROPY_ERROR, - ShieldAuthType, ExportPrivateKeyRequest, ExportPrivateKeyResponse, + ShieldAuthType, ExportPrivateKeyRequest, ExportPrivateKeyResponse, MISSING_PROJECT_ENTROPY_ERROR, } from './types'; export interface IframeConfiguration { @@ -36,6 +36,12 @@ export class MissingRecoveryPasswordError extends Error { } } +export class MissingProjectEntropyError extends Error { + constructor() { + super('MissingProjectEntropyError'); + } +} + export class WrongRecoveryPasswordError extends Error { constructor() { super('Wrong recovery password for this embedded signer'); @@ -163,6 +169,8 @@ export default class IframeManager { reject(new NotConfiguredError()); } else if (response.error === MISSING_USER_ENTROPY_ERROR) { reject(new MissingRecoveryPasswordError()); + } else if (response.error === MISSING_PROJECT_ENTROPY_ERROR) { + reject(new MissingProjectEntropyError()); } else if (response.error === INCORRECT_USER_ENTROPY_ERROR) { reject(new WrongRecoveryPasswordError()); } diff --git a/sdk/src/iframe/types.ts b/sdk/src/iframe/types.ts index 54f2d81..a703cbe 100644 --- a/sdk/src/iframe/types.ts +++ b/sdk/src/iframe/types.ts @@ -19,6 +19,7 @@ export enum Event { export const NOT_CONFIGURED_ERROR = 'not-configured-error'; export const MISSING_USER_ENTROPY_ERROR = 'missing-user-entropy-error'; +export const MISSING_PROJECT_ENTROPY_ERROR = 'missing-project-entropy-error'; export const INCORRECT_USER_ENTROPY_ERROR = 'incorrect-user-entropy-error'; export interface IEvent { diff --git a/sdk/src/openfort.ts b/sdk/src/openfort.ts index d32546b..0bcb826 100644 --- a/sdk/src/openfort.ts +++ b/sdk/src/openfort.ts @@ -32,7 +32,11 @@ import { LocalStorage } from './storage/localStorage'; import { SessionSigner } from './signer/session.signer'; import { EmbeddedSigner } from './signer/embedded.signer'; import { SessionStorage } from './storage/sessionStorage'; -import IframeManager, { IframeConfiguration, MissingRecoveryPasswordError } from './iframe/iframeManager'; +import IframeManager, { + IframeConfiguration, + MissingProjectEntropyError, + MissingRecoveryPasswordError, +} from './iframe/iframeManager'; import { ShieldAuthentication, ShieldAuthType } from './iframe/types'; export class Openfort { @@ -189,7 +193,7 @@ export class Openfort { this.signer = signer; this.instanceManager.setSignerType(SignerType.EMBEDDED); } catch (e) { - if (e instanceof MissingRecoveryPasswordError) { + if (e instanceof MissingRecoveryPasswordError || e instanceof MissingProjectEntropyError) { await this.flushSigner(); throw e; } @@ -401,7 +405,14 @@ export class Openfort { }); this.instanceManager.setPlayerID(result.id); if (this.signer && this.signer.useCredentials()) { - await this.signer.updateAuthentication(); + try { + await this.signer.updateAuthentication(); + } catch (e) { + if (e instanceof MissingRecoveryPasswordError || e instanceof MissingProjectEntropyError) { + await this.flushSigner(); + } + throw e; + } } return result; } @@ -726,7 +737,14 @@ export class Openfort { const auth = await this.authManager.validateCredentials(forceRefresh); this.storeCredentials(auth); if (this.signer && this.signer.useCredentials()) { - await this.signer.updateAuthentication(); + try { + await this.signer.updateAuthentication(); + } catch (e) { + if (e instanceof MissingRecoveryPasswordError || e instanceof MissingProjectEntropyError) { + await this.flushSigner(); + } + throw e; + } } } } diff --git a/sdk/src/version.ts b/sdk/src/version.ts index 2951557..7093a41 100644 --- a/sdk/src/version.ts +++ b/sdk/src/version.ts @@ -1,2 +1,2 @@ -export const VERSION = '0.7.20'; +export const VERSION = '0.7.21'; export const PACKAGE = '@openfort/openfort-js'; From cf02f5b9152b8e5a2477ade1577ad9bea355c558 Mon Sep 17 00:00:00 2001 From: gllm-dev Date: Thu, 18 Jul 2024 16:20:23 +0200 Subject: [PATCH 2/3] fix: handle missing project entropy --- sdk/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/package.json b/sdk/package.json index b33c0cc..e5b11e4 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@openfort/openfort-js", - "version": "0.7.20", + "version": "0.7.21", "author": "Openfort (https://www.openfort.xyz)", "bugs": "https://github.com/openfort-xyz/openfort-js/issues", "repository": "openfort-xyz/openfort-js.git", From 91288ebc366182daf2b68eceafe8286bf1d66a5d Mon Sep 17 00:00:00 2001 From: gllm-dev Date: Thu, 18 Jul 2024 16:23:22 +0200 Subject: [PATCH 3/3] fix: handle missing project entropy --- CHANGELOG.md | 6 +++++- examples/apps/auth-sample/package.json | 2 +- packages/platform-bridge/package.json | 2 +- yarn.lock | 4 ++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 694e375..6eb357f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,9 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.7.21] - 2024-07-16 +### Fixed +- Handle missing project entropy + ## [0.7.20] - 2024-07-18 ### Fixed -- AccountType to shieldAuthType type missmatch +- AccountType to shieldAuthType type mismatch ## [0.7.19] - 2024-07-16 ### Fixed diff --git a/examples/apps/auth-sample/package.json b/examples/apps/auth-sample/package.json index f321f5c..338cd5d 100644 --- a/examples/apps/auth-sample/package.json +++ b/examples/apps/auth-sample/package.json @@ -9,7 +9,7 @@ }, "dependencies": { "@heroicons/react": "^2.0.13", - "@openfort/openfort-js": "0.7.20", + "@openfort/openfort-js": "0.7.21", "@openfort/openfort-node": "^0.6.62", "@radix-ui/react-toast": "^1.1.2", "@rainbow-me/rainbowkit": "^2.1.1", diff --git a/packages/platform-bridge/package.json b/packages/platform-bridge/package.json index d7277eb..dc42831 100644 --- a/packages/platform-bridge/package.json +++ b/packages/platform-bridge/package.json @@ -2,7 +2,7 @@ "name": "@openfort/platform-bridge", "version": "0.0.0", "dependencies": { - "@openfort/openfort-js": "0.7.20", + "@openfort/openfort-js": "0.7.21", "ethers": "^5.7.0" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 2b78dfc..8b8e0ad 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1403,7 +1403,7 @@ __metadata: languageName: unknown linkType: soft -"@openfort/openfort-js@0.7.20, @openfort/openfort-js@workspace:sdk": +"@openfort/openfort-js@0.7.21, @openfort/openfort-js@workspace:sdk": version: 0.0.0-use.local resolution: "@openfort/openfort-js@workspace:sdk" dependencies: @@ -1458,7 +1458,7 @@ __metadata: version: 0.0.0-use.local resolution: "@openfort/platform-bridge@workspace:packages/platform-bridge" dependencies: - "@openfort/openfort-js": 0.7.20 + "@openfort/openfort-js": 0.7.21 eslint: ^8.40.0 ethers: ^5.7.0 parcel: ^2.8.3