diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 4194b9a46..0751d016e 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,7 +1,7 @@ # See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.205.2/containers/typescript-node/.devcontainer/base.Dockerfile # [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 16, 14, 12, 16-bullseye, 14-bullseye, 12-bullseye, 16-buster, 14-buster, 12-buster -ARG VARIANT="16-bullseye" +ARG VARIANT="18-bullseye" FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT} # [Optional] Uncomment this section to install additional OS packages. diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 1f2d697ef..67633d6f2 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -8,7 +8,7 @@ // Append -bullseye or -buster to pin to an OS version. // Use -bullseye variants on local on arm64/Apple Silicon. "args": { - "VARIANT": "16-bullseye" + "VARIANT": "18-bullseye" } }, diff --git a/Dockerfile b/Dockerfile index 5821b57de..eef1f9419 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:16 +FROM node:18 RUN apt-get update && apt-get install -yq git python build-essential diff --git a/lerna.json b/lerna.json index b18aadec3..9bac617a7 100644 --- a/lerna.json +++ b/lerna.json @@ -1,4 +1,4 @@ { - "version": "4.3.2", + "version": "4.3.3", "$schema": "node_modules/lerna/schemas/lerna-schema.json" } diff --git a/package-lock.json b/package-lock.json index ccf10866e..7d1a37c8d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -75,7 +75,7 @@ "webpack-cli": "^5.1.4" }, "engines": { - "node": ">=16.0.0", + "node": ">=18.0.0", "npm": ">=7.0.0" } }, @@ -25085,38 +25085,38 @@ }, "packages/beacon-blockchain-substrate": { "name": "@airgap/beacon-blockchain-substrate", - "version": "4.3.2", + "version": "4.3.3", "license": "ISC", "dependencies": { - "@airgap/beacon-types": "4.3.2", - "@airgap/beacon-ui": "4.3.2" + "@airgap/beacon-types": "4.3.3", + "@airgap/beacon-ui": "4.3.3" } }, "packages/beacon-blockchain-tezos": { "name": "@airgap/beacon-blockchain-tezos", - "version": "4.3.2", + "version": "4.3.3", "license": "ISC", "dependencies": { - "@airgap/beacon-types": "4.3.2", - "@airgap/beacon-ui": "4.3.2" + "@airgap/beacon-types": "4.3.3", + "@airgap/beacon-ui": "4.3.3" } }, "packages/beacon-blockchain-tezos-sapling": { "name": "@airgap/beacon-blockchain-tezos-sapling", - "version": "4.3.2", + "version": "4.3.3", "license": "ISC", "dependencies": { - "@airgap/beacon-types": "4.3.2", - "@airgap/beacon-ui": "4.3.2" + "@airgap/beacon-types": "4.3.3", + "@airgap/beacon-ui": "4.3.3" } }, "packages/beacon-core": { "name": "@airgap/beacon-core", - "version": "4.3.2", + "version": "4.3.3", "license": "ISC", "dependencies": { - "@airgap/beacon-types": "4.3.2", - "@airgap/beacon-utils": "4.3.2", + "@airgap/beacon-types": "4.3.3", + "@airgap/beacon-utils": "4.3.3", "@stablelib/ed25519": "^1.0.3", "@stablelib/nacl": "^1.0.4", "@stablelib/utf8": "^1.0.1", @@ -25127,68 +25127,68 @@ }, "packages/beacon-dapp": { "name": "@airgap/beacon-dapp", - "version": "4.3.2", + "version": "4.3.3", "license": "ISC", "dependencies": { - "@airgap/beacon-core": "4.3.2", - "@airgap/beacon-transport-matrix": "4.3.2", - "@airgap/beacon-transport-postmessage": "4.3.2", - "@airgap/beacon-transport-walletconnect": "4.3.2", - "@airgap/beacon-ui": "4.3.2", + "@airgap/beacon-core": "4.3.3", + "@airgap/beacon-transport-matrix": "4.3.3", + "@airgap/beacon-transport-postmessage": "4.3.3", + "@airgap/beacon-transport-walletconnect": "4.3.3", + "@airgap/beacon-ui": "4.3.3", "broadcast-channel": "^7.0.0" } }, "packages/beacon-sdk": { "name": "@airgap/beacon-sdk", - "version": "4.3.2", + "version": "4.3.3", "license": "ISC", "dependencies": { - "@airgap/beacon-blockchain-substrate": "4.3.2", - "@airgap/beacon-blockchain-tezos": "4.3.2", - "@airgap/beacon-core": "4.3.2", - "@airgap/beacon-dapp": "4.3.2", - "@airgap/beacon-transport-matrix": "4.3.2", - "@airgap/beacon-transport-postmessage": "4.3.2", - "@airgap/beacon-types": "4.3.2", - "@airgap/beacon-ui": "4.3.2", - "@airgap/beacon-utils": "4.3.2", - "@airgap/beacon-wallet": "4.3.2" + "@airgap/beacon-blockchain-substrate": "4.3.3", + "@airgap/beacon-blockchain-tezos": "4.3.3", + "@airgap/beacon-core": "4.3.3", + "@airgap/beacon-dapp": "4.3.3", + "@airgap/beacon-transport-matrix": "4.3.3", + "@airgap/beacon-transport-postmessage": "4.3.3", + "@airgap/beacon-types": "4.3.3", + "@airgap/beacon-ui": "4.3.3", + "@airgap/beacon-utils": "4.3.3", + "@airgap/beacon-wallet": "4.3.3" } }, "packages/beacon-transport-matrix": { "name": "@airgap/beacon-transport-matrix", - "version": "4.3.2", + "version": "4.3.3", "license": "ISC", "dependencies": { - "@airgap/beacon-core": "4.3.2", - "@airgap/beacon-utils": "4.3.2", + "@airgap/beacon-core": "4.3.3", + "@airgap/beacon-utils": "4.3.3", "axios": "^1.6.2" } }, "packages/beacon-transport-postmessage": { "name": "@airgap/beacon-transport-postmessage", - "version": "4.3.2", + "version": "4.3.3", "license": "ISC", "dependencies": { - "@airgap/beacon-core": "4.3.2", - "@airgap/beacon-types": "4.3.2", - "@airgap/beacon-utils": "4.3.2" + "@airgap/beacon-core": "4.3.3", + "@airgap/beacon-types": "4.3.3", + "@airgap/beacon-utils": "4.3.3" } }, "packages/beacon-transport-walletconnect": { "name": "@airgap/beacon-transport-walletconnect", - "version": "4.3.2", + "version": "4.3.3", "license": "ISC", "dependencies": { - "@airgap/beacon-core": "4.3.2", - "@airgap/beacon-types": "4.3.2", - "@airgap/beacon-utils": "4.3.2", + "@airgap/beacon-core": "4.3.3", + "@airgap/beacon-types": "4.3.3", + "@airgap/beacon-utils": "4.3.3", "@walletconnect/sign-client": "2.14.0" } }, "packages/beacon-types": { "name": "@airgap/beacon-types", - "version": "4.3.2", + "version": "4.3.3", "license": "ISC", "dependencies": { "@types/chrome": "0.0.246" @@ -25196,13 +25196,13 @@ }, "packages/beacon-ui": { "name": "@airgap/beacon-ui", - "version": "4.3.2", + "version": "4.3.3", "license": "ISC", "dependencies": { - "@airgap/beacon-core": "4.3.2", - "@airgap/beacon-transport-postmessage": "4.3.2", - "@airgap/beacon-types": "4.3.2", - "@airgap/beacon-utils": "4.3.2", + "@airgap/beacon-core": "4.3.3", + "@airgap/beacon-transport-postmessage": "4.3.3", + "@airgap/beacon-types": "4.3.3", + "@airgap/beacon-utils": "4.3.3", "@walletconnect/utils": "2.14.0", "qrcode-svg": "^1.1.0", "solid-js": "^1.7.11" @@ -25225,7 +25225,7 @@ }, "packages/beacon-utils": { "name": "@airgap/beacon-utils", - "version": "4.3.2", + "version": "4.3.3", "license": "ISC", "dependencies": { "@stablelib/ed25519": "^1.0.3", @@ -25237,12 +25237,12 @@ }, "packages/beacon-wallet": { "name": "@airgap/beacon-wallet", - "version": "4.3.2", + "version": "4.3.3", "license": "ISC", "dependencies": { - "@airgap/beacon-core": "4.3.2", - "@airgap/beacon-transport-matrix": "4.3.2", - "@airgap/beacon-transport-postmessage": "4.3.2" + "@airgap/beacon-core": "4.3.3", + "@airgap/beacon-transport-matrix": "4.3.3", + "@airgap/beacon-transport-postmessage": "4.3.3" } } } diff --git a/package.json b/package.json index d3665cb5c..29cc1a7f9 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ }, "engines": { "npm": ">=7.0.0", - "node": ">=16.0.0" + "node": ">=18.0.0" }, "scripts": { "prebuild": "ts-node --project tsconfig-cjs.json scripts/generate-wallet-list.ts", diff --git a/packages/beacon-blockchain-substrate/package.json b/packages/beacon-blockchain-substrate/package.json index 9b2e17e89..3b7d24011 100644 --- a/packages/beacon-blockchain-substrate/package.json +++ b/packages/beacon-blockchain-substrate/package.json @@ -1,6 +1,6 @@ { "name": "@airgap/beacon-blockchain-substrate", - "version": "4.3.2", + "version": "4.3.3", "description": "This package adds support for `substrate` based blockchains. It can be used in combination with the `@airgap/beacon-dapp` or `@airgap/beacon-wallet` packages.", "author": "Andreas Gassmann ", "homepage": "https://walletbeacon.io", @@ -34,7 +34,7 @@ "url": "https://github.com/airgap-it/beacon-sdk/issues" }, "dependencies": { - "@airgap/beacon-types": "4.3.2", - "@airgap/beacon-ui": "4.3.2" + "@airgap/beacon-types": "4.3.3", + "@airgap/beacon-ui": "4.3.3" } } diff --git a/packages/beacon-blockchain-tezos-sapling/package.json b/packages/beacon-blockchain-tezos-sapling/package.json index 56b5b4961..b443edf6a 100644 --- a/packages/beacon-blockchain-tezos-sapling/package.json +++ b/packages/beacon-blockchain-tezos-sapling/package.json @@ -1,6 +1,6 @@ { "name": "@airgap/beacon-blockchain-tezos-sapling", - "version": "4.3.2", + "version": "4.3.3", "description": "This package adds support for `tezos-sapling`, the sapling integration on the Tezos blockchain. It can be used in combination with the `@airgap/beacon-dapp` or `@airgap/beacon-wallet` packages.", "author": "Andreas Gassmann ", "homepage": "https://walletbeacon.io", @@ -34,7 +34,7 @@ "url": "https://github.com/airgap-it/beacon-sdk/issues" }, "dependencies": { - "@airgap/beacon-types": "4.3.2", - "@airgap/beacon-ui": "4.3.2" + "@airgap/beacon-types": "4.3.3", + "@airgap/beacon-ui": "4.3.3" } } diff --git a/packages/beacon-blockchain-tezos/package.json b/packages/beacon-blockchain-tezos/package.json index b3eb24083..d754b70b0 100644 --- a/packages/beacon-blockchain-tezos/package.json +++ b/packages/beacon-blockchain-tezos/package.json @@ -1,6 +1,6 @@ { "name": "@airgap/beacon-blockchain-tezos", - "version": "4.3.2", + "version": "4.3.3", "description": "This package adds support for the `tezos` blockchain. It can be used in combination with the `@airgap/beacon-dapp` or `@airgap/beacon-wallet` packages.", "author": "Andreas Gassmann ", "homepage": "https://walletbeacon.io", @@ -34,7 +34,7 @@ "url": "https://github.com/airgap-it/beacon-sdk/issues" }, "dependencies": { - "@airgap/beacon-types": "4.3.2", - "@airgap/beacon-ui": "4.3.2" + "@airgap/beacon-types": "4.3.3", + "@airgap/beacon-ui": "4.3.3" } } diff --git a/packages/beacon-core/package.json b/packages/beacon-core/package.json index 2c2bb3d90..427f4db05 100644 --- a/packages/beacon-core/package.json +++ b/packages/beacon-core/package.json @@ -1,6 +1,6 @@ { "name": "@airgap/beacon-core", - "version": "4.3.2", + "version": "4.3.3", "description": "This package contains internal methods that are used by both the dApp and wallet client.", "author": "Andreas Gassmann ", "homepage": "https://walletbeacon.io", @@ -34,8 +34,8 @@ "url": "https://github.com/airgap-it/beacon-sdk/issues" }, "dependencies": { - "@airgap/beacon-types": "4.3.2", - "@airgap/beacon-utils": "4.3.2", + "@airgap/beacon-types": "4.3.3", + "@airgap/beacon-utils": "4.3.3", "@stablelib/ed25519": "^1.0.3", "@stablelib/nacl": "^1.0.4", "@stablelib/utf8": "^1.0.1", diff --git a/packages/beacon-core/src/clients/beacon-client/BeaconClient.ts b/packages/beacon-core/src/clients/beacon-client/BeaconClient.ts index 8e79be01a..b8c5791b3 100644 --- a/packages/beacon-core/src/clients/beacon-client/BeaconClient.ts +++ b/packages/beacon-core/src/clients/beacon-client/BeaconClient.ts @@ -85,7 +85,7 @@ export abstract class BeaconClient { /** * This method initializes the SDK by setting some values in the storage and generating a keypair. */ - private async initSDK(): Promise { + protected async initSDK(): Promise { this.storage.set(StorageKey.BEACON_SDK_VERSION, SDK_VERSION).catch(console.error) this.loadOrCreateBeaconSecret().catch(console.error) diff --git a/packages/beacon-core/src/constants.ts b/packages/beacon-core/src/constants.ts index 5b6c69931..b94ec181e 100644 --- a/packages/beacon-core/src/constants.ts +++ b/packages/beacon-core/src/constants.ts @@ -1,4 +1,4 @@ -export const SDK_VERSION: string = '4.3.2' +export const SDK_VERSION: string = '4.3.3' export const BEACON_VERSION: string = '3' export const NOTIFICATION_ORACLE_URL: string = diff --git a/packages/beacon-core/src/transports/clients/CommunicationClient.ts b/packages/beacon-core/src/transports/clients/CommunicationClient.ts index 740db2ad4..2bfe8a122 100644 --- a/packages/beacon-core/src/transports/clients/CommunicationClient.ts +++ b/packages/beacon-core/src/transports/clients/CommunicationClient.ts @@ -9,7 +9,7 @@ import { ClientEvents } from './ClientEvents' * */ export abstract class CommunicationClient { - constructor(protected readonly keyPair?: KeyPair) {} + constructor(protected keyPair?: KeyPair) {} public eventHandlers: Map = new Map() diff --git a/packages/beacon-dapp/package.json b/packages/beacon-dapp/package.json index 173e863ee..0a8788577 100644 --- a/packages/beacon-dapp/package.json +++ b/packages/beacon-dapp/package.json @@ -1,6 +1,6 @@ { "name": "@airgap/beacon-dapp", - "version": "4.3.2", + "version": "4.3.3", "description": "Use this package on your dApp to instanciate a DAppClient object and communicate to wallets.", "author": "Andreas Gassmann ", "homepage": "https://walletbeacon.io", @@ -35,11 +35,11 @@ "url": "https://github.com/airgap-it/beacon-sdk/issues" }, "dependencies": { - "@airgap/beacon-core": "4.3.2", - "@airgap/beacon-transport-matrix": "4.3.2", - "@airgap/beacon-transport-postmessage": "4.3.2", - "@airgap/beacon-transport-walletconnect": "4.3.2", - "@airgap/beacon-ui": "4.3.2", + "@airgap/beacon-core": "4.3.3", + "@airgap/beacon-transport-matrix": "4.3.3", + "@airgap/beacon-transport-postmessage": "4.3.3", + "@airgap/beacon-transport-walletconnect": "4.3.3", + "@airgap/beacon-ui": "4.3.3", "broadcast-channel": "^7.0.0" } } diff --git a/packages/beacon-dapp/src/dapp-client/DAppClient.ts b/packages/beacon-dapp/src/dapp-client/DAppClient.ts index e470502f5..55cb68089 100644 --- a/packages/beacon-dapp/src/dapp-client/DAppClient.ts +++ b/packages/beacon-dapp/src/dapp-client/DAppClient.ts @@ -101,7 +101,8 @@ import { signMessage, CONTRACT_PREFIX, prefixPublicKey, - isValidAddress + isValidAddress, + getKeypairFromSeed } from '@airgap/beacon-utils' import { messageEvents } from '../beacon-message-events' import { BlockExplorer } from '../utils/block-explorer' @@ -264,7 +265,9 @@ export class DAppClient extends Client { this.storage.subscribeToStorageChanged(async (event) => { if (event.eventType === 'storageCleared') { this.setActiveAccount(undefined) - } else if (event.eventType === 'entryModified') { + return + } + if (event.eventType === 'entryModified') { if (event.key === this.storage.getPrefixedKey(StorageKey.ACTIVE_ACCOUNT)) { const accountIdentifier = event.newValue if (!accountIdentifier || accountIdentifier === 'undefined') { @@ -273,8 +276,17 @@ export class DAppClient extends Client { const account = await this.getAccount(accountIdentifier) this.setActiveAccount(account) } - } else if (event.key === this.storage.getPrefixedKey(StorageKey.ENABLE_METRICS)) { + return + } + if (event.key === this.storage.getPrefixedKey(StorageKey.ENABLE_METRICS)) { this.enableMetrics = !!(await this.storage.get(StorageKey.ENABLE_METRICS)) + return + } + if (event.key === this.storage.getPrefixedKey(StorageKey.BEACON_SDK_SECRET_SEED)) { + this._keyPair = new ExposedPromise() + this._beaconId = new ExposedPromise() + await this.initSDK() + return } } }) @@ -292,8 +304,9 @@ export class DAppClient extends Client { } }) .catch(async (storageError) => { - await this.setActiveAccount(undefined) logger.error(storageError) + await this.resetInvalidState(false) + this.events.emit(BeaconEvent.INVALID_ACCOUNT_DEACTIVATED) return undefined }) @@ -555,7 +568,11 @@ export class DAppClient extends Client { } public async initInternalTransports(): Promise { - const keyPair = await this.keyPair + const seed = await this.storage.get(StorageKey.BEACON_SDK_SECRET_SEED) + if (!seed) { + throw new Error('Secret seed not found') + } + const keyPair = await getKeypairFromSeed(seed) if (this.postMessageTransport || this.p2pTransport || this.walletConnectTransport) { return @@ -785,33 +802,41 @@ export class DAppClient extends Client { console.error(error) }) + const abortHandler = async () => { + logger.log('init', 'ABORTED') + this.sendMetrics( + 'performance-metrics/save', + await this.buildPayload('connect', 'abort') + ) + await Promise.all([ + postMessageTransport.disconnect(), + // p2pTransport.disconnect(), do not abort connection manually + walletConnectTransport.disconnect() + ]) + this.postMessageTransport = this.walletConnectTransport = this.p2pTransport = undefined + this._activeAccount.isResolved() && this.clearActiveAccount() + this._initPromise = undefined + } + this.events .emit(BeaconEvent.PAIR_INIT, { p2pPeerInfo: () => { - p2pTransport.connect().then().catch(console.error) + p2pTransport + .connect() + .then() + .catch((err) => { + logger.error(err) + if (err.message === 'The account is deactivated.') { + this.hideUI(['alert']) + abortHandler() + } + }) return p2pTransport.getPairingRequestInfo() }, postmessagePeerInfo: () => postMessageTransport.getPairingRequestInfo(), walletConnectPeerInfo: () => walletConnectTransport.getPairingRequestInfo(), networkType: this.network.type, - abortedHandler: async () => { - logger.log('init', 'ABORTED') - this.sendMetrics( - 'performance-metrics/save', - await this.buildPayload('connect', 'abort') - ) - await Promise.all([ - postMessageTransport.disconnect(), - // p2pTransport.disconnect(), do not abort connection manually - walletConnectTransport.disconnect() - ]) - this.postMessageTransport = - this.walletConnectTransport = - this.p2pTransport = - undefined - this._activeAccount.isResolved() && this.clearActiveAccount() - this._initPromise = undefined - }, + abortedHandler: abortHandler.bind(this), disclaimerText: this.disclaimerText, analytics: this.analytics, featuredWallets: this.featuredWallets diff --git a/packages/beacon-dapp/src/events.ts b/packages/beacon-dapp/src/events.ts index a3dafdab2..f8ef74604 100644 --- a/packages/beacon-dapp/src/events.ts +++ b/packages/beacon-dapp/src/events.ts @@ -95,6 +95,7 @@ export enum BeaconEvent { SHOW_PREPARE = 'SHOW_PREPARE', HIDE_UI = 'HIDE_UI', INVALID_ACTIVE_ACCOUNT_STATE = 'INVALID_ACTIVE_ACCOUNT_STATE', + INVALID_ACCOUNT_DEACTIVATED = 'INVALID_ACCOUNT_DEACTIVATED', PAIR_INIT = 'PAIR_INIT', PAIR_SUCCESS = 'PAIR_SUCCESS', CHANNEL_CLOSED = 'CHANNEL_CLOSED', @@ -195,7 +196,8 @@ export interface BeaconEventType { [BeaconEvent.NO_PERMISSIONS]: undefined [BeaconEvent.ACTIVE_ACCOUNT_SET]: AccountInfo [BeaconEvent.ACTIVE_TRANSPORT_SET]: Transport - [BeaconEvent.INVALID_ACTIVE_ACCOUNT_STATE]: undefined + [BeaconEvent.INVALID_ACTIVE_ACCOUNT_STATE]: undefined + [BeaconEvent.INVALID_ACCOUNT_DEACTIVATED]: undefined [BeaconEvent.SHOW_PREPARE]: { walletInfo?: WalletInfo } [BeaconEvent.HIDE_UI]: ('alert' | 'toast')[] | undefined [BeaconEvent.PAIR_INIT]: { @@ -314,7 +316,7 @@ const showNoPermissionAlert = async (): Promise => { } /** - * Show a + * Show an "Invalid state" alert */ const showInvalidActiveAccountState = async (): Promise => { await openAlert({ @@ -324,6 +326,16 @@ const showInvalidActiveAccountState = async (): Promise => { }) } +/** + * Show an "account deactivated" error alert + */ +const showInvalidAccountDeactivated = async (): Promise => { + await openAlert({ + title: 'Error', + body: `Your session has expired. Please pair with your wallet again.` + }) +} + /** * Show an error toast * @@ -756,6 +768,7 @@ export const defaultEventCallbacks: { [BeaconEvent.ACTIVE_ACCOUNT_SET]: emptyHandler(), [BeaconEvent.ACTIVE_TRANSPORT_SET]: emptyHandler(), [BeaconEvent.INVALID_ACTIVE_ACCOUNT_STATE]: showInvalidActiveAccountState, + [BeaconEvent.INVALID_ACCOUNT_DEACTIVATED]: showInvalidAccountDeactivated, [BeaconEvent.SHOW_PREPARE]: showPrepare, [BeaconEvent.HIDE_UI]: hideUI, [BeaconEvent.PAIR_INIT]: showPairAlert, @@ -816,6 +829,9 @@ export class BeaconEventHandler { [BeaconEvent.INVALID_ACTIVE_ACCOUNT_STATE]: [ defaultEventCallbacks.INVALID_ACTIVE_ACCOUNT_STATE ], + [BeaconEvent.INVALID_ACCOUNT_DEACTIVATED]: [ + defaultEventCallbacks.INVALID_ACCOUNT_DEACTIVATED + ], [BeaconEvent.SHOW_PREPARE]: [defaultEventCallbacks.SHOW_PREPARE], [BeaconEvent.HIDE_UI]: [defaultEventCallbacks.HIDE_UI], [BeaconEvent.PAIR_INIT]: [defaultEventCallbacks.PAIR_INIT], diff --git a/packages/beacon-sdk/package.json b/packages/beacon-sdk/package.json index c95dc905f..18d08a5dd 100644 --- a/packages/beacon-sdk/package.json +++ b/packages/beacon-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@airgap/beacon-sdk", - "version": "4.3.2", + "version": "4.3.3", "description": "The `beacon-sdk` simplifies and abstracts the communication between dApps and wallets over different transport layers.", "author": "Andreas Gassmann ", "homepage": "https://walletbeacon.io", @@ -35,15 +35,15 @@ "url": "https://github.com/airgap-it/beacon-sdk/issues" }, "dependencies": { - "@airgap/beacon-blockchain-substrate": "4.3.2", - "@airgap/beacon-blockchain-tezos": "4.3.2", - "@airgap/beacon-core": "4.3.2", - "@airgap/beacon-dapp": "4.3.2", - "@airgap/beacon-transport-matrix": "4.3.2", - "@airgap/beacon-transport-postmessage": "4.3.2", - "@airgap/beacon-types": "4.3.2", - "@airgap/beacon-ui": "4.3.2", - "@airgap/beacon-utils": "4.3.2", - "@airgap/beacon-wallet": "4.3.2" + "@airgap/beacon-blockchain-substrate": "4.3.3", + "@airgap/beacon-blockchain-tezos": "4.3.3", + "@airgap/beacon-core": "4.3.3", + "@airgap/beacon-dapp": "4.3.3", + "@airgap/beacon-transport-matrix": "4.3.3", + "@airgap/beacon-transport-postmessage": "4.3.3", + "@airgap/beacon-types": "4.3.3", + "@airgap/beacon-ui": "4.3.3", + "@airgap/beacon-utils": "4.3.3", + "@airgap/beacon-wallet": "4.3.3" } } diff --git a/packages/beacon-transport-matrix/package.json b/packages/beacon-transport-matrix/package.json index d6ad1c0a8..4979d94f9 100644 --- a/packages/beacon-transport-matrix/package.json +++ b/packages/beacon-transport-matrix/package.json @@ -1,6 +1,6 @@ { "name": "@airgap/beacon-transport-matrix", - "version": "4.3.2", + "version": "4.3.3", "description": "This package contains methods to facilitate communication over the Beacon network, a decentralised P2P network that is based on the matrix protocol.", "author": "Andreas Gassmann ", "homepage": "https://walletbeacon.io", @@ -34,8 +34,8 @@ "url": "https://github.com/airgap-it/beacon-sdk/issues" }, "dependencies": { - "@airgap/beacon-core": "4.3.2", - "@airgap/beacon-utils": "4.3.2", + "@airgap/beacon-core": "4.3.3", + "@airgap/beacon-utils": "4.3.3", "axios": "^1.6.2" } } diff --git a/packages/beacon-transport-matrix/src/communication-client/P2PCommunicationClient.ts b/packages/beacon-transport-matrix/src/communication-client/P2PCommunicationClient.ts index eec92668a..77a9005e9 100644 --- a/packages/beacon-transport-matrix/src/communication-client/P2PCommunicationClient.ts +++ b/packages/beacon-transport-matrix/src/communication-client/P2PCommunicationClient.ts @@ -8,7 +8,8 @@ import { encryptCryptoboxPayload, decryptCryptoboxPayload, secretbox_NONCEBYTES, - secretbox_MACBYTES + secretbox_MACBYTES, + getKeypairFromSeed } from '@airgap/beacon-utils' import { MatrixClient } from '../matrix-client/MatrixClient' import { @@ -387,8 +388,15 @@ export class P2PCommunicationClient extends CommunicationClient { password: `ed:${toHex(rawSignature)}:${await this.getPublicKey()}`, deviceId: toHex(this.keyPair!.publicKey) }) - } catch (error) { - logger.error('start', 'Could not log in, retrying') + } catch (error: any) { + logger.error('start', 'Could not log in, retrying', error) + + if (error.errcode === 'M_USER_DEACTIVATED') { + await this.generateNewKeyPair() + await this.reset() + throw new Error('The account is deactivated.') + } + await this.reset() // If we can't log in, let's reset if (!this.selectedRegion) { throw new Error('No region selected.') @@ -426,6 +434,7 @@ export class P2PCommunicationClient extends CommunicationClient { await this.storage.delete(StorageKey.MATRIX_PEER_ROOM_IDS).catch((error) => logger.log(error)) await this.storage.delete(StorageKey.MATRIX_PRESERVED_STATE).catch((error) => logger.log(error)) await this.storage.delete(StorageKey.MATRIX_SELECTED_NODE).catch((error) => logger.log(error)) + // Instead of resetting everything, maybe we should make sure a new instance is created? this.relayServer = undefined this.client = new ExposedPromise() @@ -779,6 +788,16 @@ export class P2PCommunicationClient extends CommunicationClient { ) } + private async generateNewKeyPair() { + const newSeed = await generateGUID() + + console.warn(`The current user ID has been deactivated. Generating new ID: ${newSeed}`) + + this.storage.set(StorageKey.BEACON_SDK_SECRET_SEED, newSeed) + + this.keyPair = await getKeypairFromSeed(newSeed) + } + private async getRelevantRoom(recipient: string): Promise { const roomIds = await this.storage.get(StorageKey.MATRIX_PEER_ROOM_IDS) let roomId = roomIds[recipient] diff --git a/packages/beacon-transport-postmessage/package.json b/packages/beacon-transport-postmessage/package.json index 06f2c6356..4561e38c4 100644 --- a/packages/beacon-transport-postmessage/package.json +++ b/packages/beacon-transport-postmessage/package.json @@ -1,6 +1,6 @@ { "name": "@airgap/beacon-transport-postmessage", - "version": "4.3.2", + "version": "4.3.3", "description": "This package contains methods to facilitate communication over the postmessage interface of the browser to talk to browser extensions.", "author": "Andreas Gassmann ", "homepage": "https://walletbeacon.io", @@ -34,8 +34,8 @@ "url": "https://github.com/airgap-it/beacon-sdk/issues" }, "dependencies": { - "@airgap/beacon-core": "4.3.2", - "@airgap/beacon-types": "4.3.2", - "@airgap/beacon-utils": "4.3.2" + "@airgap/beacon-core": "4.3.3", + "@airgap/beacon-types": "4.3.3", + "@airgap/beacon-utils": "4.3.3" } } diff --git a/packages/beacon-transport-walletconnect/package.json b/packages/beacon-transport-walletconnect/package.json index de2785687..d176395a8 100644 --- a/packages/beacon-transport-walletconnect/package.json +++ b/packages/beacon-transport-walletconnect/package.json @@ -1,6 +1,6 @@ { "name": "@airgap/beacon-transport-walletconnect", - "version": "4.3.2", + "version": "4.3.3", "description": "This package contains methods to facilitate communication over the WalletConnect network.", "author": "Papers AG", "homepage": "https://walletbeacon.io", @@ -34,9 +34,9 @@ "url": "https://github.com/airgap-it/beacon-sdk/issues" }, "dependencies": { - "@airgap/beacon-core": "4.3.2", - "@airgap/beacon-types": "4.3.2", - "@airgap/beacon-utils": "4.3.2", + "@airgap/beacon-core": "4.3.3", + "@airgap/beacon-types": "4.3.3", + "@airgap/beacon-utils": "4.3.3", "@walletconnect/sign-client": "2.14.0" } } diff --git a/packages/beacon-types/package.json b/packages/beacon-types/package.json index a42c79cef..32b5a0934 100644 --- a/packages/beacon-types/package.json +++ b/packages/beacon-types/package.json @@ -1,6 +1,6 @@ { "name": "@airgap/beacon-types", - "version": "4.3.2", + "version": "4.3.3", "description": "This package contains types that are used throughout the Beacon SDK.", "author": "Andreas Gassmann ", "homepage": "https://walletbeacon.io", diff --git a/packages/beacon-ui/package.json b/packages/beacon-ui/package.json index cbed75911..c77f50c75 100644 --- a/packages/beacon-ui/package.json +++ b/packages/beacon-ui/package.json @@ -1,6 +1,6 @@ { "name": "@airgap/beacon-ui", - "version": "4.3.2", + "version": "4.3.3", "description": "This package contains the UI part (alerts and toasts) of the Beacon SDK.", "author": "Andreas Gassmann ", "homepage": "https://walletbeacon.io", @@ -34,10 +34,10 @@ "url": "https://github.com/airgap-it/beacon-sdk/issues" }, "dependencies": { - "@airgap/beacon-core": "4.3.2", - "@airgap/beacon-transport-postmessage": "4.3.2", - "@airgap/beacon-types": "4.3.2", - "@airgap/beacon-utils": "4.3.2", + "@airgap/beacon-core": "4.3.3", + "@airgap/beacon-transport-postmessage": "4.3.3", + "@airgap/beacon-types": "4.3.3", + "@airgap/beacon-utils": "4.3.3", "@walletconnect/utils": "2.14.0", "qrcode-svg": "^1.1.0", "solid-js": "^1.7.11" diff --git a/packages/beacon-utils/package.json b/packages/beacon-utils/package.json index 7563d4d21..55498b2cd 100644 --- a/packages/beacon-utils/package.json +++ b/packages/beacon-utils/package.json @@ -1,6 +1,6 @@ { "name": "@airgap/beacon-utils", - "version": "4.3.2", + "version": "4.3.3", "description": "This package contains utility functions that are used throughout the beacon-sdk", "author": "Andreas Gassmann ", "homepage": "https://walletbeacon.io", diff --git a/packages/beacon-wallet/package.json b/packages/beacon-wallet/package.json index d70ce203f..d79f0f909 100644 --- a/packages/beacon-wallet/package.json +++ b/packages/beacon-wallet/package.json @@ -1,6 +1,6 @@ { "name": "@airgap/beacon-wallet", - "version": "4.3.2", + "version": "4.3.3", "description": "Use this package in your wallet to instanciate a WalletClient object and communicate to dApps.", "author": "Andreas Gassmann ", "homepage": "https://walletbeacon.io", @@ -35,8 +35,8 @@ "url": "https://github.com/airgap-it/beacon-sdk/issues" }, "dependencies": { - "@airgap/beacon-core": "4.3.2", - "@airgap/beacon-transport-matrix": "4.3.2", - "@airgap/beacon-transport-postmessage": "4.3.2" + "@airgap/beacon-core": "4.3.3", + "@airgap/beacon-transport-matrix": "4.3.3", + "@airgap/beacon-transport-postmessage": "4.3.3" } } diff --git a/packages/beacon-wallet/src/client/WalletClient.ts b/packages/beacon-wallet/src/client/WalletClient.ts index b34e9622c..d33dab817 100644 --- a/packages/beacon-wallet/src/client/WalletClient.ts +++ b/packages/beacon-wallet/src/client/WalletClient.ts @@ -235,24 +235,34 @@ export class WalletClient extends Client { /** * The method will attempt to initiate a connection using the active transport. */ - public async _connect(): Promise { + public async _connect(attempts: number = 3): Promise { const transport: WalletP2PTransport = (await this.transport) as WalletP2PTransport - if (transport.connectionStatus === TransportStatus.NOT_CONNECTED) { + if (attempts == 0 || transport.connectionStatus !== TransportStatus.NOT_CONNECTED) { + return + } + + try { await transport.connect() - transport - .addListener(async (message: unknown, connectionInfo: ConnectionContext) => { - if (typeof message === 'string') { - const deserializedMessage = (await new Serializer().deserialize( - message - )) as BeaconRequestMessage - this.handleResponse(deserializedMessage, connectionInfo) - } - }) - .catch((error) => logger.log('_connect', error)) - this._isConnected.resolve(true) - } else { - // NO-OP + } catch (err: any) { + logger.warn('_connect', err.message) + if (err.message === 'The account is deactivated.') { + await transport.disconnect() + await this._connect(--attempts) + return + } } + + transport + .addListener(async (message: unknown, connectionInfo: ConnectionContext) => { + if (typeof message === 'string') { + const deserializedMessage = (await new Serializer().deserialize( + message + )) as BeaconRequestMessage + this.handleResponse(deserializedMessage, connectionInfo) + } + }) + .catch((error) => logger.log('_connect', error)) + this._isConnected.resolve(true) } /**