Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: node
uses: actions/setup-node@v4
with:
node-version: 20.9.0
node-version: 20.18.0

- name: Deps
run: |
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"devDependencies": {
"@types/jest": "29.0.3",
"@types/node": "18.7.18",
"@typescript-eslint/eslint-plugin": "5.38.0",
"@typescript-eslint/parser": "5.38.0",
"eslint": "8.23.1",
"@typescript-eslint/eslint-plugin": "7.18.0",
"@typescript-eslint/parser": "7.18.0",
"eslint": "8.57.1",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-simple-import-sort": "8.0.0",
Expand All @@ -37,8 +37,8 @@
"prettier": "2.7.1",
"publish-scripts": "0.1.0",
"rimraf": "3.0.2",
"ts-jest": "29.0.1",
"typescript": "4.8.3"
"ts-jest": "29.4.5",
"typescript": "5.8.3"
},
"workspaces": [
"packages/*",
Expand All @@ -48,4 +48,4 @@
"type": "git",
"url": "https://github.com/hyperweb-io/cosmos-kit#readme"
}
}
}
19 changes: 8 additions & 11 deletions wallets/web3auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,17 @@
]
},
"dependencies": {
"@toruslabs/eccrypto": "6.2.0",
"@cosmos-kit/core": "^2.16.6",
"@solana/web3.js": "^1.77.3",
"@toruslabs/eccrypto": "^2.1.1",
"@web3auth/auth-adapter": "^9.5.0",
"@web3auth/base": "^9.5.0",
"@web3auth/base-provider": "^9.5.0",
"@web3auth/ethereum-provider": "^9.5.0",
"@web3auth/no-modal": "^9.5.0",
"@web3auth/solana-provider": "^9.5.0",
"ethereum-cryptography": "^2.1.2",
"url": "^0.11.1"
"@web3auth/auth": "^10.5.0",
"@web3auth/modal": "^10.4.0",
"url": "^0.11.1",
"viem": "^2.23.0",
"@react-native-async-storage/async-storage": "^2.2.0"
},
"devDependencies": {
"@chain-registry/types": "^0.46.11"
"@chain-registry/types": "^0.46.11",
"typescript": "5.8.3"
},
"peerDependencies": {
"@chain-registry/types": ">= 0.17",
Expand Down
9 changes: 4 additions & 5 deletions wallets/web3auth/src/extension/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import { OfflineAminoSigner, StdSignature } from '@cosmjs/amino';
import { OfflineDirectSigner } from '@cosmjs/proto-signing';
import { DappEnv, WalletClient } from '@cosmos-kit/core';
import { makeADR36AminoSignDoc } from '@keplr-wallet/cosmos';
import eccrypto from '@toruslabs/eccrypto';
import { LOGIN_PROVIDER } from '@web3auth/auth-adapter';
import { UserInfo } from '@web3auth/base';
import * as eccrypto from '@toruslabs/eccrypto';
import { AUTH_CONNECTION, UserInfo } from '@web3auth/modal';

import { Web3AuthSigner } from './signer';
import { Web3AuthClientOptions } from './types';
Expand Down Expand Up @@ -61,8 +60,8 @@ export class Web3AuthClient implements WalletClient {
}

if (
(this.#options?.loginProvider === LOGIN_PROVIDER.EMAIL_PASSWORDLESS ||
this.#options?.loginProvider === LOGIN_PROVIDER.SMS_PASSWORDLESS) &&
(this.#options?.loginProvider === AUTH_CONNECTION.EMAIL_PASSWORDLESS ||
this.#options?.loginProvider === AUTH_CONNECTION.SMS_PASSWORDLESS) &&
this.#loginHint === undefined
) {
throw new Error(
Expand Down
7 changes: 4 additions & 3 deletions wallets/web3auth/src/extension/main-wallet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MainWalletBase } from '@cosmos-kit/core';
import { getHashQueryParams } from '@web3auth/auth-adapter';
import { WEB3AUTH_NETWORK } from '@web3auth/base';
import { getHashQueryParams } from '@web3auth/auth';
import { WEB3AUTH_NETWORK } from '@web3auth/modal';

import { Web3AuthChainWallet } from './chain-wallet';
import { Web3AuthClient } from './client';
Expand Down Expand Up @@ -30,7 +30,8 @@ export class Web3AuthWallet extends MainWalletBase {
if (
typeof options.client?.web3AuthNetwork !== 'string' ||
!Object.values(WEB3AUTH_NETWORK).includes(
options.client.web3AuthNetwork
options.client
.web3AuthNetwork as typeof WEB3AUTH_NETWORK[keyof typeof WEB3AUTH_NETWORK]
)
) {
throw new Error('Invalid web3auth network');
Expand Down
2 changes: 1 addition & 1 deletion wallets/web3auth/src/extension/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
DirectSignResponse,
OfflineDirectSigner,
} from '@cosmjs/proto-signing';
import eccrypto from '@toruslabs/eccrypto';
import * as eccrypto from '@toruslabs/eccrypto';
import { SignDoc } from 'cosmjs-types/cosmos/tx/v1beta1/tx';

import { PromptSign, SignData, ToWorkerMessage } from './types';
Expand Down
22 changes: 4 additions & 18 deletions wallets/web3auth/src/extension/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,23 @@ import { AminoSignResponse, StdSignDoc } from '@cosmjs/amino';
import { AccountData, DirectSignResponse } from '@cosmjs/proto-signing';
import { Wallet } from '@cosmos-kit/core';
import { Ecies } from '@toruslabs/eccrypto';
import {
LOGIN_PROVIDER_TYPE,
MfaLevelType,
WEB3AUTH_NETWORK_TYPE,
} from '@web3auth/auth-adapter';
import { Web3AuthNoModalOptions } from '@web3auth/base';
import { AUTH_CONNECTION_TYPE, Web3AuthNoModalOptions } from '@web3auth/modal';
import { SignDoc } from 'cosmjs-types/cosmos/tx/v1beta1/tx';

export type Web3AuthWalletInfo = Wallet & { options: Web3AuthClientOptions };

export type Web3AuthLoginMethod = {
provider: LOGIN_PROVIDER_TYPE;
provider: AUTH_CONNECTION_TYPE;
name: string;
logo: string;
};

export type Web3AuthClientOptions = {
loginProvider: LOGIN_PROVIDER_TYPE;
mfaLevel?: MfaLevelType;
loginProvider: AUTH_CONNECTION_TYPE;
getLoginHint?: () => string | undefined;

// Web3Auth client options.
client: {
clientId: string;
web3AuthNetwork: WEB3AUTH_NETWORK_TYPE;
} & Omit<Web3AuthNoModalOptions, 'chainConfig'> & {
chainConfig?: Omit<
Web3AuthNoModalOptions['chainConfig'],
'chainNamespace'
>;
};
client: Web3AuthNoModalOptions;

// Mobile devices block popups by default, so the default behavior is to use
// the redirect method to sign-in on mobile, and the popup method on desktop.
Expand Down
70 changes: 26 additions & 44 deletions wallets/web3auth/src/extension/utils.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { sha256 } from '@cosmjs/crypto';
import { toUtf8 } from '@cosmjs/encoding';
import eccrypto, { Ecies } from '@toruslabs/eccrypto';
import { AuthAdapter, AuthLoginParams } from '@web3auth/auth-adapter';
import * as eccrypto from '@toruslabs/eccrypto';
import { Ecies } from '@toruslabs/eccrypto';
import {
ADAPTER_STATUS,
CHAIN_NAMESPACES,
CustomChainConfig,
CONNECTOR_STATUS,
SafeEventEmitterProvider,
UX_MODE,
WALLET_ADAPTERS,
} from '@web3auth/base';
import { CommonPrivateKeyProvider } from '@web3auth/base-provider';
import { Web3AuthNoModal } from '@web3auth/no-modal';
WALLET_CONNECTORS,
Web3Auth,
} from '@web3auth/modal';

import {
FromWorkerMessage,
Expand Down Expand Up @@ -116,28 +113,11 @@ export const connectClientAndProvider = async (
options: Web3AuthClientOptions,
{ dontAttemptLogin = false } = {}
): Promise<{
client: Web3AuthNoModal;
client: Web3Auth;
provider: SafeEventEmitterProvider | null;
}> => {
const chainConfig: CustomChainConfig = {
chainId: 'other',
rpcTarget: 'other',
displayName: 'other',
blockExplorerUrl: 'other',
ticker: 'other',
tickerName: 'other',
...options.client.chainConfig,
chainNamespace: CHAIN_NAMESPACES.OTHER,
};
const privateKeyProvider = new CommonPrivateKeyProvider({
config: {
chainConfig,
},
});
const client = new Web3AuthNoModal({
const client = new Web3Auth({
...options.client,
chainConfig,
privateKeyProvider,
});

// Popups are blocked by default on mobile browsers, so use redirect. Popup is
Expand All @@ -157,27 +137,29 @@ export const connectClientAndProvider = async (
);
}

const mfaLevel = options.mfaLevel ?? 'default';
const authAdapter = new AuthAdapter({
adapterSettings: {
uxMode,
},
loginSettings: {
mfaLevel,
},
});
client.configureAdapter(authAdapter);

await client.init();

// Wait up to 10 seconds for the client to be ready or connected.
// This is necessary on v10 because init() does not wait for the session to
// be restored.
const timeout = 10000;
const startTime = Date.now();
while (
client.status !== CONNECTOR_STATUS.READY &&
client.status !== CONNECTOR_STATUS.CONNECTED &&
Date.now() - startTime < timeout
) {
await new Promise((resolve) => setTimeout(resolve, 100));
}

let provider = client.connected ? client.provider : null;
if (!client.connected && !dontAttemptLogin) {
try {
const loginHint = options.getLoginHint?.();
provider = await client.connectTo(WALLET_ADAPTERS.AUTH, {
loginProvider: options.loginProvider,
login_hint: loginHint,
} as AuthLoginParams);
provider = await client.connectTo(WALLET_CONNECTORS.AUTH, {
authConnection: options.loginProvider,
loginHint: loginHint,
});
} catch (err) {
// Unnecessary error thrown during redirect, so log and ignore it.
if (
Expand All @@ -194,7 +176,7 @@ export const connectClientAndProvider = async (
}

if (usingRedirect) {
if (client.status === ADAPTER_STATUS.CONNECTED) {
if (client.status === CONNECTOR_STATUS.CONNECTED) {
// On successful connection from a redirect, remove the localStorage key
// so we do not attempt to auto connect on the next page load.
localStorage.removeItem(WEB3AUTH_REDIRECT_AUTO_CONNECT_KEY);
Expand Down
2 changes: 1 addition & 1 deletion wallets/web3auth/src/extension/web3auth.worker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Secp256k1Wallet } from '@cosmjs/amino';
import { DirectSecp256k1Wallet } from '@cosmjs/proto-signing';
import eccrypto from '@toruslabs/eccrypto';
import * as eccrypto from '@toruslabs/eccrypto';

import { ToWorkerMessage } from './types';
import { decrypt, hashObject } from './utils';
Expand Down
Loading