Skip to content

Commit

Permalink
add xportal hub integration
Browse files Browse the repository at this point in the history
  • Loading branch information
juliancwirko committed Jan 13, 2024
1 parent 3003c36 commit e1a26c6
Show file tree
Hide file tree
Showing 28 changed files with 1,330 additions and 836 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
meta.txt
meta.json
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ dev-server.mjs
esbuild.config.cjs
tsconfig.json
meta.txt
meta.json
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### [0.15.0](https://github.com/elven-js/elven.js/releases/tag/v0.15.0) (2024-01-13)
- add webview provider (based on sdk-dapp), required for xPortal Hub integration (experimental, need more tests and rewrites, it will probably land in a separate package in the following updates)
- update dependencies

### [0.14.0](https://github.com/elven-js/elven.js/releases/tag/v0.14.0) (2023-11-25)
- add tools for signing messages with all supported providers (`ElvenJS.signMessage`). Find more details in the [demo example]((/example/index.html)) and [documentation]((https://www.elvenjs.com)).
- update dependencies
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ or from CDN:
TokenTransfer,
ContractFunction,
U32Value,
} from 'https://unpkg.com/elven.js@0.9.0/build/elven.js';
} from 'https://unpkg.com/elven.js@<actual_version_here>/build/elven.js';
// Your code here
</script>
Expand All @@ -83,7 +83,7 @@ You will find the whole demo there. The same is deployed here: [elvenjs.netlify.

### Usage in frontend frameworks

Elven.js from v0.3.0 can also be used in many different frameworks by importing it from node_modules (of course, it is a client-side library). When it comes to React/Nextjs, it is advised to use one of the ready templates, for example, the one mentioned above. But Elven.js can be helpful in other frameworks where there are no templates yet. Example:
Elven.js can also be used in many different frameworks by importing it from node_modules (of course, it is a client-side library). When it comes to React/Nextjs, it is advised to use one of the ready templates, for example, the one mentioned above. But Elven.js can be helpful in other frameworks where there are no templates yet. Example:

```bash
npm install elven.js
Expand All @@ -99,11 +99,13 @@ The types should also be exported.

The API is limited for now, this will change, but even now, it can do most of the core operations:

- authenticate using the xPortal mobile, MultiversX browser extension or MultiversX Web Wallet
- authenticate using the xPortal mobile, MultiversX browser extension, MultiversX Web Wallet and xAlias
- integrate with xPortal Hub
- handle expiration of the auth state
- handle login with tokens to be able to get the signature
- sign transactions
- send transactions (also custom smart contracts)
- sign custom messages
- basic global states handling (local storage)
- basic structures for transaction payload
- sync the network on page load
Expand All @@ -114,10 +116,9 @@ The API is limited for now, this will change, but even now, it can do most of th

- authenticate with Ledger Nano
- result parsing (separate library)
- sign messages
- more advanced global state handling and (real-time updates (if needed)?)
- more structures and simplification for payload builders
- rethink the structure and split it into more files (???)
- split it into more files/libraries
- make it as small as possible

### What it won't probably do:
Expand Down
49 changes: 26 additions & 23 deletions build/elven.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions build/types/auth/login-with-native-auth-token.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Used for xPortal Hub integration
*/
export declare function loginWithNativeAuthToken(token: string, elven: any): void;
6 changes: 4 additions & 2 deletions build/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ExtensionProvider } from '@multiversx/sdk-extension-provider/out/extens
import { Transaction } from '@multiversx/sdk-core/out/transaction';
import { WalletConnectV2Provider } from '@multiversx/sdk-wallet-connect-provider/out/walletConnectV2Provider';
import { WalletProvider } from '@multiversx/sdk-web-wallet-provider/out/walletProvider';
import { WebviewProvider } from './webview-provider/webview-provider';
export interface InitOptions {
apiUrl?: string;
chainType?: string;
Expand All @@ -26,9 +27,10 @@ export declare enum LoginMethodsEnum {
mobile = "mobile",
webWallet = "web-wallet",
browserExtension = "browser-extension",
xAlias = "x-alias"
xAlias = "x-alias",
xPortalHub = "x-portal-hub"
}
export type DappProvider = ExtensionProvider | WalletConnectV2Provider | WalletProvider | undefined;
export type DappProvider = ExtensionProvider | WalletConnectV2Provider | WalletProvider | WebviewProvider | undefined;
export interface LoginOptions {
qrCodeContainer?: string | HTMLElement;
callbackRoute?: string;
Expand Down
8 changes: 8 additions & 0 deletions build/types/webview-provider/base64-utils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Required for xPortal Hub integration
* Based on sdk-dapp webview provider implementation
* It will probably be replaced with separate library in the future
*/
export declare function isStringBase64(str: string): boolean;
export declare function encodeToBase64(string: string): string;
export declare function decodeBase64(string: string): string;
14 changes: 14 additions & 0 deletions build/types/webview-provider/decode-login-token.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Required for xPortal Hub integration
* Based on sdk-dapp webview provider implementation
* It will probably be replaced with separate library in the future
*/
export interface DecodedLoginTokenType {
blockHash: string;
extraInfo?: {
timestamp: number;
};
origin: string;
ttl: number;
}
export declare const decodeLoginToken: (loginToken: string) => DecodedLoginTokenType | null;
13 changes: 13 additions & 0 deletions build/types/webview-provider/decode-native-auth-token.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Required for xPortal Hub integration
* Based on sdk-dapp webview provider implementation
* It will probably be replaced with separate library in the future
*/
import { DecodedLoginTokenType } from './decode-login-token';
interface DecodedNativeAuthTokenType extends DecodedLoginTokenType {
address: string;
body: string;
signature: string;
}
export declare const decodeNativeAuthToken: (accessToken?: string) => DecodedNativeAuthTokenType | null;
export {};
28 changes: 28 additions & 0 deletions build/types/webview-provider/request-methods.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Required for xPortal Hub integration
* Based on sdk-dapp webview provider implementation
* It will probably be replaced with separate library in the future
*/
export type CustomRequestPayloadType = {
request: {
method: string;
params: any;
};
};
export declare const requestMethods: {
signTransactions: {
ios: (transactions: any) => any;
reactNative: (message: any) => any;
web: (message: any) => any;
};
signMessage: {
ios: (message: string) => any;
reactNative: (message: any) => any;
web: (message: any) => any;
};
logout: {
ios: () => any;
reactNative: () => any;
web: () => any;
};
};
56 changes: 56 additions & 0 deletions build/types/webview-provider/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Required for xPortal Hub integration
* Based on sdk-dapp webview provider implementation
* It will probably be replaced with separate library in the future
*/
export declare enum PlatformsEnum {
ios = "ios",
reactNative = "reactNative",
web = "web",
webWallet = "webWallet"
}
export declare enum WebViewProviderResponseBaseEnums {
reloginResponse = "RELOGIN_RESPONSE"
}
declare enum CrossWindowProviderResponseEnums {
handshakeResponse = "HANDSHAKE_RESPONSE",
loginResponse = "LOGIN_RESPONSE",
disconnectResponse = "DISCONNECT_RESPONSE",
cancelResponse = "CANCEL_RESPONSE",
signTransactionsResponse = "SIGN_TRANSACTIONS_RESPONSE",
signMessageResponse = "SIGN_MESSAGE_RESPONSE",
noneResponse = "NONE_RESPONSE"
}
export declare const WebViewProviderResponseEnums: {
reloginResponse: WebViewProviderResponseBaseEnums.reloginResponse;
handshakeResponse: CrossWindowProviderResponseEnums.handshakeResponse;
loginResponse: CrossWindowProviderResponseEnums.loginResponse;
disconnectResponse: CrossWindowProviderResponseEnums.disconnectResponse;
cancelResponse: CrossWindowProviderResponseEnums.cancelResponse;
signTransactionsResponse: CrossWindowProviderResponseEnums.signTransactionsResponse;
signMessageResponse: CrossWindowProviderResponseEnums.signMessageResponse;
noneResponse: CrossWindowProviderResponseEnums.noneResponse;
};
export declare enum WebViewProviderRequestBaseEnums {
signTransactionsWithGuardianResponse = "SIGN_TRANSACTIONS_WITH_GUARDIAN_RESPONSE",
reloginRequest = "RELOGIN_REQUEST"
}
declare enum CrossWindowProviderRequestEnums {
signTransactionsRequest = "SIGN_TRANSACTIONS_REQUEST",
signMessageRequest = "SIGN_MESSAGE_REQUEST",
loginRequest = "LOGIN_REQUEST",
logoutRequest = "LOGOUT_REQUEST",
cancelAction = "CANCEL_ACTION_REQUEST",
finalizeHandshakeRequest = "FINALIZE_HANDSHAKE_REQUEST"
}
export declare const WebViewProviderRequestEnums: {
signTransactionsWithGuardianResponse: WebViewProviderRequestBaseEnums.signTransactionsWithGuardianResponse;
reloginRequest: WebViewProviderRequestBaseEnums.reloginRequest;
signTransactionsRequest: CrossWindowProviderRequestEnums.signTransactionsRequest;
signMessageRequest: CrossWindowProviderRequestEnums.signMessageRequest;
loginRequest: CrossWindowProviderRequestEnums.loginRequest;
logoutRequest: CrossWindowProviderRequestEnums.logoutRequest;
cancelAction: CrossWindowProviderRequestEnums.cancelAction;
finalizeHandshakeRequest: CrossWindowProviderRequestEnums.finalizeHandshakeRequest;
};
export {};
9 changes: 9 additions & 0 deletions build/types/webview-provider/utils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Required for xPortal Hub integration
* Based on sdk-dapp webview provider implementation
* It will probably be replaced with separate library in the future
*/
import { PlatformsEnum } from './types';
export declare const detectCurrentPlatform: () => PlatformsEnum.ios | PlatformsEnum.reactNative | PlatformsEnum.web;
export declare const getTargetOrigin: () => string;
export declare const isString: (x: any) => boolean;
13 changes: 13 additions & 0 deletions build/types/webview-provider/webview-provider.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Required for xPortal Hub integration
* Based on sdk-dapp webview provider implementation
* It will probably be replaced with separate library in the future
*/
import { Transaction } from '@multiversx/sdk-core';
export declare class WebviewProvider {
constructor();
logout(): Promise<unknown>;
signMessage(message: string): Promise<string>;
signTransactions(transactions: Transaction[]): Promise<Transaction[]>;
signTransaction(transaction: Transaction): Promise<Transaction>;
}
4 changes: 4 additions & 0 deletions esbuild.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ esbuild
outdir: 'build',
platform: 'browser',
})
.then((result) => {
fs.writeFileSync('./build/meta.json', JSON.stringify(result.metafile));
return result;
})
.then((result) => {
return esbuild.analyzeMetafile(result.metafile);
})
Expand Down
49 changes: 26 additions & 23 deletions example/elven.js

Large diffs are not rendered by default.

Loading

0 comments on commit e1a26c6

Please sign in to comment.