@injectivelabs/wallet-magic 1.15.6 → 1.15.7

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.
@@ -1,14 +1,9 @@
1
1
  import { TxRaw, DirectSignResponse, AminoSignResponse } from '@injectivelabs/sdk-ts';
2
2
  import { AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
3
- import { StdSignDoc, MagicMetadata, MagicProvider, WalletDeviceType, BaseConcreteStrategy, BrowserEip1993Provider, ConcreteWalletStrategy, SendTransactionOptions, WalletStrategyArguments } from '@injectivelabs/wallet-base';
4
- interface MagicConnectArgs extends WalletStrategyArguments {
5
- metadata?: MagicMetadata;
6
- }
3
+ import { StdSignDoc, MagicProvider, WalletDeviceType, BaseConcreteStrategy, BrowserEip1993Provider, ConcreteWalletStrategy, SendTransactionOptions } from '@injectivelabs/wallet-base';
7
4
  export declare class Magic extends BaseConcreteStrategy implements ConcreteWalletStrategy {
8
5
  provider: BrowserEip1993Provider | undefined;
9
- metadata?: MagicMetadata;
10
6
  private magicWallet;
11
- constructor(args: MagicConnectArgs);
12
7
  getWalletDeviceType(): Promise<WalletDeviceType>;
13
8
  enable({ email, provider, }: {
14
9
  email?: string;
@@ -42,5 +37,5 @@ export declare class Magic extends BaseConcreteStrategy implements ConcreteWalle
42
37
  getEthereumTransactionReceipt(_txHash: string): Promise<string>;
43
38
  getPubKey(): Promise<string>;
44
39
  private pollUserLoggedInState;
40
+ private getMagicWallet;
45
41
  }
46
- export {};
@@ -10,27 +10,7 @@ const cosmos_1 = require("@magic-ext/cosmos");
10
10
  const wallet_base_1 = require("@injectivelabs/wallet-base");
11
11
  class Magic extends wallet_base_1.BaseConcreteStrategy {
12
12
  provider;
13
- metadata;
14
13
  magicWallet;
15
- constructor(args) {
16
- if (!args.metadata?.apiKey) {
17
- throw new exceptions_1.WalletException(new Error('You have to pass the apiKey within metadata to use Magic wallet'));
18
- }
19
- if (!args.metadata.rpcEndpoint) {
20
- throw new exceptions_1.WalletException(new Error('You have to pass the rpc url endpoint within metadata to use Magic wallet'));
21
- }
22
- super(args);
23
- this.metadata = args.metadata;
24
- this.magicWallet = new magic_sdk_1.Magic(args.metadata.apiKey, {
25
- extensions: [
26
- new oauth2_1.OAuthExtension(),
27
- new cosmos_1.CosmosExtension({
28
- rpcUrl: args.metadata.rpcEndpoint,
29
- chain: 'inj',
30
- }),
31
- ],
32
- });
33
- }
34
14
  async getWalletDeviceType() {
35
15
  return Promise.resolve(wallet_base_1.WalletDeviceType.Browser);
36
16
  }
@@ -57,37 +37,41 @@ class Magic extends wallet_base_1.BaseConcreteStrategy {
57
37
  }
58
38
  }
59
39
  async connectViaEmail(email) {
40
+ const magicWallet = await this.getMagicWallet();
60
41
  if (!email) {
61
42
  throw new exceptions_1.WalletException(new Error('You have to pass the email for using Magic wallet'));
62
43
  }
63
- return this.magicWallet.auth.loginWithMagicLink({ email });
44
+ return magicWallet.auth.loginWithMagicLink({ email });
64
45
  }
65
46
  async connectViaOauth(provider) {
66
- return this.magicWallet.oauth2.loginWithRedirect({
47
+ const magicWallet = await this.getMagicWallet();
48
+ return magicWallet.oauth2.loginWithRedirect({
67
49
  provider: provider,
68
50
  redirectURI: window.location.origin,
69
51
  });
70
52
  }
71
53
  async disconnect() {
72
- const isUserLoggedIn = await this.magicWallet.user.isLoggedIn();
54
+ const magicWallet = await this.getMagicWallet();
55
+ const isUserLoggedIn = await magicWallet.user.isLoggedIn();
73
56
  if (!isUserLoggedIn) {
74
57
  return;
75
58
  }
76
- await this.magicWallet.user.logout();
59
+ await magicWallet.user.logout();
77
60
  }
78
61
  async getAddresses({ provider, }) {
62
+ const magicWallet = await this.getMagicWallet();
79
63
  if (!provider) {
80
64
  try {
81
- await this.magicWallet.oauth2.getRedirectResult();
65
+ await magicWallet.oauth2.getRedirectResult();
82
66
  }
83
67
  catch {
84
68
  // fail silently
85
69
  }
86
70
  }
87
71
  try {
88
- const { publicAddress } = await this.magicWallet.user.getInfo();
72
+ const { publicAddress } = await magicWallet.user.getInfo();
89
73
  if (!publicAddress?.startsWith('inj')) {
90
- const address = await this.magicWallet.cosmos.changeAddress('inj');
74
+ const address = await magicWallet.cosmos.changeAddress('inj');
91
75
  return [address || ''];
92
76
  }
93
77
  return [publicAddress || ''];
@@ -127,7 +111,8 @@ class Magic extends wallet_base_1.BaseConcreteStrategy {
127
111
  return response;
128
112
  }
129
113
  async signEip712TypedData(eip712json, _address) {
130
- const signature = await this.magicWallet.cosmos.signTypedData(eip712json);
114
+ const magicWallet = await this.getMagicWallet();
115
+ const signature = await magicWallet.cosmos.signTypedData(eip712json);
131
116
  return `0x${signature}`;
132
117
  }
133
118
  // eslint-disable-next-line class-methods-use-this
@@ -170,10 +155,11 @@ class Magic extends wallet_base_1.BaseConcreteStrategy {
170
155
  throw new exceptions_1.WalletException(new Error('You can only fetch PubKey from Cosmos native wallets'));
171
156
  }
172
157
  async pollUserLoggedInState(timeout = 60 * 1000) {
158
+ const magicWallet = await this.getMagicWallet();
173
159
  const POLL_INTERVAL = 3 * 1000;
174
160
  for (let i = 0; i <= timeout / POLL_INTERVAL; i += 1) {
175
161
  try {
176
- const result = await this.magicWallet.user.isLoggedIn();
162
+ const result = await magicWallet.user.isLoggedIn();
177
163
  if (result) {
178
164
  return result;
179
165
  }
@@ -192,5 +178,26 @@ class Magic extends wallet_base_1.BaseConcreteStrategy {
192
178
  contextModule: 'Magic-Wallet-pollUserLoggedInState',
193
179
  });
194
180
  }
181
+ async getMagicWallet() {
182
+ const { metadata } = this;
183
+ if (!this.magicWallet) {
184
+ if (!metadata?.magic?.apiKey) {
185
+ throw new exceptions_1.WalletException(new Error('You have to pass the apiKey within metadata to use Magic wallet'));
186
+ }
187
+ if (!metadata?.magic?.rpcEndpoint) {
188
+ throw new exceptions_1.WalletException(new Error('You have to pass the rpc url endpoint within metadata to use Magic wallet'));
189
+ }
190
+ this.magicWallet = new magic_sdk_1.Magic(metadata.magic.apiKey, {
191
+ extensions: [
192
+ new oauth2_1.OAuthExtension(),
193
+ new cosmos_1.CosmosExtension({
194
+ rpcUrl: metadata.magic.rpcEndpoint,
195
+ chain: 'inj',
196
+ }),
197
+ ],
198
+ });
199
+ }
200
+ return this.magicWallet;
201
+ }
195
202
  }
196
203
  exports.Magic = Magic;
@@ -1,14 +1,9 @@
1
1
  import { TxRaw, DirectSignResponse, AminoSignResponse } from '@injectivelabs/sdk-ts';
2
2
  import { AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
3
- import { StdSignDoc, MagicMetadata, MagicProvider, WalletDeviceType, BaseConcreteStrategy, BrowserEip1993Provider, ConcreteWalletStrategy, SendTransactionOptions, WalletStrategyArguments } from '@injectivelabs/wallet-base';
4
- interface MagicConnectArgs extends WalletStrategyArguments {
5
- metadata?: MagicMetadata;
6
- }
3
+ import { StdSignDoc, MagicProvider, WalletDeviceType, BaseConcreteStrategy, BrowserEip1993Provider, ConcreteWalletStrategy, SendTransactionOptions } from '@injectivelabs/wallet-base';
7
4
  export declare class Magic extends BaseConcreteStrategy implements ConcreteWalletStrategy {
8
5
  provider: BrowserEip1993Provider | undefined;
9
- metadata?: MagicMetadata;
10
6
  private magicWallet;
11
- constructor(args: MagicConnectArgs);
12
7
  getWalletDeviceType(): Promise<WalletDeviceType>;
13
8
  enable({ email, provider, }: {
14
9
  email?: string;
@@ -42,5 +37,5 @@ export declare class Magic extends BaseConcreteStrategy implements ConcreteWalle
42
37
  getEthereumTransactionReceipt(_txHash: string): Promise<string>;
43
38
  getPubKey(): Promise<string>;
44
39
  private pollUserLoggedInState;
40
+ private getMagicWallet;
45
41
  }
46
- export {};
@@ -7,27 +7,7 @@ import { CosmosExtension } from '@magic-ext/cosmos';
7
7
  import { WalletAction, MagicProvider, WalletDeviceType, BaseConcreteStrategy, } from '@injectivelabs/wallet-base';
8
8
  export class Magic extends BaseConcreteStrategy {
9
9
  provider;
10
- metadata;
11
10
  magicWallet;
12
- constructor(args) {
13
- if (!args.metadata?.apiKey) {
14
- throw new WalletException(new Error('You have to pass the apiKey within metadata to use Magic wallet'));
15
- }
16
- if (!args.metadata.rpcEndpoint) {
17
- throw new WalletException(new Error('You have to pass the rpc url endpoint within metadata to use Magic wallet'));
18
- }
19
- super(args);
20
- this.metadata = args.metadata;
21
- this.magicWallet = new MagicWallet(args.metadata.apiKey, {
22
- extensions: [
23
- new OAuthExtension(),
24
- new CosmosExtension({
25
- rpcUrl: args.metadata.rpcEndpoint,
26
- chain: 'inj',
27
- }),
28
- ],
29
- });
30
- }
31
11
  async getWalletDeviceType() {
32
12
  return Promise.resolve(WalletDeviceType.Browser);
33
13
  }
@@ -54,37 +34,41 @@ export class Magic extends BaseConcreteStrategy {
54
34
  }
55
35
  }
56
36
  async connectViaEmail(email) {
37
+ const magicWallet = await this.getMagicWallet();
57
38
  if (!email) {
58
39
  throw new WalletException(new Error('You have to pass the email for using Magic wallet'));
59
40
  }
60
- return this.magicWallet.auth.loginWithMagicLink({ email });
41
+ return magicWallet.auth.loginWithMagicLink({ email });
61
42
  }
62
43
  async connectViaOauth(provider) {
63
- return this.magicWallet.oauth2.loginWithRedirect({
44
+ const magicWallet = await this.getMagicWallet();
45
+ return magicWallet.oauth2.loginWithRedirect({
64
46
  provider: provider,
65
47
  redirectURI: window.location.origin,
66
48
  });
67
49
  }
68
50
  async disconnect() {
69
- const isUserLoggedIn = await this.magicWallet.user.isLoggedIn();
51
+ const magicWallet = await this.getMagicWallet();
52
+ const isUserLoggedIn = await magicWallet.user.isLoggedIn();
70
53
  if (!isUserLoggedIn) {
71
54
  return;
72
55
  }
73
- await this.magicWallet.user.logout();
56
+ await magicWallet.user.logout();
74
57
  }
75
58
  async getAddresses({ provider, }) {
59
+ const magicWallet = await this.getMagicWallet();
76
60
  if (!provider) {
77
61
  try {
78
- await this.magicWallet.oauth2.getRedirectResult();
62
+ await magicWallet.oauth2.getRedirectResult();
79
63
  }
80
64
  catch {
81
65
  // fail silently
82
66
  }
83
67
  }
84
68
  try {
85
- const { publicAddress } = await this.magicWallet.user.getInfo();
69
+ const { publicAddress } = await magicWallet.user.getInfo();
86
70
  if (!publicAddress?.startsWith('inj')) {
87
- const address = await this.magicWallet.cosmos.changeAddress('inj');
71
+ const address = await magicWallet.cosmos.changeAddress('inj');
88
72
  return [address || ''];
89
73
  }
90
74
  return [publicAddress || ''];
@@ -124,7 +108,8 @@ export class Magic extends BaseConcreteStrategy {
124
108
  return response;
125
109
  }
126
110
  async signEip712TypedData(eip712json, _address) {
127
- const signature = await this.magicWallet.cosmos.signTypedData(eip712json);
111
+ const magicWallet = await this.getMagicWallet();
112
+ const signature = await magicWallet.cosmos.signTypedData(eip712json);
128
113
  return `0x${signature}`;
129
114
  }
130
115
  // eslint-disable-next-line class-methods-use-this
@@ -167,10 +152,11 @@ export class Magic extends BaseConcreteStrategy {
167
152
  throw new WalletException(new Error('You can only fetch PubKey from Cosmos native wallets'));
168
153
  }
169
154
  async pollUserLoggedInState(timeout = 60 * 1000) {
155
+ const magicWallet = await this.getMagicWallet();
170
156
  const POLL_INTERVAL = 3 * 1000;
171
157
  for (let i = 0; i <= timeout / POLL_INTERVAL; i += 1) {
172
158
  try {
173
- const result = await this.magicWallet.user.isLoggedIn();
159
+ const result = await magicWallet.user.isLoggedIn();
174
160
  if (result) {
175
161
  return result;
176
162
  }
@@ -189,4 +175,25 @@ export class Magic extends BaseConcreteStrategy {
189
175
  contextModule: 'Magic-Wallet-pollUserLoggedInState',
190
176
  });
191
177
  }
178
+ async getMagicWallet() {
179
+ const { metadata } = this;
180
+ if (!this.magicWallet) {
181
+ if (!metadata?.magic?.apiKey) {
182
+ throw new WalletException(new Error('You have to pass the apiKey within metadata to use Magic wallet'));
183
+ }
184
+ if (!metadata?.magic?.rpcEndpoint) {
185
+ throw new WalletException(new Error('You have to pass the rpc url endpoint within metadata to use Magic wallet'));
186
+ }
187
+ this.magicWallet = new MagicWallet(metadata.magic.apiKey, {
188
+ extensions: [
189
+ new OAuthExtension(),
190
+ new CosmosExtension({
191
+ rpcUrl: metadata.magic.rpcEndpoint,
192
+ chain: 'inj',
193
+ }),
194
+ ],
195
+ });
196
+ }
197
+ return this.magicWallet;
198
+ }
192
199
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@injectivelabs/wallet-magic",
3
3
  "description": "Magic wallet strategy for use with @injectivelabs/wallet-core.",
4
- "version": "1.15.6",
4
+ "version": "1.15.7",
5
5
  "sideEffects": false,
6
6
  "type": "module",
7
7
  "author": {
@@ -56,16 +56,16 @@
56
56
  "start": "node dist/index.js"
57
57
  },
58
58
  "dependencies": {
59
- "@injectivelabs/exceptions": "^1.15.3",
60
- "@injectivelabs/sdk-ts": "^1.15.6",
61
- "@injectivelabs/ts-types": "^1.15.4",
62
- "@injectivelabs/utils": "^1.15.4",
63
- "@injectivelabs/wallet-base": "^1.15.6",
59
+ "@injectivelabs/exceptions": "^1.15.4",
60
+ "@injectivelabs/sdk-ts": "^1.15.7",
61
+ "@injectivelabs/ts-types": "^1.15.5",
62
+ "@injectivelabs/utils": "^1.15.5",
63
+ "@injectivelabs/wallet-base": "^1.15.7",
64
64
  "@magic-ext/cosmos": "23.9.1",
65
65
  "@magic-ext/oauth2": "9.9.0",
66
66
  "magic-sdk": "28.9.0"
67
67
  },
68
- "gitHead": "de7c94dbd9f169649cab7bcc66d16fa73a2bd8a3",
68
+ "gitHead": "9beac4caf49a97d0d64bde184c4fc603696b81c0",
69
69
  "typedoc": {
70
70
  "entryPoint": "./src/index.ts",
71
71
  "readmeFile": "./README.md",