-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
18 changed files
with
744 additions
and
442 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { initStore } from 'store/store'; | ||
import { defaultStorageCallback } from 'store/storage'; | ||
import { setNativeAuthConfig } from 'store/actions/config/configActions'; | ||
import { initializeNetwork } from 'store/actions'; | ||
import { NativeAuthConfigType } from 'services/nativeAuth/nativeAuth.types'; | ||
import { getDefaultNativeAuthConfig } from 'services/nativeAuth/methods/getDefaultNativeAuthConfig'; | ||
import { InitAppType } from './initApp.types'; | ||
|
||
const defaultInitAppProps = { | ||
storage: { | ||
getStorageCallback: defaultStorageCallback | ||
} | ||
}; | ||
|
||
/** | ||
* Initializes the dApp with the given configuration. | ||
* @param props - The configuration for the dApp initialization. | ||
* | ||
* @example | ||
* ```ts | ||
initApp({ | ||
nativeAuth: true, | ||
environment: EnvironmentsEnum.devnet | ||
}); | ||
* ``` | ||
* */ | ||
export const initApp = async ({ | ||
storage = defaultInitAppProps.storage, | ||
dAppConfig | ||
}: InitAppType) => { | ||
initStore(storage.getStorageCallback); | ||
|
||
if (dAppConfig?.nativeAuth) { | ||
const nativeAuthConfig: NativeAuthConfigType = | ||
typeof dAppConfig.nativeAuth === 'boolean' | ||
? getDefaultNativeAuthConfig() | ||
: dAppConfig.nativeAuth; | ||
|
||
setNativeAuthConfig(nativeAuthConfig); | ||
} | ||
|
||
await initializeNetwork({ | ||
customNetworkConfig: dAppConfig.network, | ||
environment: dAppConfig.environment | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { StorageCallback } from 'store/storage'; | ||
import { CustomNetworkType } from 'types/network.types'; | ||
import { EnvironmentsEnum } from 'types/enums.types'; | ||
import { NativeAuthConfigType } from 'services/nativeAuth/nativeAuth.types'; | ||
|
||
type BaseDappConfigType = { | ||
/** | ||
* The native auth configuration for the dApp. | ||
* If set to `true`, will fallback on default configuration. | ||
* If set to `false`, will disable native auth. | ||
* If set to `NativeAuthConfigType`, will set the native auth configuration. | ||
*/ | ||
nativeAuth?: boolean | NativeAuthConfigType; | ||
}; | ||
|
||
export type EnvironmentDappConfigType = BaseDappConfigType & { | ||
/** | ||
* If passed in, will automatically initialize the network with the given environment. | ||
*/ | ||
environment: EnvironmentsEnum; | ||
network?: CustomNetworkType; | ||
}; | ||
|
||
export type CustomNetworkDappConfigType = BaseDappConfigType & { | ||
/** | ||
* Can override the network configuration, e.g. for sovereign shards. | ||
* Must include `apiAddress` if provided. | ||
*/ | ||
network: CustomNetworkType & { apiAddress: string }; | ||
environment?: never; | ||
}; | ||
|
||
export type DappConfigType = | ||
| EnvironmentDappConfigType | ||
| CustomNetworkDappConfigType; | ||
|
||
export type InitAppType = { | ||
/** | ||
* The storage configuration for the dApp. | ||
*/ | ||
storage?: { | ||
/** | ||
* The callback to get the storage (custom storage). | ||
*/ | ||
getStorageCallback: StorageCallback; | ||
}; | ||
dAppConfig: DappConfigType; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Address } from '@multiversx/sdk-core/out'; | ||
import { UserPublicKey, UserVerifier } from '@multiversx/sdk-wallet'; | ||
|
||
export const getVerifier = (address: string) => { | ||
const publicKey = new UserPublicKey(Address.fromString(address).pubkey()); | ||
|
||
return new UserVerifier(publicKey); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { SignableMessage, Address } from '@multiversx/sdk-core'; | ||
import { getAccountProvider } from 'core/providers'; | ||
import { getProviderType } from 'core/providers/helpers/utils'; | ||
import { CrossWindowProvider } from 'lib/sdkWebWalletCrossWindowProvider'; | ||
import { Nullable } from 'types'; | ||
import { getAddress } from '../account/getAddress'; | ||
import { addOriginToLocationPath } from 'utils/window/addOriginToLocationPath'; | ||
import { ProviderTypeEnum } from 'core/providers/types/providerFactory.types'; | ||
|
||
export interface SignMessageType { | ||
message: string; | ||
callbackRoute?: string; | ||
options?: { | ||
hasConsentPopup?: boolean; | ||
}; | ||
} | ||
|
||
// TODO: upgrade to Message | ||
export const signMessage = async ({ | ||
message, | ||
callbackRoute, | ||
options | ||
}: SignMessageType): Promise<Nullable<SignableMessage>> => { | ||
const address = getAddress(); | ||
const provider = getAccountProvider(); | ||
const providerType = getProviderType(provider); | ||
|
||
const callbackUrl = addOriginToLocationPath(callbackRoute); | ||
const signableMessage = new SignableMessage({ | ||
address: new Address(address), | ||
message: Buffer.from(message, 'ascii') | ||
}); | ||
|
||
if ( | ||
options?.hasConsentPopup && | ||
providerType === ProviderTypeEnum.crossWindow | ||
) { | ||
(provider as unknown as CrossWindowProvider).setShouldShowConsentPopup( | ||
true | ||
); | ||
} | ||
|
||
const signedMessage = await provider.signMessage(signableMessage, { | ||
callbackUrl: encodeURIComponent(callbackUrl) | ||
}); | ||
|
||
return signedMessage; | ||
}; |
Oops, something went wrong.