Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.0.0 #1282

Merged
merged 3 commits into from
Oct 22, 2024
Merged

v3.0.0 #1282

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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [⚠️ Breaking ⚠️[v3.0.0](https://github.com/multiversx/mx-sdk-dapp/pull/1282)] - 2024-10-21
- [Upgrade providers login methods & signMessage. Upgrade sdk-core to v.13](https://github.com/multiversx/mx-sdk-dapp/pull/1279)

## [[v2.40.11](https://github.com/multiversx/mx-sdk-dapp/pull/1280)] - 2024-10-09
- [Fixed axios interceptor concurrent calls](https://github.com/multiversx/mx-sdk-dapp/pull/1279)

Expand Down
27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-dapp",
"version": "2.40.11",
"version": "3.0.0",
"description": "A library to hold the main logic for a dapp on the MultiversX blockchain",
"author": "MultiversX",
"license": "GPL-3.0-or-later",
Expand All @@ -18,6 +18,8 @@
"build": "rimraf dist && node esbuild.js && yarn build:esm-types && yarn build:cjs-types && cp package.json dist && cp README.md dist",
"publish-package": "yarn test && yarn build && cd dist && npm publish",
"publish-package-next": "yarn test && yarn build && cd dist && npm publish --tag next",
"unpublish-verdaccio": "npm unpublish @multiversx/[email protected] --registry http://localhost:4873",
mgavrila marked this conversation as resolved.
Show resolved Hide resolved
"publish-verdaccio": "npm run unpublish-verdaccio && npm run build && cd dist && npm publish --registry http://localhost:4873/",
"publish-yalc": "yarn build && cd dist && yalc publish --push",
"watch": "yarn node esbuild-watch.js && yarn build:esm-types && yarn build:cjs-types -- --watch",
"test": "jest",
Expand All @@ -36,7 +38,7 @@
"@babel/preset-react": "7.23.3",
"@babel/preset-typescript": "7.23.3",
"@ledgerhq/hw-transport-mocker": "6.27.17",
"@multiversx/sdk-core": ">= 12.18.0",
"@multiversx/sdk-core": ">= 13.5.0",
"@octokit/rest": "19.0.5",
"@storybook/addon-actions": "6.5.14",
"@storybook/addon-essentials": "6.5.14",
Expand Down Expand Up @@ -122,7 +124,7 @@
"transaction"
],
"peerDependencies": {
"@multiversx/sdk-core": ">= 12.18.0",
"@multiversx/sdk-core": ">= 13.5.0",
"@types/react": "^18.0.24",
"@types/react-dom": "^18.0.8",
"axios": ">=1.7.4",
Expand Down Expand Up @@ -157,19 +159,19 @@
"dependencies": {
"@lifeomic/axios-fetch": "3.0.1",
"@metamask/providers": "16.0.0",
"@multiversx/sdk-dapp-utils": "0.1.0",
"@multiversx/sdk-extension-provider": "3.0.0",
"@multiversx/sdk-hw-provider": "6.4.0",
"@multiversx/sdk-metamask-provider": "0.0.7",
"@multiversx/sdk-dapp-utils": "1.0.0",
"@multiversx/sdk-extension-provider": "4.0.0",
"@multiversx/sdk-hw-provider": "7.0.0",
"@multiversx/sdk-metamask-provider": "1.0.0",
"@multiversx/sdk-native-auth-client": "1.0.9",
"@multiversx/sdk-opera-provider": "1.0.0-alpha.1",
"@multiversx/sdk-passkey-provider": "1.0.9",
"@multiversx/sdk-wallet": "4.6.0",
"@multiversx/sdk-wallet-connect-provider": "4.1.4",
"@multiversx/sdk-web-wallet-cross-window-provider": "1.0.0",
"@multiversx/sdk-web-wallet-iframe-provider": "1.0.3",
"@multiversx/sdk-web-wallet-provider": "3.2.1",
"@multiversx/sdk-webview-provider": "1.0.0",
"@multiversx/sdk-wallet-connect-provider": "5.0.0",
"@multiversx/sdk-web-wallet-cross-window-provider": "2.0.1",
"@multiversx/sdk-web-wallet-iframe-provider": "2.0.1",
"@multiversx/sdk-web-wallet-provider": "4.0.0",
"@multiversx/sdk-webview-provider": "2.0.0-alpha.0",
"@reduxjs/toolkit": "1.8.2",
"bignumber.js": "9.x",
"linkify-react": "4.0.2",
Expand All @@ -185,7 +187,6 @@
"react-redux": "8.0.2",
"redux-persist": "6.0.0",
"reselect": "4.0.0",
"shx": "0.3.4",
"socket.io-client": "4.6.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export const ExtensionProvider = {
'e4c98dd01020118b13db9dd5db9e5b56ff0c4a0141306918a9d3eea964a21ada5d566f58cdf6c921ed3405bf5685d1e87545dbcc86ea3c27a43aa3abee8c2b0e';
}
return Promise.resolve({
address: testAddress
address: testAddress,
signature
});
},
setAddress: () => provider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const mockLedgerProvider = async () => {

jest.spyOn(HWProvider.prototype, 'init').mockResolvedValue(true);
jest.spyOn(HWProvider.prototype, 'isInitialized').mockReturnValue(true);
jest.spyOn(HWProvider.prototype, 'isConnected').mockResolvedValue(true);
jest.spyOn(HWProvider.prototype, 'isConnected').mockReturnValue(true);
jest
.spyOn(HWProvider.prototype, 'getAccounts')
.mockResolvedValue([testAddress]);
Expand Down
4 changes: 1 addition & 3 deletions src/hooks/login/useExtensionLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,10 @@ export const useExtensionLogin = ({
...(token && { token })
};

await provider.login(providerLoginData);
const { signature, address } = await provider.login(providerLoginData);

setAccountProvider(provider);

const { signature, address } = provider.account;

if (!address) {
setIsLoading(false);
console.warn('Login cancelled.');
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/login/useLedgerLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const useLedgerLogin = ({
onLoginRedirect
}: UseLedgerLoginPropsType): LedgerLoginHookReturnType => {
const ledgerAccount = useSelector(ledgerAccountSelector);
const hwProvider = getAccountProvider() as HWProvider;
const hwProvider = getAccountProvider() as unknown as HWProvider;
const dispatch = useDispatch();
const isLoggedIn = getIsLoggedIn();
const hasNativeAuth = nativeAuth != null;
Expand Down Expand Up @@ -198,7 +198,7 @@ export const useLedgerLogin = ({
}
} else {
try {
const address = await hwProvider.login({ addressIndex: index });
const { address } = await hwProvider.login({ addressIndex: index });

dispatchLoginActions({
address,
Expand Down Expand Up @@ -295,7 +295,7 @@ export const useLedgerLogin = ({
return onLoginFailed(failInitializeErrorText);
}

const address = await hwProvider.login({
const { address } = await hwProvider.login({
addressIndex: selectedAddress.index.valueOf()
});

Expand Down
9 changes: 5 additions & 4 deletions src/hooks/signMessage/useSignMessage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from 'react';
import { SignableMessage, Address } from '@multiversx/sdk-core';
import { Address, Message } from '@multiversx/sdk-core';
import {
CANCELLED,
ERROR_SIGNING,
Expand Down Expand Up @@ -142,9 +142,10 @@ export const useSignMessage = (options?: { hasConsentPopup?: boolean }) => {
const address = await getAddress();
const provider = getAccountProvider();
const callbackUrl = encodeURIComponent(String(callbackRoute));
const signableMessage = new SignableMessage({

const signableMessage = new Message({
address: new Address(address),
message: Buffer.from(message, 'ascii')
data: Buffer.from(message)
});

return provider.signMessage(signableMessage, {
Expand Down Expand Up @@ -212,7 +213,7 @@ export const useSignMessage = (options?: { hasConsentPopup?: boolean }) => {
status: SignedMessageStatusesEnum.signed,
callbackUrl: callbackRoute,
message: props.message,
signature: signedMessage.signature.toString('hex')
signature: Buffer.from(signedMessage?.signature).toString('hex')
}
})
);
Expand Down
23 changes: 12 additions & 11 deletions src/hooks/signMessage/verifyMessage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, SignableMessage } from '@multiversx/sdk-core/out';
import { Address, Message, MessageComputer } from '@multiversx/sdk-core/out';
import { getVerifier } from './getVerifier';

export const verifyMessage = (signedMessage: string) => {
Expand All @@ -7,18 +7,19 @@ export const verifyMessage = (signedMessage: string) => {

const decodedMessage = Buffer.from(message.replace('0x', ''), 'hex');
const decodedSignature = Buffer.from(signature.replace('0x', ''), 'hex');
const bech32Address = new Address(address);
const signedM = new SignableMessage({
address: bech32Address,
message: decodedMessage,
signature: decodedSignature
});

const verifier = getVerifier(address);
const isVerified = verifier.verify(
signedM.serializeForSigning(),
signedM.getSignature()
);

const messageComputer = new MessageComputer();

const msg = new Message({
address: new Address(address),
data: decodedMessage
});

const serializedMessage = messageComputer.computeBytesForVerifying(msg);

const isVerified = verifier.verify(serializedMessage, decodedSignature);

return {
isVerified,
Expand Down
4 changes: 0 additions & 4 deletions src/lib/sdkDappUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
export { safeWindow } from '@multiversx/sdk-dapp-utils/out/constants/browserConstants';
export {
WindowProviderRequestEnums,
WindowProviderResponseEnums
} from '@multiversx/sdk-dapp-utils/out/enums/windowProviderEnums';
4 changes: 4 additions & 0 deletions src/lib/sdkWebWalletCrossWindowProvider.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export { CrossWindowProvider } from '@multiversx/sdk-web-wallet-cross-window-provider/out/CrossWindowProvider/CrossWindowProvider';
export {
WindowProviderRequestEnums,
WindowProviderResponseEnums
} from '@multiversx/sdk-web-wallet-cross-window-provider/out/enums';
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SignableMessage, Transaction } from '@multiversx/sdk-core';
import { Message, Transaction } from '@multiversx/sdk-core';
import { IDAppProviderAccount } from '@multiversx/sdk-dapp-utils/out';
import { providerNotInitializedError } from '@multiversx/sdk-dapp-utils/out/helpers/providerNotInitializedError';
import { WebviewProvider } from '@multiversx/sdk-webview-provider/out/WebviewProvider';
import { logoutAction } from 'reduxStore/commonActions';
Expand All @@ -24,6 +25,15 @@ export class ExperimentalWebviewProvider implements IDappProvider {
return ExperimentalWebviewProvider._instance;
}

getAccount(): IDAppProviderAccount | null {
const data = this._provider.getAccount();
return { address: data?.address ?? '' };
}

setAccount(account: IDAppProviderAccount): void {
this._provider.setAccount(account);
}

constructor() {
this._provider = WebviewProvider.getInstance({
resetStateCallback: () => store.dispatch(logoutAction())
Expand All @@ -35,7 +45,8 @@ export class ExperimentalWebviewProvider implements IDappProvider {
};

login = async () => {
return await this._provider.login();
const data = await this._provider.login();
return { address: data?.address ?? '' };
};

logout = async () => {
Expand Down Expand Up @@ -74,9 +85,7 @@ export class ExperimentalWebviewProvider implements IDappProvider {
return await this._provider.signTransaction(transaction);
};

signMessage = async (
message: SignableMessage
): Promise<SignableMessage | null> => {
signMessage = async (message: Message): Promise<Message | null> => {
return await this._provider.signMessage(message);
};

Expand All @@ -88,8 +97,8 @@ export class ExperimentalWebviewProvider implements IDappProvider {
return this._provider.isInitialized();
};

isConnected = async () => {
return await this._provider.isConnected();
isConnected = () => {
return this._provider.isConnected();
};

sendCustomRequest = async (payload: {
Expand Down
17 changes: 13 additions & 4 deletions src/providers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SignableMessage, Transaction } from '@multiversx/sdk-core';
import { Message, Transaction } from '@multiversx/sdk-core';
import { IDAppProviderAccount } from '@multiversx/sdk-dapp-utils/out';
import { ExtensionProvider } from '@multiversx/sdk-extension-provider';
import { HWProvider } from '@multiversx/sdk-hw-provider';
import { IHWWalletApp } from '@multiversx/sdk-hw-provider/out/interface';
Expand Down Expand Up @@ -71,6 +72,14 @@ export class EmptyProvider implements IDappProvider {
return Promise.resolve(false);
}

getAccount(): IDAppProviderAccount | null {
throw new Error(notInitializedError('getAccount'));
}

setAccount(account: IDAppProviderAccount): void {
throw new Error(notInitializedError(`setAccount: ${account}`));
}

login<TOptions = { callbackUrl?: string } | undefined, TResponse = string>(
options?: TOptions
): Promise<TResponse> {
Expand All @@ -91,8 +100,8 @@ export class EmptyProvider implements IDappProvider {
return false;
}

isConnected(): Promise<boolean> {
return Promise.resolve(false);
isConnected(): boolean {
return false;
}

sendTransaction?<
Expand Down Expand Up @@ -128,7 +137,7 @@ export class EmptyProvider implements IDappProvider {
);
}

signMessage<T extends SignableMessage, TOptions = { callbackUrl?: string }>(
signMessage<T extends Message, TOptions = { callbackUrl?: string }>(
message: T,
options: TOptions
): Promise<T> {
Expand Down
2 changes: 1 addition & 1 deletion src/types/dappProvider.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface IDappProvider extends IDAppProviderBase {
init?(): Promise<boolean>;
getAddress(): Promise<string>;
isInitialized(): boolean;
isConnected(): Promise<boolean>;
isConnected(): boolean;
sendTransaction?(
transaction: Transaction,
options?: DappOptions
Expand Down
2 changes: 1 addition & 1 deletion src/types/enums.types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
WindowProviderRequestEnums,
WindowProviderResponseEnums
} from 'lib/sdkDappUtils';
} from 'lib/sdkWebWalletCrossWindowProvider';

export enum TransactionServerStatusesEnum {
pending = 'pending',
Expand Down
7 changes: 4 additions & 3 deletions src/utils/account/signMessage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SignableMessage, Address } from '@multiversx/sdk-core';
import { Message, Address } from '@multiversx/sdk-core';
import { CrossWindowProvider } from 'lib/sdkWebWalletCrossWindowProvider';
import { getAccountProvider, getProviderType } from 'providers';
import { LoginMethodsEnum } from 'types';
Expand All @@ -23,9 +23,10 @@ export const signMessage = async ({
const providerType = getProviderType(provider);

const callbackUrl = addOriginToLocationPath(callbackRoute);
const signableMessage = new SignableMessage({

const signableMessage = new Message({
address: new Address(address),
message: Buffer.from(message, 'ascii')
data: Buffer.from(message)
});

if (
Expand Down
2 changes: 1 addition & 1 deletion src/utils/tests/ledger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ test('HWProvider login', async () => {
const provider = new HWProvider(ledgerApp);

// Test the login method
const address = await provider.login({ addressIndex: 0 });
const { address } = await provider.login({ addressIndex: 0 });
expect(address).toBe('mockAddress');
});
Loading
Loading