Skip to content

Commit

Permalink
Merge pull request #45 from openfort-xyz/fix/missing-project-entropy
Browse files Browse the repository at this point in the history
fix: handle missing project entropy
  • Loading branch information
gllm-dev authored Jul 18, 2024
2 parents 33cc832 + 91288eb commit 173d46f
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 12 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/apps/auth-sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/platform-bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion sdk/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 9 additions & 1 deletion sdk/src/iframe/iframeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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');
Expand Down Expand Up @@ -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());
}
Expand Down
1 change: 1 addition & 0 deletions sdk/src/iframe/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
26 changes: 22 additions & 4 deletions sdk/src/openfort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const VERSION = '0.7.20';
export const VERSION = '0.7.21';
export const PACKAGE = '@openfort/openfort-js';
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,7 @@ __metadata:
languageName: unknown
linkType: soft

"@openfort/[email protected].20, @openfort/openfort-js@workspace:sdk":
"@openfort/[email protected].21, @openfort/openfort-js@workspace:sdk":
version: 0.0.0-use.local
resolution: "@openfort/openfort-js@workspace:sdk"
dependencies:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 173d46f

Please sign in to comment.