@injectivelabs/wallet-magic 0.0.2

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.
package/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # 🌟 Injective Protocol - Magic Wallet Strategy
2
+
3
+ <!-- TODO -->
4
+
5
+ [![downloads](https://img.shields.io/npm/dm/@injectivelabs/wallet-ts.svg)](https://www.npmjs.com/package/@injectivelabs/wallet-ts)
6
+ [![npm-version](https://img.shields.io/npm/v/@injectivelabs/wallet-ts.svg)](https://www.npmjs.com/package/@injectivelabs/wallet-ts)
7
+ [![license](https://img.shields.io/npm/l/express.svg)]()
8
+
9
+ _Package to use Magic Wallets on Injective via the wallet strategy._
10
+
11
+ ---
12
+
13
+ ## 📚 Installation
14
+
15
+ ```bash
16
+ yarn add @injectivelabs/wallet-magic
17
+ ```
18
+
19
+ ---
20
+
21
+ ## 📖 Documentation
22
+
23
+ Injective's wallet packages are intended to make it easy for developers to choose exactly what wallets - and subsequent dependencies - they
24
+ want to include in their projects.
25
+
26
+ Regardless of which wallet package(s) you choose to use you must also have `@injectivelabs/wallet-core` and `@injectivelabs/wallet-base`
27
+ installed. These contain all of the types and core wallet functionality, with the separate wallet packages only providing the necessary
28
+ dependencies and implementations for their specific wallets.
29
+
30
+ Here's a brief example of how to use this package to send 1 INJ.:
31
+
32
+ ```typescript
33
+ import { Wallet } from '@injectivelabs/wallet-base';
34
+ import { BaseWalletStrategy, MsgBroadcaster } from '@injectivelabs/wallet-core';
35
+ import { MagicStrategy } from '@injectivelabs/wallet-magic';
36
+
37
+
38
+ const strategyArgs: WalletStrategyArguments = {
39
+ chainId: ChainId.Mainnet,
40
+ wallet: Wallet.Magic,
41
+ strategies: {
42
+ [Wallet.Magic]: new MagicStrategy({
43
+ chainId: ChainId.Mainnet,
44
+ metadata: {
45
+ apiKey: 'YOUR_MAGIC_API_KEY'
46
+ }
47
+ }),
48
+ },
49
+ }
50
+ const walletStrategy = new BaseWalletStrategy(strategyArgs)
51
+
52
+ const msgBroadcaster = new MsgBroadcaster({
53
+ walletStrategy,
54
+ simulateTx: true,
55
+ network: Network.Mainnet,
56
+ })
57
+
58
+ const sendTX = async () => {
59
+ const injectiveAddress = 'someInjectiveAddress'
60
+
61
+ const message = MsgSend.fromJSON({
62
+ srcInjectiveAddress: injectiveAddress,
63
+ dstInjectiveAddress: injectiveAddress,
64
+ amount: {
65
+ amount: '1',
66
+ denom: 'inj',
67
+ },
68
+ })
69
+
70
+ return await msgBroadcaster.broadcast({ msgs: message })
71
+ }
72
+
73
+ const result = await sendTX()
74
+ ```
75
+
76
+ Read more and find example usages on our [WalletStrategy Docs](https://docs.ts.injective.network/wallet/wallet-wallet-strategy)
77
+
78
+ ---
79
+
80
+ ## 📜 Contribution
81
+
82
+ **Contribution guides and practices will be available once there is a stable foundation of the whole package set within the `injective-ts` repo.**
83
+
84
+ ---
85
+
86
+ ## ⛑ Support
87
+
88
+ Reach out to us at one of the following places!
89
+
90
+ - Website at <a href="https://injective.com" target="_blank">`injective.com`</a>
91
+ - Twitter at <a href="https://twitter.com/Injective_" target="_blank">`@Injective`</a>
92
+ - Discord at <a href="https://discord.com/invite/NK4qdbv" target="_blank">`Discord`</a>
93
+ - Telegram at <a href="https://t.me/joininjective" target="_blank">`Telegram`</a>
94
+
95
+ ---
96
+
97
+ ## 🔓 License
98
+
99
+ Copyright © 2021 - 2022 Injective Labs Inc. (https://injectivelabs.org/)
100
+
101
+ <a href="https://iili.io/mNneZN.md.png"><img src="https://iili.io/mNneZN.md.png" style="width: 300px; max-width: 100%; height: auto" />
102
+
103
+ Originally released by Injective Labs Inc. under: <br />
104
+ Apache License <br />
105
+ Version 2.0, January 2004 <br />
106
+ http://www.apache.org/licenses/
107
+
108
+ <p>&nbsp;</p>
109
+ <div align="center">
110
+ <sub><em>Powering the future of decentralized finance.</em></sub>
111
+ </div>
@@ -0,0 +1,2 @@
1
+ export { Magic as MagicStrategy } from './strategy/strategy';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,aAAa,EAAE,MAAM,qBAAqB,CAAA"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MagicStrategy = void 0;
4
+ var strategy_1 = require("./strategy/strategy");
5
+ Object.defineProperty(exports, "MagicStrategy", { enumerable: true, get: function () { return strategy_1.Magic; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,gDAA4D;AAAnD,yGAAA,KAAK,OAAiB"}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,47 @@
1
+ import { TxRaw, DirectSignResponse, AminoSignResponse } from '@injectivelabs/sdk-ts';
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
+ }
7
+ export declare class Magic extends BaseConcreteStrategy implements ConcreteWalletStrategy {
8
+ provider: BrowserEip1993Provider | undefined;
9
+ metadata?: MagicMetadata;
10
+ private magicWallet;
11
+ constructor(args: MagicConnectArgs);
12
+ getWalletDeviceType(): Promise<WalletDeviceType>;
13
+ enable({ email, provider, }: {
14
+ email?: string;
15
+ provider?: MagicProvider;
16
+ }): Promise<boolean>;
17
+ connectViaEmail(email?: string): Promise<string | null>;
18
+ connectViaOauth(provider: MagicProvider): Promise<any>;
19
+ disconnect(): Promise<void>;
20
+ getAddresses({ provider, }: {
21
+ provider: MagicProvider;
22
+ }): Promise<string[]>;
23
+ getSessionOrConfirm(address: AccountAddress): Promise<string>;
24
+ sendEthereumTransaction(_transaction: unknown, _options: {
25
+ address: AccountAddress;
26
+ ethereumChainId: EthereumChainId;
27
+ }): Promise<string>;
28
+ sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<any>;
29
+ signEip712TypedData(eip712json: string, _address: AccountAddress): Promise<string>;
30
+ signCosmosTransaction(_transaction: {
31
+ txRaw: TxRaw;
32
+ accountNumber: number;
33
+ chainId: string;
34
+ address: string;
35
+ }): Promise<DirectSignResponse>;
36
+ signAminoCosmosTransaction(_transaction: {
37
+ address: string;
38
+ signDoc: StdSignDoc;
39
+ }): Promise<AminoSignResponse>;
40
+ signArbitrary(_signer: AccountAddress, _data: string | Uint8Array): Promise<string>;
41
+ getEthereumChainId(): Promise<string>;
42
+ getEthereumTransactionReceipt(_txHash: string): Promise<string>;
43
+ getPubKey(): Promise<string>;
44
+ private pollUserLoggedInState;
45
+ }
46
+ export {};
47
+ //# sourceMappingURL=strategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../../../src/strategy/strategy.ts"],"names":[],"mappings":"AASA,OAAO,EACL,KAAK,EAEL,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,uBAAuB,CAAA;AAG9B,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACzE,OAAO,EACL,UAAU,EAEV,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,4BAA4B,CAAA;AAEnC,UAAU,gBAAiB,SAAQ,uBAAuB;IACxD,QAAQ,CAAC,EAAE,aAAa,CAAA;CACzB;AAED,qBAAa,KAAM,SAAQ,oBAAqB,YAAW,sBAAsB;IACxE,QAAQ,EAAE,sBAAsB,GAAG,SAAS,CAA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AG,OAAO,CAAC,iBAAiB,CAAC;IAWxB,aAAa,CACjB,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,MAAM,GAAG,UAAU,GACzB,OAAO,CAAC,MAAM,CAAC;IAWZ,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAUrC,6BAA6B,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAc/D,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;YAMpB,qBAAqB;CA6BpC"}
@@ -0,0 +1,238 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Magic = void 0;
13
+ /* eslint-disable class-methods-use-this */
14
+ const exceptions_1 = require("@injectivelabs/exceptions");
15
+ const magic_sdk_1 = require("magic-sdk");
16
+ const sdk_ts_1 = require("@injectivelabs/sdk-ts");
17
+ const oauth2_1 = require("@magic-ext/oauth2");
18
+ const cosmos_1 = require("@magic-ext/cosmos");
19
+ const wallet_base_1 = require("@injectivelabs/wallet-base");
20
+ class Magic extends wallet_base_1.BaseConcreteStrategy {
21
+ constructor(args) {
22
+ var _a;
23
+ if (!((_a = args.metadata) === null || _a === void 0 ? void 0 : _a.apiKey)) {
24
+ throw new exceptions_1.WalletException(new Error('You have to pass the apiKey within metadata to use Magic wallet'));
25
+ }
26
+ if (!args.metadata.rpcEndpoint) {
27
+ throw new exceptions_1.WalletException(new Error('You have to pass the rpc url endpoint within metadata to use Magic wallet'));
28
+ }
29
+ super(args);
30
+ this.metadata = args.metadata;
31
+ this.magicWallet = new magic_sdk_1.Magic(args.metadata.apiKey, {
32
+ extensions: [
33
+ new oauth2_1.OAuthExtension(),
34
+ new cosmos_1.CosmosExtension({
35
+ rpcUrl: args.metadata.rpcEndpoint,
36
+ chain: 'inj',
37
+ }),
38
+ ],
39
+ });
40
+ }
41
+ getWalletDeviceType() {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ return Promise.resolve(wallet_base_1.WalletDeviceType.Browser);
44
+ });
45
+ }
46
+ enable(_a) {
47
+ return __awaiter(this, arguments, void 0, function* ({ email, provider, }) {
48
+ if (!provider) {
49
+ return Promise.resolve(true);
50
+ }
51
+ try {
52
+ if (provider === wallet_base_1.MagicProvider.Email) {
53
+ yield this.connectViaEmail(email);
54
+ }
55
+ else {
56
+ yield this.connectViaOauth(provider);
57
+ }
58
+ yield this.pollUserLoggedInState();
59
+ return Promise.resolve(true);
60
+ }
61
+ catch (e) {
62
+ throw new exceptions_1.WalletException(new Error(e.message), {
63
+ code: exceptions_1.UnspecifiedErrorCode,
64
+ type: exceptions_1.ErrorType.WalletError,
65
+ contextModule: wallet_base_1.WalletAction.GetAccounts,
66
+ });
67
+ }
68
+ });
69
+ }
70
+ connectViaEmail(email) {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ if (!email) {
73
+ throw new exceptions_1.WalletException(new Error('You have to pass the email for using Magic wallet'));
74
+ }
75
+ return this.magicWallet.auth.loginWithMagicLink({ email });
76
+ });
77
+ }
78
+ connectViaOauth(provider) {
79
+ return __awaiter(this, void 0, void 0, function* () {
80
+ return this.magicWallet.oauth2.loginWithRedirect({
81
+ provider: provider,
82
+ redirectURI: window.location.origin,
83
+ });
84
+ });
85
+ }
86
+ disconnect() {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ const isUserLoggedIn = yield this.magicWallet.user.isLoggedIn();
89
+ if (!isUserLoggedIn) {
90
+ return;
91
+ }
92
+ yield this.magicWallet.user.logout();
93
+ });
94
+ }
95
+ getAddresses(_a) {
96
+ return __awaiter(this, arguments, void 0, function* ({ provider, }) {
97
+ if (!provider) {
98
+ try {
99
+ yield this.magicWallet.oauth2.getRedirectResult();
100
+ }
101
+ catch (_b) {
102
+ // fail silently
103
+ }
104
+ }
105
+ try {
106
+ const { publicAddress } = yield this.magicWallet.user.getInfo();
107
+ if (!(publicAddress === null || publicAddress === void 0 ? void 0 : publicAddress.startsWith('inj'))) {
108
+ const address = yield this.magicWallet.cosmos.changeAddress('inj');
109
+ return [address || ''];
110
+ }
111
+ return [publicAddress || ''];
112
+ }
113
+ catch (e) {
114
+ throw new exceptions_1.WalletException(new Error(e.message), {
115
+ code: exceptions_1.UnspecifiedErrorCode,
116
+ type: exceptions_1.ErrorType.WalletError,
117
+ contextModule: wallet_base_1.WalletAction.GetAccounts,
118
+ });
119
+ }
120
+ });
121
+ }
122
+ // eslint-disable-next-line class-methods-use-this
123
+ getSessionOrConfirm(address) {
124
+ return __awaiter(this, void 0, void 0, function* () {
125
+ return Promise.resolve(`0x${Buffer.from(`Confirmation for ${address} at time: ${Date.now()}`).toString('hex')}`);
126
+ });
127
+ }
128
+ sendEthereumTransaction(_transaction, _options) {
129
+ return __awaiter(this, void 0, void 0, function* () {
130
+ throw new exceptions_1.CosmosWalletException(new Error('sendEthereumTransaction is not supported. Leap only supports sending cosmos transactions'), {
131
+ code: exceptions_1.UnspecifiedErrorCode,
132
+ context: wallet_base_1.WalletAction.SendEthereumTransaction,
133
+ });
134
+ });
135
+ }
136
+ sendTransaction(transaction, options) {
137
+ return __awaiter(this, void 0, void 0, function* () {
138
+ const { endpoints, txTimeout } = options;
139
+ if (!endpoints) {
140
+ throw new exceptions_1.WalletException(new Error('You have to pass endpoints.grpc within the options for using Magic wallet'));
141
+ }
142
+ const txApi = new sdk_ts_1.TxGrpcApi(endpoints.grpc);
143
+ const response = yield txApi.broadcast(transaction, { txTimeout });
144
+ if (response.code !== 0) {
145
+ throw new exceptions_1.TransactionException(new Error(response.rawLog), {
146
+ code: exceptions_1.UnspecifiedErrorCode,
147
+ contextCode: response.code,
148
+ contextModule: response.codespace,
149
+ });
150
+ }
151
+ return response;
152
+ });
153
+ }
154
+ signEip712TypedData(eip712json, _address) {
155
+ return __awaiter(this, void 0, void 0, function* () {
156
+ const signature = yield this.magicWallet.cosmos.signTypedData(eip712json);
157
+ return `0x${signature}`;
158
+ });
159
+ }
160
+ // eslint-disable-next-line class-methods-use-this
161
+ signCosmosTransaction(_transaction) {
162
+ return __awaiter(this, void 0, void 0, function* () {
163
+ throw new exceptions_1.WalletException(new Error('This wallet does not support signing Cosmos transactions'), {
164
+ code: exceptions_1.UnspecifiedErrorCode,
165
+ type: exceptions_1.ErrorType.WalletError,
166
+ contextModule: wallet_base_1.WalletAction.SignTransaction,
167
+ });
168
+ });
169
+ }
170
+ signAminoCosmosTransaction(_transaction) {
171
+ return __awaiter(this, void 0, void 0, function* () {
172
+ throw new exceptions_1.WalletException(new Error('This wallet does not support signAminoCosmosTransaction'), {
173
+ code: exceptions_1.UnspecifiedErrorCode,
174
+ type: exceptions_1.ErrorType.WalletError,
175
+ contextModule: wallet_base_1.WalletAction.SignTransaction,
176
+ });
177
+ });
178
+ }
179
+ signArbitrary(_signer, _data) {
180
+ return __awaiter(this, void 0, void 0, function* () {
181
+ throw new exceptions_1.WalletException(new Error('This wallet does not support signArbitrary'), {
182
+ code: exceptions_1.UnspecifiedErrorCode,
183
+ type: exceptions_1.ErrorType.WalletError,
184
+ contextModule: wallet_base_1.WalletAction.SignTransaction,
185
+ });
186
+ });
187
+ }
188
+ getEthereumChainId() {
189
+ return __awaiter(this, void 0, void 0, function* () {
190
+ throw new exceptions_1.CosmosWalletException(new Error('getEthereumChainId is not supported on Magic wallet'), {
191
+ code: exceptions_1.UnspecifiedErrorCode,
192
+ context: wallet_base_1.WalletAction.GetChainId,
193
+ });
194
+ });
195
+ }
196
+ getEthereumTransactionReceipt(_txHash) {
197
+ return __awaiter(this, void 0, void 0, function* () {
198
+ throw new exceptions_1.CosmosWalletException(new Error('getEthereumTransactionReceipt is not supported on Cosmostation'), {
199
+ code: exceptions_1.UnspecifiedErrorCode,
200
+ type: exceptions_1.ErrorType.WalletError,
201
+ context: wallet_base_1.WalletAction.GetEthereumTransactionReceipt,
202
+ });
203
+ });
204
+ }
205
+ // eslint-disable-next-line class-methods-use-this
206
+ getPubKey() {
207
+ return __awaiter(this, void 0, void 0, function* () {
208
+ throw new exceptions_1.WalletException(new Error('You can only fetch PubKey from Cosmos native wallets'));
209
+ });
210
+ }
211
+ pollUserLoggedInState() {
212
+ return __awaiter(this, arguments, void 0, function* (timeout = 60 * 1000) {
213
+ const POLL_INTERVAL = 3 * 1000;
214
+ for (let i = 0; i <= timeout / POLL_INTERVAL; i += 1) {
215
+ try {
216
+ const result = yield this.magicWallet.user.isLoggedIn();
217
+ if (result) {
218
+ return result;
219
+ }
220
+ }
221
+ catch (e) {
222
+ // We throw only if the transaction failed on chain
223
+ if (e instanceof exceptions_1.TransactionException) {
224
+ throw e;
225
+ }
226
+ }
227
+ yield new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL));
228
+ }
229
+ // Transaction was not included in the block in the desired timeout
230
+ throw new exceptions_1.WalletException(new Error(`User did not verify sign in - timeout of ${timeout}ms`), {
231
+ context: 'Wallet',
232
+ contextModule: 'Magic-Wallet-pollUserLoggedInState',
233
+ });
234
+ });
235
+ }
236
+ }
237
+ exports.Magic = Magic;
238
+ //# sourceMappingURL=strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategy.js","sourceRoot":"","sources":["../../../src/strategy/strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA2C;AAC3C,0DAMkC;AAClC,yCAAgD;AAChD,kDAK8B;AAC9B,8CAAkD;AAClD,8CAAmD;AAEnD,4DAWmC;AAMnC,MAAa,KAAM,SAAQ,kCAAoB;IAK7C,YAAY,IAAsB;;QAChC,IAAI,CAAC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X,OAAO,MAAM,CAAA;oBACf,CAAC;gBACH,CAAC;gBAAC,OAAO,CAAU,EAAE,CAAC;oBACpB,mDAAmD;oBACnD,IAAI,CAAC,YAAY,iCAAoB,EAAE,CAAC;wBACtC,MAAM,CAAC,CAAA;oBACT,CAAC;gBACH,CAAC;gBAED,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAA;YACpE,CAAC;YAED,mEAAmE;YACnE,MAAM,IAAI,4BAAe,CACvB,IAAI,KAAK,CAAC,4CAA4C,OAAO,IAAI,CAAC,EAClE;gBACE,OAAO,EAAE,QAAQ;gBACjB,aAAa,EAAE,oCAAoC;aACpD,CACF,CAAA;QACH,CAAC;KAAA;CACF;AA1SD,sBA0SC"}
@@ -0,0 +1,2 @@
1
+ export { Magic as MagicStrategy } from './strategy/strategy';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,aAAa,EAAE,MAAM,qBAAqB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export { Magic as MagicStrategy } from './strategy/strategy';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,aAAa,EAAE,MAAM,qBAAqB,CAAA"}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,47 @@
1
+ import { TxRaw, DirectSignResponse, AminoSignResponse } from '@injectivelabs/sdk-ts';
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
+ }
7
+ export declare class Magic extends BaseConcreteStrategy implements ConcreteWalletStrategy {
8
+ provider: BrowserEip1993Provider | undefined;
9
+ metadata?: MagicMetadata;
10
+ private magicWallet;
11
+ constructor(args: MagicConnectArgs);
12
+ getWalletDeviceType(): Promise<WalletDeviceType>;
13
+ enable({ email, provider, }: {
14
+ email?: string;
15
+ provider?: MagicProvider;
16
+ }): Promise<boolean>;
17
+ connectViaEmail(email?: string): Promise<string | null>;
18
+ connectViaOauth(provider: MagicProvider): Promise<any>;
19
+ disconnect(): Promise<void>;
20
+ getAddresses({ provider, }: {
21
+ provider: MagicProvider;
22
+ }): Promise<string[]>;
23
+ getSessionOrConfirm(address: AccountAddress): Promise<string>;
24
+ sendEthereumTransaction(_transaction: unknown, _options: {
25
+ address: AccountAddress;
26
+ ethereumChainId: EthereumChainId;
27
+ }): Promise<string>;
28
+ sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<any>;
29
+ signEip712TypedData(eip712json: string, _address: AccountAddress): Promise<string>;
30
+ signCosmosTransaction(_transaction: {
31
+ txRaw: TxRaw;
32
+ accountNumber: number;
33
+ chainId: string;
34
+ address: string;
35
+ }): Promise<DirectSignResponse>;
36
+ signAminoCosmosTransaction(_transaction: {
37
+ address: string;
38
+ signDoc: StdSignDoc;
39
+ }): Promise<AminoSignResponse>;
40
+ signArbitrary(_signer: AccountAddress, _data: string | Uint8Array): Promise<string>;
41
+ getEthereumChainId(): Promise<string>;
42
+ getEthereumTransactionReceipt(_txHash: string): Promise<string>;
43
+ getPubKey(): Promise<string>;
44
+ private pollUserLoggedInState;
45
+ }
46
+ export {};
47
+ //# sourceMappingURL=strategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../../../src/strategy/strategy.ts"],"names":[],"mappings":"AASA,OAAO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AW,EAAE,KAAK,EAClB,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,GAAG,CAAC;IAyBT,mBAAmB,CACvB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,cAAc,GACvB,OAAO,CAAC,MAAM,CAAC;IASZ,qBAAqB,CAAC,YAAY,EAAE;QACxC,KAAK,EAAE,KAAK,CAAA;QACZ,aAAa,EAAE,MAAM,CAAA;QACrB,OAAO,EAAE,MAAM,CAAA;QACf,OAAO,EAAE,MAAM,CAAA;KAChB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAWzB,0BAA0B,CAAC,YAAY,EAAE;QAC7C,OAAO,EAAE,MAAM,CAAA;QACf,OAAO,EAAE,UAAU,CAAA;KACpB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAWxB,aAAa,CACjB,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,MAAM,GAAG,UAAU,GACzB,OAAO,CAAC,MAAM,CAAC;IAWZ,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAUrC,6BAA6B,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAc/D,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;YAMpB,qBAAqB;CA6BpC"}
@@ -0,0 +1,193 @@
1
+ /* eslint-disable class-methods-use-this */
2
+ import { ErrorType, WalletException, UnspecifiedErrorCode, TransactionException, CosmosWalletException, } from '@injectivelabs/exceptions';
3
+ import { Magic as MagicWallet } from 'magic-sdk';
4
+ import { TxGrpcApi, } from '@injectivelabs/sdk-ts';
5
+ import { OAuthExtension } from '@magic-ext/oauth2';
6
+ import { CosmosExtension } from '@magic-ext/cosmos';
7
+ import { WalletAction, MagicProvider, WalletDeviceType, BaseConcreteStrategy, } from '@injectivelabs/wallet-base';
8
+ export class Magic extends BaseConcreteStrategy {
9
+ provider;
10
+ metadata;
11
+ 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
+ async getWalletDeviceType() {
32
+ return Promise.resolve(WalletDeviceType.Browser);
33
+ }
34
+ async enable({ email, provider, }) {
35
+ if (!provider) {
36
+ return Promise.resolve(true);
37
+ }
38
+ try {
39
+ if (provider === MagicProvider.Email) {
40
+ await this.connectViaEmail(email);
41
+ }
42
+ else {
43
+ await this.connectViaOauth(provider);
44
+ }
45
+ await this.pollUserLoggedInState();
46
+ return Promise.resolve(true);
47
+ }
48
+ catch (e) {
49
+ throw new WalletException(new Error(e.message), {
50
+ code: UnspecifiedErrorCode,
51
+ type: ErrorType.WalletError,
52
+ contextModule: WalletAction.GetAccounts,
53
+ });
54
+ }
55
+ }
56
+ async connectViaEmail(email) {
57
+ if (!email) {
58
+ throw new WalletException(new Error('You have to pass the email for using Magic wallet'));
59
+ }
60
+ return this.magicWallet.auth.loginWithMagicLink({ email });
61
+ }
62
+ async connectViaOauth(provider) {
63
+ return this.magicWallet.oauth2.loginWithRedirect({
64
+ provider: provider,
65
+ redirectURI: window.location.origin,
66
+ });
67
+ }
68
+ async disconnect() {
69
+ const isUserLoggedIn = await this.magicWallet.user.isLoggedIn();
70
+ if (!isUserLoggedIn) {
71
+ return;
72
+ }
73
+ await this.magicWallet.user.logout();
74
+ }
75
+ async getAddresses({ provider, }) {
76
+ if (!provider) {
77
+ try {
78
+ await this.magicWallet.oauth2.getRedirectResult();
79
+ }
80
+ catch {
81
+ // fail silently
82
+ }
83
+ }
84
+ try {
85
+ const { publicAddress } = await this.magicWallet.user.getInfo();
86
+ if (!publicAddress?.startsWith('inj')) {
87
+ const address = await this.magicWallet.cosmos.changeAddress('inj');
88
+ return [address || ''];
89
+ }
90
+ return [publicAddress || ''];
91
+ }
92
+ catch (e) {
93
+ throw new WalletException(new Error(e.message), {
94
+ code: UnspecifiedErrorCode,
95
+ type: ErrorType.WalletError,
96
+ contextModule: WalletAction.GetAccounts,
97
+ });
98
+ }
99
+ }
100
+ // eslint-disable-next-line class-methods-use-this
101
+ async getSessionOrConfirm(address) {
102
+ return Promise.resolve(`0x${Buffer.from(`Confirmation for ${address} at time: ${Date.now()}`).toString('hex')}`);
103
+ }
104
+ async sendEthereumTransaction(_transaction, _options) {
105
+ throw new CosmosWalletException(new Error('sendEthereumTransaction is not supported. Leap only supports sending cosmos transactions'), {
106
+ code: UnspecifiedErrorCode,
107
+ context: WalletAction.SendEthereumTransaction,
108
+ });
109
+ }
110
+ async sendTransaction(transaction, options) {
111
+ const { endpoints, txTimeout } = options;
112
+ if (!endpoints) {
113
+ throw new WalletException(new Error('You have to pass endpoints.grpc within the options for using Magic wallet'));
114
+ }
115
+ const txApi = new TxGrpcApi(endpoints.grpc);
116
+ const response = await txApi.broadcast(transaction, { txTimeout });
117
+ if (response.code !== 0) {
118
+ throw new TransactionException(new Error(response.rawLog), {
119
+ code: UnspecifiedErrorCode,
120
+ contextCode: response.code,
121
+ contextModule: response.codespace,
122
+ });
123
+ }
124
+ return response;
125
+ }
126
+ async signEip712TypedData(eip712json, _address) {
127
+ const signature = await this.magicWallet.cosmos.signTypedData(eip712json);
128
+ return `0x${signature}`;
129
+ }
130
+ // eslint-disable-next-line class-methods-use-this
131
+ async signCosmosTransaction(_transaction) {
132
+ throw new WalletException(new Error('This wallet does not support signing Cosmos transactions'), {
133
+ code: UnspecifiedErrorCode,
134
+ type: ErrorType.WalletError,
135
+ contextModule: WalletAction.SignTransaction,
136
+ });
137
+ }
138
+ async signAminoCosmosTransaction(_transaction) {
139
+ throw new WalletException(new Error('This wallet does not support signAminoCosmosTransaction'), {
140
+ code: UnspecifiedErrorCode,
141
+ type: ErrorType.WalletError,
142
+ contextModule: WalletAction.SignTransaction,
143
+ });
144
+ }
145
+ async signArbitrary(_signer, _data) {
146
+ throw new WalletException(new Error('This wallet does not support signArbitrary'), {
147
+ code: UnspecifiedErrorCode,
148
+ type: ErrorType.WalletError,
149
+ contextModule: WalletAction.SignTransaction,
150
+ });
151
+ }
152
+ async getEthereumChainId() {
153
+ throw new CosmosWalletException(new Error('getEthereumChainId is not supported on Magic wallet'), {
154
+ code: UnspecifiedErrorCode,
155
+ context: WalletAction.GetChainId,
156
+ });
157
+ }
158
+ async getEthereumTransactionReceipt(_txHash) {
159
+ throw new CosmosWalletException(new Error('getEthereumTransactionReceipt is not supported on Cosmostation'), {
160
+ code: UnspecifiedErrorCode,
161
+ type: ErrorType.WalletError,
162
+ context: WalletAction.GetEthereumTransactionReceipt,
163
+ });
164
+ }
165
+ // eslint-disable-next-line class-methods-use-this
166
+ async getPubKey() {
167
+ throw new WalletException(new Error('You can only fetch PubKey from Cosmos native wallets'));
168
+ }
169
+ async pollUserLoggedInState(timeout = 60 * 1000) {
170
+ const POLL_INTERVAL = 3 * 1000;
171
+ for (let i = 0; i <= timeout / POLL_INTERVAL; i += 1) {
172
+ try {
173
+ const result = await this.magicWallet.user.isLoggedIn();
174
+ if (result) {
175
+ return result;
176
+ }
177
+ }
178
+ catch (e) {
179
+ // We throw only if the transaction failed on chain
180
+ if (e instanceof TransactionException) {
181
+ throw e;
182
+ }
183
+ }
184
+ await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL));
185
+ }
186
+ // Transaction was not included in the block in the desired timeout
187
+ throw new WalletException(new Error(`User did not verify sign in - timeout of ${timeout}ms`), {
188
+ context: 'Wallet',
189
+ contextModule: 'Magic-Wallet-pollUserLoggedInState',
190
+ });
191
+ }
192
+ }
193
+ //# sourceMappingURL=strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strateg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C3B,OAAO,EAAE,YAAY,CAAC,6BAA6B;SACpD,CACF,CAAA;IACH,CAAC;IAED,kDAAkD;IAClD,KAAK,CAAC,SAAS;QACb,MAAM,IAAI,eAAe,CACvB,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAClE,CAAA;IACH,CAAC;IAEO,KAAK,CAAC,qBAAqB,CAAC,OAAO,GAAG,EAAE,GAAG,IAAI;QACrD,MAAM,aAAa,GAAG,CAAC,GAAG,IAAI,CAAA;QAE9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,OAAO,GAAG,aAAa,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YACrD,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,EAAE,CAAA;gBAEvD,IAAI,MAAM,EAAE,CAAC;oBACX,OAAO,MAAM,CAAA;gBACf,CAAC;YACH,CAAC;YAAC,OAAO,CAAU,EAAE,CAAC;gBACpB,mDAAmD;gBACnD,IAAI,CAAC,YAAY,oBAAoB,EAAE,CAAC;oBACtC,MAAM,CAAC,CAAA;gBACT,CAAC;YACH,CAAC;YAED,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAA;QACpE,CAAC;QAED,mEAAmE;QACnE,MAAM,IAAI,eAAe,CACvB,IAAI,KAAK,CAAC,4CAA4C,OAAO,IAAI,CAAC,EAClE;YACE,OAAO,EAAE,QAAQ;YACjB,aAAa,EAAE,oCAAoC;SACpD,CACF,CAAA;IACH,CAAC;CACF"}
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@injectivelabs/wallet-magic",
3
+ "description": "Magic wallet strategy for use with @injectivelabs/wallet-core.",
4
+ "version": "0.0.2",
5
+ "sideEffects": false,
6
+ "author": {
7
+ "name": "InjectiveLabs",
8
+ "email": "admin@injectivelabs.org"
9
+ },
10
+ "license": "Apache-2.0",
11
+ "types": "dist/cjs/index.d.ts",
12
+ "main": "dist/cjs/index.js",
13
+ "module": "dist/esm/index.js",
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "_moduleAliases": {
18
+ "~wallet-magic": "dist"
19
+ },
20
+ "scripts": {
21
+ "postinstall": "link-module-alias",
22
+ "build:cjs": "BUILD_MODE=cjs tsc --build tsconfig.build.json",
23
+ "build:esm": "BUILD_MODE=esm tsc --build tsconfig.build.esm.json",
24
+ "build": "yarn build:esm && yarn build:cjs && yarn build:post && link-module-alias",
25
+ "build:watch": "tsc --build -w tsconfig.build.json && tsc -w --build tsconfig.build.esm.json && yarn build:post && link-module-alias",
26
+ "build:post": "shx cp ../../../etc/stub/package.json.stub dist/cjs/package.json && shx cp ../../../etc/stub/package.esm.json.stub dist/esm/package.json",
27
+ "clean": "tsc --build tsconfig.build.json --clean && tsc --build tsconfig.build.esm.json --clean && shx rm -rf coverage *.log junit.xml dist && jest --clearCache && shx mkdir -p dist",
28
+ "test": "jest",
29
+ "test:watch": "jest --watch",
30
+ "test:ci": "jest --coverage --ci --reporters='jest-junit'",
31
+ "coverage": "jest --coverage",
32
+ "coverage:show": "live-server coverage",
33
+ "dev": "ts-node -r tsconfig-paths/register src/index.ts",
34
+ "start": "node dist/index.js"
35
+ },
36
+ "dependencies": {
37
+ "@injectivelabs/exceptions": "^1.14.14",
38
+ "@injectivelabs/sdk-ts": "^1.14.15",
39
+ "@injectivelabs/ts-types": "^1.14.14",
40
+ "@injectivelabs/utils": "^1.14.14",
41
+ "@injectivelabs/wallet-base": "^0.0.2",
42
+ "@magic-ext/cosmos": "23.9.1",
43
+ "@magic-ext/oauth2": "9.9.0",
44
+ "magic-sdk": "28.9.0"
45
+ },
46
+ "gitHead": "6442ae377bbfb3459d2fb3a44c650630a5b7f445",
47
+ "typedoc": {
48
+ "entryPoint": "./src/index.ts",
49
+ "readmeFile": "./README.md",
50
+ "displayName": "wallet-magic API Documentation"
51
+ },
52
+ "resolutions": {
53
+ "**/libsodium": "npm:@bangjelkoski/noop",
54
+ "**/libsodium-wrappers": "npm:@bangjelkoski/noop"
55
+ }
56
+ }