@ultraos/wallet-sdk 0.0.3 → 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 (112) hide show
  1. package/package.json +4 -3
  2. package/src/index.d.ts +3 -0
  3. package/src/index.d.ts.map +1 -0
  4. package/src/{index.ts → index.js} +1 -0
  5. package/src/index.js.map +1 -0
  6. package/src/lib/common/client-error.d.ts +8 -0
  7. package/src/lib/common/client-error.d.ts.map +1 -0
  8. package/src/lib/common/client-error.js +11 -0
  9. package/src/lib/common/client-error.js.map +1 -0
  10. package/src/lib/common/client-messenger.d.ts +10 -0
  11. package/src/lib/common/client-messenger.d.ts.map +1 -0
  12. package/src/lib/common/client-messenger.js +93 -0
  13. package/src/lib/common/client-messenger.js.map +1 -0
  14. package/src/lib/common/window-manager.d.ts +9 -0
  15. package/src/lib/common/window-manager.d.ts.map +1 -0
  16. package/src/lib/common/window-manager.js +25 -0
  17. package/src/lib/common/window-manager.js.map +1 -0
  18. package/src/lib/config/ultra-wallet-sdk.config.d.ts +16 -0
  19. package/src/lib/config/ultra-wallet-sdk.config.d.ts.map +1 -0
  20. package/src/lib/config/ultra-wallet-sdk.config.js +20 -0
  21. package/src/lib/config/ultra-wallet-sdk.config.js.map +1 -0
  22. package/src/lib/interfaces/blockchain-transaction.interface.d.ts +22 -0
  23. package/src/lib/interfaces/blockchain-transaction.interface.d.ts.map +1 -0
  24. package/src/lib/interfaces/blockchain-transaction.interface.js +2 -0
  25. package/src/lib/interfaces/blockchain-transaction.interface.js.map +1 -0
  26. package/src/lib/interfaces/connect-params.interface.d.ts +14 -0
  27. package/src/lib/interfaces/connect-params.interface.d.ts.map +1 -0
  28. package/src/lib/interfaces/connect-params.interface.js +2 -0
  29. package/src/lib/interfaces/connect-params.interface.js.map +1 -0
  30. package/src/lib/interfaces/error-enum.d.ts +11 -0
  31. package/src/lib/interfaces/error-enum.d.ts.map +1 -0
  32. package/src/lib/interfaces/error-enum.js +16 -0
  33. package/src/lib/interfaces/error-enum.js.map +1 -0
  34. package/src/lib/interfaces/index.d.ts +9 -0
  35. package/src/lib/interfaces/index.d.ts.map +1 -0
  36. package/src/lib/interfaces/{index.ts → index.js} +1 -0
  37. package/src/lib/interfaces/index.js.map +1 -0
  38. package/src/lib/interfaces/json-rpc-message.interface.d.ts +8 -0
  39. package/src/lib/interfaces/json-rpc-message.interface.d.ts.map +1 -0
  40. package/src/lib/interfaces/json-rpc-message.interface.js +2 -0
  41. package/src/lib/interfaces/json-rpc-message.interface.js.map +1 -0
  42. package/src/lib/interfaces/purchase-item.interface.d.ts +8 -0
  43. package/src/lib/interfaces/purchase-item.interface.d.ts.map +1 -0
  44. package/src/lib/interfaces/purchase-item.interface.js +9 -0
  45. package/src/lib/interfaces/purchase-item.interface.js.map +1 -0
  46. package/src/lib/interfaces/wallet-provider-response.interface.d.ts +150 -0
  47. package/src/lib/interfaces/wallet-provider-response.interface.d.ts.map +1 -0
  48. package/src/lib/interfaces/wallet-provider-response.interface.js +10 -0
  49. package/src/lib/interfaces/wallet-provider-response.interface.js.map +1 -0
  50. package/src/lib/interfaces/wallet-provider.interface.d.ts +41 -0
  51. package/src/lib/interfaces/wallet-provider.interface.d.ts.map +1 -0
  52. package/src/lib/interfaces/wallet-provider.interface.js +2 -0
  53. package/src/lib/interfaces/wallet-provider.interface.js.map +1 -0
  54. package/src/lib/interfaces/{wallet-sdk-options.interface.ts → wallet-sdk-options.interface.d.ts} +2 -1
  55. package/src/lib/interfaces/wallet-sdk-options.interface.d.ts.map +1 -0
  56. package/src/lib/interfaces/wallet-sdk-options.interface.js +2 -0
  57. package/src/lib/interfaces/wallet-sdk-options.interface.js.map +1 -0
  58. package/src/lib/providers/extension-provider/extension.provider.d.ts +17 -0
  59. package/src/lib/providers/extension-provider/extension.provider.d.ts.map +1 -0
  60. package/src/lib/providers/extension-provider/extension.provider.js +29 -0
  61. package/src/lib/providers/extension-provider/extension.provider.js.map +1 -0
  62. package/src/lib/providers/index.d.ts +3 -0
  63. package/src/lib/providers/index.d.ts.map +1 -0
  64. package/src/lib/providers/{index.ts → index.js} +1 -0
  65. package/src/lib/providers/index.js.map +1 -0
  66. package/src/lib/providers/web-provider/web.provider.d.ts +15 -0
  67. package/src/lib/providers/web-provider/web.provider.d.ts.map +1 -0
  68. package/src/lib/providers/web-provider/web.provider.js +36 -0
  69. package/src/lib/providers/web-provider/web.provider.js.map +1 -0
  70. package/src/lib/ultra-wallet-sdk.d.ts +25 -0
  71. package/src/lib/ultra-wallet-sdk.d.ts.map +1 -0
  72. package/src/lib/ultra-wallet-sdk.js +46 -0
  73. package/src/lib/ultra-wallet-sdk.js.map +1 -0
  74. package/src/lib/utils/chain-validator.d.ts +2 -0
  75. package/src/lib/utils/chain-validator.d.ts.map +1 -0
  76. package/src/lib/utils/chain-validator.js +6 -0
  77. package/src/lib/utils/chain-validator.js.map +1 -0
  78. package/src/lib/utils/detection.d.ts +2 -0
  79. package/src/lib/utils/detection.d.ts.map +1 -0
  80. package/src/lib/utils/detection.js +4 -0
  81. package/src/lib/utils/detection.js.map +1 -0
  82. package/LICENSE +0 -165
  83. package/README.md +0 -74
  84. package/eslint.config.js +0 -5
  85. package/jest.config.ts +0 -11
  86. package/karma.conf.js +0 -16
  87. package/project.json +0 -33
  88. package/src/lib/common/client-error.ts +0 -14
  89. package/src/lib/common/client-messenger.spec.ts +0 -118
  90. package/src/lib/common/client-messenger.ts +0 -109
  91. package/src/lib/common/window-manager.spec.ts +0 -65
  92. package/src/lib/common/window-manager.ts +0 -34
  93. package/src/lib/config/ultra-wallet-sdk.config.ts +0 -37
  94. package/src/lib/interfaces/blockchain-transaction.interface.ts +0 -21
  95. package/src/lib/interfaces/connect-params.interface.ts +0 -13
  96. package/src/lib/interfaces/error-enum.ts +0 -15
  97. package/src/lib/interfaces/json-rpc-message.interface.ts +0 -7
  98. package/src/lib/interfaces/purchase-item.interface.ts +0 -7
  99. package/src/lib/interfaces/wallet-provider-response.interface.ts +0 -157
  100. package/src/lib/interfaces/wallet-provider.interface.ts +0 -55
  101. package/src/lib/providers/extension-provider/extension.provider.spec.ts +0 -121
  102. package/src/lib/providers/extension-provider/extension.provider.ts +0 -55
  103. package/src/lib/providers/web-provider/web.provider.spec.ts +0 -76
  104. package/src/lib/providers/web-provider/web.provider.ts +0 -59
  105. package/src/lib/ultra-wallet-sdk.spec.ts +0 -90
  106. package/src/lib/ultra-wallet-sdk.ts +0 -67
  107. package/src/lib/utils/chain-validator.ts +0 -6
  108. package/src/lib/utils/detection.ts +0 -3
  109. package/tsconfig.json +0 -28
  110. package/tsconfig.lib.json +0 -12
  111. package/tsconfig.lib.prod.json +0 -9
  112. package/tsconfig.spec.json +0 -8
@@ -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,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,76 +0,0 @@
1
- import { WebProvider } from './web.provider';
2
- import { ClientMessenger } from '../../common/client-messenger';
3
- import { ResponseStatus, UltraResponse, UltraWalletSdkOptions } from '../../interfaces';
4
- import { BlockchainTransaction, PurchaseItemType } from '../../interfaces';
5
-
6
- jest.mock('../../common/client-messenger');
7
-
8
- describe('WebProvider', () => {
9
- let provider: WebProvider;
10
- let mockMessenger: jest.Mocked<ClientMessenger>;
11
- const mockOptions: UltraWalletSdkOptions = { environment: 'mainnet' };
12
-
13
- beforeEach(() => {
14
- mockMessenger = new ClientMessenger({} as any) as jest.Mocked<ClientMessenger>;
15
- (ClientMessenger as jest.Mock).mockImplementation(() => mockMessenger);
16
- provider = new WebProvider(mockOptions);
17
- });
18
-
19
- it('should call connect', async () => {
20
- const expectedResponse: UltraResponse = { status: ResponseStatus.SUCCESS, data: {} };
21
- mockMessenger.sendRequest.mockResolvedValueOnce(expectedResponse);
22
-
23
- const result = await provider.connect();
24
- expect(mockMessenger.sendRequest).toHaveBeenCalledWith('connect', {});
25
- expect(result).toEqual(expectedResponse);
26
- });
27
-
28
- it('should call disconnect', async () => {
29
- const expectedResponse: UltraResponse = { status: ResponseStatus.SUCCESS, data: true };
30
- mockMessenger.sendRequest.mockResolvedValueOnce(expectedResponse);
31
-
32
- const result = await provider.disconnect();
33
- expect(mockMessenger.sendRequest).toHaveBeenCalledWith('disconnect', {});
34
- expect(result).toEqual(expectedResponse);
35
- });
36
-
37
- it('should call signMessage', async () => {
38
- const expectedResponse: UltraResponse = { status: ResponseStatus.SUCCESS, data: { signature: 'abc' } };
39
- mockMessenger.sendRequest.mockResolvedValueOnce(expectedResponse);
40
-
41
- const message = 'test message';
42
- const result = await provider.signMessage(message);
43
- expect(mockMessenger.sendRequest).toHaveBeenCalledWith('signMessage', { message });
44
- expect(result).toEqual(expectedResponse);
45
- });
46
-
47
- it('should call signTransaction', async () => {
48
- const transaction: BlockchainTransaction = { action: 'foo', contract: 'bar', data: {}, authorizations: [] };
49
- const expectedResponse = { status: ResponseStatus.SUCCESS, data: { transactionHash: '0x123' } };
50
- mockMessenger.sendRequest.mockResolvedValueOnce(expectedResponse);
51
-
52
- const result = await provider.signTransaction(transaction);
53
- expect(mockMessenger.sendRequest).toHaveBeenCalledWith('signTransaction', { transaction });
54
- expect(result).toEqual(expectedResponse);
55
- });
56
-
57
- it('should call getChainId', async () => {
58
- const expectedResponse: UltraResponse = { status: ResponseStatus.SUCCESS, data: '1' };
59
- mockMessenger.sendRequest.mockResolvedValueOnce(expectedResponse);
60
-
61
- const result = await provider.getChainId();
62
- expect(mockMessenger.sendRequest).toHaveBeenCalledWith('getChainId', {});
63
- expect(result).toEqual(expectedResponse);
64
- });
65
-
66
- it('should call purchaseItem', async () => {
67
- const expectedResponse: UltraResponse = { status: ResponseStatus.SUCCESS, data: { orderId: '123' } };
68
- mockMessenger.sendRequest.mockResolvedValueOnce(expectedResponse);
69
-
70
- const itemType = 'horse' as PurchaseItemType;
71
- const itemId = '123';
72
- const result = await provider.purchaseItem(itemType, itemId);
73
- expect(mockMessenger.sendRequest).toHaveBeenCalledWith('purchaseItem', { itemType, itemId });
74
- expect(result).toEqual(expectedResponse);
75
- });
76
- });
@@ -1,59 +0,0 @@
1
- import { ClientMessenger } from '../../common/client-messenger';
2
- import { WindowManager } from '../../common/window-manager';
3
- import UltraWalletSdkConfig from '../../config/ultra-wallet-sdk.config';
4
- import {
5
- BlockchainTransaction,
6
- ConnectParams,
7
- ConnectResult,
8
- PurchaseItemResult,
9
- PurchaseItemType,
10
- SignMessageResult,
11
- SignTransactionResult,
12
- UltraResponse,
13
- UltraWalletProvider,
14
- UltraWalletSdkOptions,
15
- } from '../../interfaces';
16
-
17
- export class WebProvider implements UltraWalletProvider {
18
- private readonly windowManager: WindowManager;
19
- private readonly clientMessenger: ClientMessenger;
20
-
21
- constructor(private readonly options?: UltraWalletSdkOptions) {
22
- this.windowManager = new WindowManager(this.resolveWalletUrl());
23
- this.clientMessenger = new ClientMessenger(this.windowManager);
24
- }
25
-
26
- connect(_?: ConnectParams): Promise<UltraResponse<ConnectResult>> {
27
- return this.clientMessenger.sendRequest<ConnectResult>('connect', {});
28
- }
29
-
30
- disconnect(): Promise<UltraResponse<boolean>> {
31
- return this.clientMessenger.sendRequest<boolean>('disconnect', {});
32
- }
33
-
34
- signMessage(message: string): Promise<UltraResponse<SignMessageResult>> {
35
- return this.clientMessenger.sendRequest<SignMessageResult>('signMessage', { message });
36
- }
37
-
38
- signTransaction(
39
- transaction: BlockchainTransaction | BlockchainTransaction[],
40
- ): Promise<UltraResponse<SignTransactionResult>> {
41
- return this.clientMessenger.sendRequest<SignTransactionResult>('signTransaction', { transaction });
42
- }
43
-
44
- getChainId(): Promise<UltraResponse<string>> {
45
- return this.clientMessenger.sendRequest<string>('getChainId', {});
46
- }
47
-
48
- purchaseItem(itemType: PurchaseItemType, itemId: string): Promise<UltraResponse<PurchaseItemResult>> {
49
- return this.clientMessenger.sendRequest<PurchaseItemResult>('purchaseItem', {
50
- itemType,
51
- itemId,
52
- });
53
- }
54
-
55
- private resolveWalletUrl(): string {
56
- const env = UltraWalletSdkConfig.walletUrls[this.options?.environment || 'mainnet'];
57
- return env || this.options.environment;
58
- }
59
- }
@@ -1,90 +0,0 @@
1
- import { UltraWalletSDK } from './ultra-wallet-sdk';
2
- import { ExtensionProvider, WebProvider } from './providers';
3
- import * as detectionUtils from './utils/detection';
4
- import { ConnectParams, PurchaseItemType } from './interfaces';
5
-
6
- jest.mock('./providers/extension-provider/extension.provider');
7
- jest.mock('./providers/web-provider/web.provider');
8
- jest.mock('./utils/detection');
9
-
10
- describe('UltraWalletSDK', () => {
11
- let sdk: UltraWalletSDK;
12
- let connectSpy: jest.Mock;
13
- let disconnectSpy: jest.Mock;
14
- let signMessageSpy: jest.Mock;
15
- let signTransactionSpy: jest.Mock;
16
- let getChainIdSpy: jest.Mock;
17
- let purchaseItemSpy: jest.Mock;
18
-
19
- beforeEach(() => {
20
- connectSpy = jest.fn();
21
- disconnectSpy = jest.fn();
22
- signMessageSpy = jest.fn();
23
- signTransactionSpy = jest.fn();
24
- getChainIdSpy = jest.fn();
25
- purchaseItemSpy = jest.fn();
26
-
27
- (detectionUtils.isExtensionAvailable as jest.Mock).mockReturnValue(true);
28
- (ExtensionProvider as jest.Mock).mockImplementation(() => ({
29
- connect: connectSpy,
30
- disconnect: disconnectSpy,
31
- signMessage: signMessageSpy,
32
- signTransaction: signTransactionSpy,
33
- getChainId: getChainIdSpy,
34
- purchaseItem: purchaseItemSpy,
35
- }));
36
- });
37
-
38
- it('should use ExtensionProvider when extension is available', () => {
39
- sdk = new UltraWalletSDK();
40
- expect(sdk).toBeTruthy();
41
- });
42
-
43
- it('should use WebProvider when extension is not available', () => {
44
- (detectionUtils.isExtensionAvailable as jest.Mock).mockReturnValue(false);
45
- (WebProvider as unknown as jest.Mock).mockImplementation(() => ({
46
- connect: connectSpy,
47
- }));
48
-
49
- sdk = new UltraWalletSDK({ environment: 'testnet' });
50
- expect(sdk).toBeTruthy();
51
- });
52
-
53
- it('should delegate connect to the provider', async () => {
54
- sdk = new UltraWalletSDK();
55
- const params: ConnectParams = { onlyIfTrusted: true };
56
- await sdk.connect(params);
57
- expect(connectSpy).toHaveBeenCalledWith(params);
58
- });
59
-
60
- it('should delegate disconnect to the provider', async () => {
61
- sdk = new UltraWalletSDK();
62
- await sdk.disconnect();
63
- expect(disconnectSpy).toHaveBeenCalled();
64
- });
65
-
66
- it('should delegate signMessage to the provider', async () => {
67
- sdk = new UltraWalletSDK();
68
- await sdk.signMessage('hello');
69
- expect(signMessageSpy).toHaveBeenCalledWith('hello');
70
- });
71
-
72
- it('should delegate signTransaction to the provider', async () => {
73
- sdk = new UltraWalletSDK();
74
- const transaction = { contract: 'test', action: 'test', data: {}, authorizations: [] };
75
- await sdk.signTransaction(transaction);
76
- expect(signTransactionSpy).toHaveBeenCalledWith(transaction);
77
- });
78
-
79
- it('should delegate getChainId to the provider', async () => {
80
- sdk = new UltraWalletSDK();
81
- await sdk.getChainId();
82
- expect(getChainIdSpy).toHaveBeenCalled();
83
- });
84
-
85
- it('should delegate purchaseItem to the provider', async () => {
86
- sdk = new UltraWalletSDK();
87
- await sdk.purchaseItem(PurchaseItemType.UNIQ_FACTORY, 'item123');
88
- expect(purchaseItemSpy).toHaveBeenCalledWith('UniqFactory', 'item123');
89
- });
90
- });
@@ -1,67 +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 { ExtensionProvider, WebProvider } from './providers';
14
- import { isExtensionAvailable } from './utils/detection';
15
-
16
- /**
17
- * UltraWalletClient acts as a Facade for interacting with the Ultra Wallet.
18
- * It provides a unified API regardless of the underlying provider implementation (Extension or Web).
19
- */
20
- export class UltraWalletSDK {
21
- private provider: UltraWalletProvider;
22
-
23
- /**
24
- * Constructs an UltraWalletClient instance.
25
- * If the Ultra Wallet Extension is available (window.ultra), it will be used automatically.
26
- * If the Extension is not available, the Web Wallet provider will be initialized using the given network options.
27
- *
28
- * @param {UltraWalletSdkOptions} [options] - Configuration options for the Web Wallet fallback (environment or custom URL).
29
- */
30
- constructor(private readonly options?: UltraWalletSdkOptions) {
31
- this.provider = this.resolveWalletProvider();
32
- }
33
-
34
- connect(params?: ConnectParams): Promise<UltraResponse<ConnectResult>> {
35
- return this.provider.connect(params);
36
- }
37
-
38
- disconnect(): Promise<UltraResponse<boolean>> {
39
- return this.provider.disconnect();
40
- }
41
-
42
- signMessage(message: string): Promise<UltraResponse<SignMessageResult>> {
43
- return this.provider.signMessage(message);
44
- }
45
-
46
- signTransaction(
47
- transaction: BlockchainTransaction | BlockchainTransaction[],
48
- ): Promise<UltraResponse<SignTransactionResult>> {
49
- return this.provider.signTransaction(transaction);
50
- }
51
-
52
- getChainId(): Promise<UltraResponse<string>> {
53
- return this.provider.getChainId();
54
- }
55
-
56
- purchaseItem(itemType: PurchaseItemType, itemId: string): Promise<UltraResponse<PurchaseItemResult>> {
57
- return this.provider.purchaseItem(itemType, itemId);
58
- }
59
-
60
- private resolveWalletProvider(): UltraWalletProvider {
61
- if (isExtensionAvailable()) {
62
- return new ExtensionProvider();
63
- } else {
64
- return new WebProvider(this.options);
65
- }
66
- }
67
- }
@@ -1,6 +0,0 @@
1
- import UltraWalletSdkConfig from '../config/ultra-wallet-sdk.config';
2
-
3
- export function isValidChain(targetNetwork: string, walletChainId: string): boolean {
4
- const { chainId } = UltraWalletSdkConfig.networkInfo[targetNetwork] || {};
5
- return !chainId || chainId === walletChainId;
6
- }
@@ -1,3 +0,0 @@
1
- export function isExtensionAvailable(): boolean {
2
- return typeof window !== 'undefined' && 'ultra' in window;
3
- }
package/tsconfig.json DELETED
@@ -1,28 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "forceConsistentCasingInFileNames": true,
5
- "strict": true,
6
- "noImplicitOverride": true,
7
- "noPropertyAccessFromIndexSignature": true,
8
- "noImplicitReturns": true,
9
- "noFallthroughCasesInSwitch": true,
10
- "target": "es2020"
11
- },
12
- "files": [],
13
- "include": [],
14
- "references": [
15
- {
16
- "path": "./tsconfig.lib.json"
17
- },
18
- {
19
- "path": "./tsconfig.spec.json"
20
- }
21
- ],
22
- "angularCompilerOptions": {
23
- "enableI18nLegacyMessageIdFormat": false,
24
- "strictInjectionParameters": true,
25
- "strictInputAccessModifiers": true,
26
- "strictTemplates": true
27
- }
28
- }
package/tsconfig.lib.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
- "declaration": true,
6
- "declarationMap": true,
7
- "inlineSources": true,
8
- "types": ["chrome"]
9
- },
10
- "files": ["src/index.ts"],
11
- "exclude": ["src/**/*.spec.ts", "jest.config.ts", "src/**/*.test.ts"]
12
- }
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "./tsconfig.lib.json",
3
- "compilerOptions": {
4
- "declarationMap": false
5
- },
6
- "angularCompilerOptions": {
7
- "compilationMode": "partial"
8
- }
9
- }
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "./tsconfig.lib.json",
3
- "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
- "types": ["jest"]
6
- },
7
- "include": ["**/*.spec.ts", "**/*.d.ts"]
8
- }