@ultraos/wallet-sdk 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/package.json +4 -3
  2. package/LICENSE +0 -165
  3. package/README.md +0 -74
  4. package/dist/libs/wallet-sdk/libs/wallet-sdk/README.md +0 -74
  5. package/eslint.config.js +0 -5
  6. package/jest.config.ts +0 -11
  7. package/karma.conf.js +0 -16
  8. package/project.json +0 -33
  9. package/src/index.ts +0 -2
  10. package/src/lib/common/client-error.ts +0 -14
  11. package/src/lib/common/client-messenger.spec.ts +0 -118
  12. package/src/lib/common/client-messenger.ts +0 -109
  13. package/src/lib/common/window-manager.spec.ts +0 -65
  14. package/src/lib/common/window-manager.ts +0 -34
  15. package/src/lib/config/ultra-wallet-sdk.config.ts +0 -37
  16. package/src/lib/interfaces/blockchain-transaction.interface.ts +0 -21
  17. package/src/lib/interfaces/connect-params.interface.ts +0 -13
  18. package/src/lib/interfaces/error-enum.ts +0 -15
  19. package/src/lib/interfaces/index.ts +0 -8
  20. package/src/lib/interfaces/json-rpc-message.interface.ts +0 -7
  21. package/src/lib/interfaces/purchase-item.interface.ts +0 -7
  22. package/src/lib/interfaces/wallet-provider-response.interface.ts +0 -157
  23. package/src/lib/interfaces/wallet-provider.interface.ts +0 -55
  24. package/src/lib/interfaces/wallet-sdk-options.interface.ts +0 -9
  25. package/src/lib/providers/extension-provider/extension.provider.spec.ts +0 -121
  26. package/src/lib/providers/extension-provider/extension.provider.ts +0 -55
  27. package/src/lib/providers/index.ts +0 -2
  28. package/src/lib/providers/web-provider/web.provider.spec.ts +0 -76
  29. package/src/lib/providers/web-provider/web.provider.ts +0 -59
  30. package/src/lib/ultra-wallet-sdk.spec.ts +0 -90
  31. package/src/lib/ultra-wallet-sdk.ts +0 -67
  32. package/src/lib/utils/chain-validator.ts +0 -6
  33. package/src/lib/utils/detection.ts +0 -3
  34. package/tsconfig.json +0 -28
  35. package/tsconfig.lib.json +0 -12
  36. package/tsconfig.lib.prod.json +0 -9
  37. package/tsconfig.spec.json +0 -8
@@ -1,65 +0,0 @@
1
- import { WindowManager } from './window-manager';
2
- import UltraWalletSdkConfig from '../config/ultra-wallet-sdk.config';
3
-
4
- describe('WindowManager', () => {
5
- let windowManager: WindowManager;
6
- const walletUrl = 'https://wallet.example.com';
7
-
8
- let walletWindowMock: Window;
9
-
10
- beforeEach(() => {
11
- walletWindowMock = {
12
- closed: false,
13
- focus: jest.fn(),
14
- } as unknown as Window;
15
-
16
- (window as any).open = jest.fn(() => walletWindowMock);
17
- Object.defineProperty(window, 'top', { value: 100 });
18
- Object.defineProperty(window, 'screenLeft', { value: 200 });
19
- Object.defineProperty(window, 'innerWidth', { value: 1200 });
20
-
21
- windowManager = new WindowManager(walletUrl);
22
- });
23
-
24
- afterEach(() => {
25
- jest.clearAllMocks();
26
- });
27
-
28
- it('opens a new wallet window when none exists', () => {
29
- windowManager.openOrReuseWallet();
30
-
31
- expect(window.open).toHaveBeenCalledWith(
32
- walletUrl,
33
- '_blank',
34
- expect.stringContaining(`width=${UltraWalletSdkConfig.width}`),
35
- );
36
- expect(windowManager.getWalletWindow()).toBe(walletWindowMock);
37
- });
38
-
39
- it('focuses existing wallet window if already open and not closed', () => {
40
- windowManager['walletWindow'] = walletWindowMock;
41
- windowManager.openOrReuseWallet();
42
-
43
- expect(walletWindowMock.focus).toHaveBeenCalled();
44
- expect(window.open).not.toHaveBeenCalled();
45
- });
46
-
47
- it('returns the current wallet window reference', () => {
48
- windowManager['walletWindow'] = walletWindowMock;
49
- const result = windowManager.getWalletWindow();
50
- expect(result).toBe(walletWindowMock);
51
- });
52
-
53
- it('opens a new window if previous one was closed', () => {
54
- const closedWindowMock = { closed: true } as unknown as Window;
55
- windowManager['walletWindow'] = closedWindowMock;
56
-
57
- windowManager.openOrReuseWallet();
58
-
59
- expect(window.open).toHaveBeenCalledWith(
60
- walletUrl,
61
- '_blank',
62
- expect.stringContaining(`width=${UltraWalletSdkConfig.width}`),
63
- );
64
- });
65
- });
@@ -1,34 +0,0 @@
1
- import UltraWalletSdkConfig from '../config/ultra-wallet-sdk.config';
2
-
3
- export class WindowManager {
4
- private currentWindow: Window;
5
- private walletWindow: Window | null = null;
6
- public readonly walletUrl: string;
7
-
8
- constructor(walletUrl: string) {
9
- this.currentWindow = window;
10
- this.walletUrl = walletUrl;
11
- }
12
-
13
- openOrReuseWallet() {
14
- if (this.walletWindow == null || this.walletWindow.closed) {
15
- const height = UltraWalletSdkConfig.height;
16
- const width = UltraWalletSdkConfig.width;
17
- const top = this.currentWindow.top;
18
- const left = this.currentWindow.screenLeft + this.currentWindow.innerWidth - width;
19
-
20
- this.walletWindow = window.open(
21
- this.walletUrl,
22
- '_blank',
23
- `width=${width},height=${height},top=${top},left=${left}`,
24
- );
25
- } else {
26
- this.walletWindow.focus();
27
- }
28
- }
29
-
30
- // Provides a reference to the wallet window
31
- getWalletWindow(): Window | null {
32
- return this.walletWindow;
33
- }
34
- }
@@ -1,37 +0,0 @@
1
- interface UltraWalletSdkConfig {
2
- width: number;
3
- height: number;
4
- walletUrls: {
5
- mainnet: string;
6
- testnet: string;
7
- };
8
- checkWindowInterval: number;
9
- handshakeTimeout: number;
10
- networkInfo: Record<
11
- 'mainnet' | 'testnet',
12
- {
13
- chainId: string;
14
- }
15
- >;
16
- }
17
-
18
- const UltraWalletSdkConfig: UltraWalletSdkConfig = Object.freeze({
19
- width: 345,
20
- height: 610,
21
- walletUrls: {
22
- mainnet: 'https://web-wallet.ultra.io',
23
- testnet: 'https://web-wallet.staging.ultra.io',
24
- },
25
- networkInfo: {
26
- mainnet: {
27
- chainId: 'a9c481dfbc7d9506dc7e87e9a137c931b0a9303f64fd7a1d08b8230133920097',
28
- },
29
- testnet: {
30
- chainId: '7fc56be645bb76ab9d747b53089f132dcb7681db06f0852cfa03eaf6f7ac80e9',
31
- },
32
- },
33
- checkWindowInterval: 500,
34
- handshakeTimeout: 10_000,
35
- });
36
-
37
- export default UltraWalletSdkConfig;
@@ -1,21 +0,0 @@
1
- /**
2
- * Defines the structure of a blockchain transaction request to be signed by the Ultra Wallet.
3
- */
4
- export interface BlockchainTransaction {
5
- /**
6
- * The smart contract address or name to interact with.
7
- */
8
- contract: string;
9
- /**
10
- * The action or method to call on the contract.
11
- */
12
- action: string;
13
- /**
14
- * The data payload for the contract action.
15
- */
16
- data: any;
17
- /**
18
- * List of authorizations (account@permission) required for the transaction.
19
- */
20
- authorizations?: string[];
21
- }
@@ -1,13 +0,0 @@
1
- /**
2
- * Optional parameters for establishing a connection with the Ultra Wallet.
3
- */
4
- export interface ConnectParams {
5
- /**
6
- * If true, do not prompt the user for permissions; share account info only if Dapp is already trusted.
7
- */
8
- onlyIfTrusted?: boolean;
9
- /**
10
- * Optional referral code to associate with the connection request.
11
- */
12
- referralCode?: string;
13
- }
@@ -1,15 +0,0 @@
1
- export enum SdkErrorCode {
2
- USER_REJECTED_REQUEST = 4001,
3
- WALLET_HANDSHAKE_TIMEOUT = 4300,
4
- WALLET_WINDOW_UNAVAILABLE = 4301,
5
- REQUESTED_RESOURCE_NOT_AVAILABLE = 32002,
6
- UNKNOWN_ERROR = -32604,
7
- }
8
-
9
- export const SDK_ERROR_MESSAGE: { [key in SdkErrorCode]: string } = {
10
- [SdkErrorCode.USER_REJECTED_REQUEST]: 'The user rejected the request.',
11
- [SdkErrorCode.WALLET_HANDSHAKE_TIMEOUT]: 'Timeout to connect with the web wallet.',
12
- [SdkErrorCode.WALLET_WINDOW_UNAVAILABLE]: 'The Web Wallet is not available.',
13
- [SdkErrorCode.REQUESTED_RESOURCE_NOT_AVAILABLE]: 'Requested resource not available.',
14
- [SdkErrorCode.UNKNOWN_ERROR]: 'Unknown error occurred.',
15
- };
@@ -1,8 +0,0 @@
1
- export * from './blockchain-transaction.interface';
2
- export * from './connect-params.interface';
3
- export * from './error-enum';
4
- export * from './json-rpc-message.interface';
5
- export * from './purchase-item.interface';
6
- export * from './wallet-provider.interface';
7
- export * from './wallet-provider-response.interface';
8
- export * from './wallet-sdk-options.interface';
@@ -1,7 +0,0 @@
1
- export interface JsonRpcMessage {
2
- jsonrpc: '2.0';
3
- method: string;
4
- params?: any;
5
- id?: string;
6
- result?: any;
7
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * Enumeration of supported item types that can be purchased via the Ultra Wallet.
3
- */
4
- export enum PurchaseItemType {
5
- UNIQ_FACTORY = 'UniqFactory',
6
- GAME_FACTORY = 'GameFactory',
7
- }
@@ -1,157 +0,0 @@
1
- /**
2
- * A generic wrapper for all Ultra Wallet SDK responses.
3
- * Encapsulates the status, data payload, and optional error messaging or codes.
4
- *
5
- * @template T The type of the data payload contained in the response.
6
- */
7
- export interface UltraResponse<T = any> {
8
- /**
9
- * The status of the response, e.g., success, fail, or error.
10
- */
11
- status: ResponseStatus;
12
- /**
13
- * The actual response data payload.
14
- */
15
- data: T;
16
- /**
17
- * Optional end-user-readable message, explaining what went wrong (if applicable).
18
- */
19
- message?: string;
20
- /**
21
- * Optional error or status code.
22
- */
23
- code?: number;
24
- }
25
-
26
- /**
27
- * Enumeration of possible response statuses returned by the Ultra Wallet SDK.
28
- */
29
- export enum ResponseStatus {
30
- SUCCESS = 'success',
31
- FAIL = 'fail',
32
- ERROR = 'error',
33
- }
34
-
35
- /**
36
- * Represents the result of a disconnect request.
37
- * A boolean indicating whether the disconnection was successful.
38
- */
39
- export type DisconnectResponse = boolean;
40
-
41
- /**
42
- * Represents the result of a successful connection request, containing the user's account details.
43
- */
44
- export type ConnectResult = Array<{
45
- /**
46
- * The blockchain network identifier.
47
- */
48
- blockchainid: string;
49
- /**
50
- * The public key associated with the user's account.
51
- */
52
- publicKey: string;
53
- }>;
54
-
55
- /**
56
- * The result structure returned after a successful item purchase using the Ultra Wallet.
57
- * Contains metadata about the purchased items and the associated blockchain transaction.
58
- */
59
- export interface PurchaseItemResult {
60
- /**
61
- * An ID associated with the purchase order, used for support requests if required.
62
- */
63
- orderHash: string;
64
-
65
- items: {
66
- /**
67
- * The ID of the minted Uniq.
68
- */
69
- artifactId: string;
70
- /**
71
- * The purchased item ID.
72
- */
73
- productId: string;
74
- /**
75
- * The ID of the transaction in the blockchain, useful for tracking the status and details of the transaction.
76
- */
77
- blockchainTransactionId: string;
78
- }[];
79
- }
80
-
81
- /**
82
- * Represents the result returned after signing a message with the Ultra Wallet.
83
- */
84
- export interface SignMessageResult {
85
- signature: string;
86
- }
87
-
88
- /**
89
- * Represents the result returned after signing a blockchain transaction with the Ultra Wallet.
90
- */
91
- export interface SignTransactionResult {
92
- /**
93
- * The hash of the signed blockchain transaction.
94
- */
95
- transactionHash?: string;
96
- processed?: {
97
- id: string;
98
- block_num: number;
99
- block_time: string; // ISO timestamp
100
- producer_block_id: string | null;
101
- receipt: {
102
- status: string;
103
- cpu_usage_us: number;
104
- net_usage_words: number;
105
- };
106
- elapsed: number;
107
- net_usage: number;
108
- scheduled: boolean;
109
- action_traces: ActionTrace[];
110
- account_ram_delta: any | null;
111
- except: any | null;
112
- error_code: number | null;
113
- };
114
- }
115
-
116
- export interface ActionTrace {
117
- action_ordinal: number;
118
- creator_action_ordinal: number;
119
- closest_unnotified_ancestor_action_ordinal: number;
120
- receipt: {
121
- receiver: string;
122
- act_digest: string;
123
- global_sequence: number;
124
- recv_sequence: number;
125
- auth_sequence: [string, number][];
126
- code_sequence: number;
127
- abi_sequence: number;
128
- };
129
- receiver: string;
130
- act: {
131
- account: string;
132
- name: string;
133
- authorization: {
134
- actor: string;
135
- permission: string;
136
- }[];
137
- data: {
138
- from: string;
139
- to: string;
140
- quantity: string;
141
- memo: string;
142
- };
143
- hex_data: string;
144
- };
145
- context_free: boolean;
146
- elapsed: number;
147
- console: string;
148
- trx_id: string;
149
- block_num: number;
150
- block_time: string;
151
- producer_block_id: string | null;
152
- account_ram_deltas: any[];
153
- except: any | null;
154
- error_code: number | null;
155
- return_value_hex_data: string;
156
- inline_traces: ActionTrace[];
157
- }
@@ -1,55 +0,0 @@
1
- import { BlockchainTransaction } from './blockchain-transaction.interface';
2
- import { ConnectParams } from './connect-params.interface';
3
- import { PurchaseItemType } from './purchase-item.interface';
4
- import {
5
- ConnectResult,
6
- DisconnectResponse,
7
- PurchaseItemResult,
8
- SignMessageResult,
9
- SignTransactionResult,
10
- UltraResponse,
11
- } from './wallet-provider-response.interface';
12
-
13
- /**
14
- * Defines the minimal interface that a wallet provider must implement for the Ultra Wallet SDK.
15
- */
16
- export interface UltraWalletProvider {
17
- /**
18
- * Prompt the user for permission to share his wallet info with the 3rd party application.
19
- * Once permission is established the first time, the 3rd party application will be whitelisted for future requests.
20
- * @param params.onlyIfTrusted - Do not prompt the user for permissions. Share current account info if Dapp is already trusted,
21
- * otherwise rejects the request.
22
- */
23
- connect(params?: ConnectParams): Promise<UltraResponse<ConnectResult>>;
24
-
25
- /**
26
- * Remove permission to interact with the 3rd party application
27
- */
28
- disconnect(): Promise<UltraResponse<DisconnectResponse>>;
29
-
30
- /**
31
- * Open a popup to sign a message
32
- * @param message - The message to sign. The message should be prefixed with "0x:, UOSx:, or message:"
33
- */
34
- signMessage(message: string): Promise<UltraResponse<SignMessageResult>>;
35
-
36
- /**
37
- * Open a popup to sign a transaction
38
- * @param transaction - The transaction to sign
39
- */
40
- signTransaction(
41
- transaction: BlockchainTransaction | BlockchainTransaction[],
42
- ): Promise<UltraResponse<SignTransactionResult>>;
43
-
44
- /**
45
- * Get current chain id
46
- */
47
- getChainId(): Promise<UltraResponse<string>>;
48
-
49
- /**
50
- * Open a popup to purchase an item
51
- * @param {PurchaseItemType} itemType - The type of item to purchase
52
- * @param {string} itemId - The id of the item to purchase
53
- */
54
- purchaseItem(itemType: PurchaseItemType, itemId: string): Promise<UltraResponse<PurchaseItemResult>>;
55
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * Options to configure the UltraWalletClient behavior.
3
- * Used primarily when falling back to the Web Wallet if no Ultra extension is available.
4
- *
5
- * @property {('mainnet' | 'testnet' | string)} [environment] - Target environment; defaults to 'mainnet' if unspecified.
6
- */
7
- export interface UltraWalletSdkOptions {
8
- environment?: 'mainnet' | 'testnet' | string;
9
- }
@@ -1,121 +0,0 @@
1
- import {
2
- BlockchainTransaction,
3
- ConnectParams,
4
- ConnectResult,
5
- PurchaseItemResult,
6
- PurchaseItemType,
7
- ResponseStatus,
8
- SignMessageResult,
9
- SignTransactionResult,
10
- UltraResponse,
11
- } from '../../interfaces';
12
- import { ExtensionProvider } from './extension.provider';
13
- import UltraWalletSdkConfig from '../../config/ultra-wallet-sdk.config';
14
-
15
- describe('ExtensionProvider', () => {
16
- let provider: ExtensionProvider;
17
-
18
- const mockUltra: jest.Mocked<Window['ultra']> = {
19
- connect: jest.fn(),
20
- disconnect: jest.fn(),
21
- signMessage: jest.fn(),
22
- signTransaction: jest.fn(),
23
- getChainId: jest.fn(),
24
- purchaseItem: jest.fn(),
25
- };
26
-
27
- beforeEach(() => {
28
- (window as any).ultra = mockUltra;
29
- provider = new ExtensionProvider();
30
- });
31
-
32
- afterEach(() => {
33
- delete (window as any).ultra;
34
- jest.clearAllMocks();
35
- });
36
-
37
- it('calls connect with params', async () => {
38
- const params: ConnectParams = {};
39
- const expected: UltraResponse<ConnectResult> = {
40
- status: ResponseStatus.SUCCESS,
41
- data: [{ blockchainid: 'acc', publicKey: 'pk' }],
42
- };
43
- mockUltra.getChainId.mockResolvedValue({
44
- status: ResponseStatus.SUCCESS,
45
- data: UltraWalletSdkConfig.networkInfo.mainnet.chainId,
46
- });
47
- mockUltra.connect.mockResolvedValue(expected);
48
-
49
- const result = await provider.connect(params);
50
- expect(mockUltra.connect).toHaveBeenCalledWith(params);
51
- expect(result).toEqual(expected);
52
- });
53
-
54
- it('throws an error when connect is called with mismatched chainId', async () => {
55
- (window as any).ultra = {
56
- getChainId: jest.fn().mockResolvedValue({ data: 'wrong-chain' }),
57
- connect: jest.fn(),
58
- };
59
-
60
- const provider = new ExtensionProvider({ environment: 'testnet' });
61
-
62
- await expect(provider.connect()).rejects.toThrow(
63
- 'Wallet environment mismatch: expected "testnet" chain, but received "wrong-chain". Please verify the SDK configuration and the connected network.',
64
- );
65
- });
66
-
67
- it('calls disconnect', async () => {
68
- const expected: UltraResponse<boolean> = { status: ResponseStatus.SUCCESS, data: true };
69
- mockUltra.disconnect.mockResolvedValue(expected);
70
-
71
- const result = await provider.disconnect();
72
- expect(mockUltra.disconnect).toHaveBeenCalled();
73
- expect(result).toEqual(expected);
74
- });
75
-
76
- it('calls signMessage', async () => {
77
- const expected: UltraResponse<SignMessageResult> = {
78
- status: ResponseStatus.SUCCESS,
79
- data: { signature: '0xabc' },
80
- };
81
- mockUltra.signMessage.mockResolvedValue(expected);
82
-
83
- const result = await provider.signMessage('hello');
84
- expect(mockUltra.signMessage).toHaveBeenCalledWith('hello');
85
- expect(result).toEqual(expected);
86
- });
87
-
88
- it('calls signTransaction', async () => {
89
- const tx: BlockchainTransaction = { to: '0x123', amount: '42' } as any;
90
- const expected: UltraResponse<SignTransactionResult> = {
91
- status: ResponseStatus.SUCCESS,
92
- data: { transactionHash: '0x999' },
93
- };
94
- mockUltra.signTransaction.mockResolvedValue(expected);
95
-
96
- const result = await provider.signTransaction(tx);
97
- expect(mockUltra.signTransaction).toHaveBeenCalledWith(tx);
98
- expect(result).toEqual(expected);
99
- });
100
-
101
- it('calls getChainId', async () => {
102
- const expected: UltraResponse<string> = { status: ResponseStatus.SUCCESS, data: 'ultra-chain' };
103
- mockUltra.getChainId.mockResolvedValue(expected);
104
-
105
- const result = await provider.getChainId();
106
- expect(mockUltra.getChainId).toHaveBeenCalled();
107
- expect(result).toEqual(expected);
108
- });
109
-
110
- it('calls purchaseItem', async () => {
111
- const expected: UltraResponse<PurchaseItemResult> = {
112
- status: ResponseStatus.SUCCESS,
113
- data: { orderHash: 'abc123', items: [] },
114
- };
115
- mockUltra.purchaseItem.mockResolvedValue(expected);
116
-
117
- const result = await provider.purchaseItem(PurchaseItemType.UNIQ_FACTORY, '123');
118
- expect(mockUltra.purchaseItem).toHaveBeenCalledWith(PurchaseItemType.UNIQ_FACTORY, '123');
119
- expect(result).toEqual(expected);
120
- });
121
- });
@@ -1,55 +0,0 @@
1
- import {
2
- BlockchainTransaction,
3
- ConnectParams,
4
- ConnectResult,
5
- PurchaseItemResult,
6
- PurchaseItemType,
7
- SignMessageResult,
8
- SignTransactionResult,
9
- UltraResponse,
10
- UltraWalletProvider,
11
- UltraWalletSdkOptions,
12
- } from '../../interfaces';
13
- import { isValidChain } from '../../utils/chain-validator';
14
-
15
- declare global {
16
- interface Window {
17
- ultra: UltraWalletProvider;
18
- }
19
- }
20
-
21
- export class ExtensionProvider implements UltraWalletProvider {
22
- constructor(private readonly options?: UltraWalletSdkOptions) {}
23
-
24
- async connect(params?: ConnectParams): Promise<UltraResponse<ConnectResult>> {
25
- const { data: chainId } = await window.ultra.getChainId();
26
- if (!isValidChain(this.options?.environment, chainId)) {
27
- throw new Error(
28
- `Wallet environment mismatch: expected "${this.options?.environment}" chain, but received "${chainId}". Please verify the SDK configuration and the connected network.`,
29
- );
30
- }
31
- return window.ultra.connect(params);
32
- }
33
-
34
- disconnect(): Promise<UltraResponse<boolean>> {
35
- return window.ultra.disconnect();
36
- }
37
-
38
- signMessage(message: string): Promise<UltraResponse<SignMessageResult>> {
39
- return window.ultra.signMessage(message);
40
- }
41
-
42
- signTransaction(
43
- transaction: BlockchainTransaction | BlockchainTransaction[],
44
- ): Promise<UltraResponse<SignTransactionResult>> {
45
- return window.ultra.signTransaction(transaction);
46
- }
47
-
48
- getChainId(): Promise<UltraResponse<string>> {
49
- return window.ultra.getChainId();
50
- }
51
-
52
- purchaseItem(itemType: PurchaseItemType, itemId: string): Promise<UltraResponse<PurchaseItemResult>> {
53
- return window.ultra.purchaseItem(itemType, itemId);
54
- }
55
- }
@@ -1,2 +0,0 @@
1
- export * from './extension-provider/extension.provider';
2
- export * from './web-provider/web.provider';