@injectivelabs/wallet-magic 1.16.36 → 1.16.38-alpha.0
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/dist/cjs/index.cjs +201 -0
- package/dist/cjs/index.d.cts +50 -0
- package/dist/cjs/package.json +2 -2
- package/dist/esm/index.d.ts +50 -1
- package/dist/esm/index.js +201 -1
- package/dist/esm/package.json +2 -2
- package/package.json +32 -37
- package/dist/cjs/index.d.ts +0 -1
- package/dist/cjs/index.js +0 -5
- package/dist/cjs/strategy/strategy.d.ts +0 -42
- package/dist/cjs/strategy/strategy.js +0 -199
- package/dist/esm/strategy/strategy.d.ts +0 -42
- package/dist/esm/strategy/strategy.js +0 -195
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
let magic_sdk = require("magic-sdk");
|
|
2
|
+
let __magic_ext_oauth2 = require("@magic-ext/oauth2");
|
|
3
|
+
let __magic_ext_cosmos = require("@magic-ext/cosmos");
|
|
4
|
+
let __injectivelabs_sdk_ts = require("@injectivelabs/sdk-ts");
|
|
5
|
+
let __injectivelabs_wallet_base = require("@injectivelabs/wallet-base");
|
|
6
|
+
let __injectivelabs_exceptions = require("@injectivelabs/exceptions");
|
|
7
|
+
|
|
8
|
+
//#region \0@oxc-project+runtime@0.98.0/helpers/typeof.js
|
|
9
|
+
function _typeof(o) {
|
|
10
|
+
"@babel/helpers - typeof";
|
|
11
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
12
|
+
return typeof o$1;
|
|
13
|
+
} : function(o$1) {
|
|
14
|
+
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
15
|
+
}, _typeof(o);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region \0@oxc-project+runtime@0.98.0/helpers/toPrimitive.js
|
|
20
|
+
function toPrimitive(t, r) {
|
|
21
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
22
|
+
var e = t[Symbol.toPrimitive];
|
|
23
|
+
if (void 0 !== e) {
|
|
24
|
+
var i = e.call(t, r || "default");
|
|
25
|
+
if ("object" != _typeof(i)) return i;
|
|
26
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
27
|
+
}
|
|
28
|
+
return ("string" === r ? String : Number)(t);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region \0@oxc-project+runtime@0.98.0/helpers/toPropertyKey.js
|
|
33
|
+
function toPropertyKey(t) {
|
|
34
|
+
var i = toPrimitive(t, "string");
|
|
35
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region \0@oxc-project+runtime@0.98.0/helpers/defineProperty.js
|
|
40
|
+
function _defineProperty(e, r, t) {
|
|
41
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
42
|
+
value: t,
|
|
43
|
+
enumerable: !0,
|
|
44
|
+
configurable: !0,
|
|
45
|
+
writable: !0
|
|
46
|
+
}) : e[r] = t, e;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/strategy/strategy.ts
|
|
51
|
+
var Magic = class extends __injectivelabs_wallet_base.BaseConcreteStrategy {
|
|
52
|
+
constructor(..._args) {
|
|
53
|
+
super(..._args);
|
|
54
|
+
_defineProperty(this, "provider", void 0);
|
|
55
|
+
_defineProperty(this, "magicWallet", void 0);
|
|
56
|
+
}
|
|
57
|
+
async getWalletDeviceType() {
|
|
58
|
+
return Promise.resolve(__injectivelabs_wallet_base.WalletDeviceType.Browser);
|
|
59
|
+
}
|
|
60
|
+
async enable({ email, provider }) {
|
|
61
|
+
if (!provider) return Promise.resolve(true);
|
|
62
|
+
try {
|
|
63
|
+
if (provider === __injectivelabs_wallet_base.MagicProvider.Email) await this.connectViaEmail(email);
|
|
64
|
+
else await this.connectViaOauth(provider);
|
|
65
|
+
await this.pollUserLoggedInState();
|
|
66
|
+
return Promise.resolve(true);
|
|
67
|
+
} catch (e) {
|
|
68
|
+
throw new __injectivelabs_exceptions.WalletException(new Error(e.message), {
|
|
69
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
70
|
+
type: __injectivelabs_exceptions.ErrorType.WalletError,
|
|
71
|
+
contextModule: __injectivelabs_wallet_base.WalletAction.GetAccounts
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async connectViaEmail(email) {
|
|
76
|
+
const magicWallet = await this.getMagicWallet();
|
|
77
|
+
if (!email) throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("You have to pass the email for using Magic wallet"));
|
|
78
|
+
return magicWallet.auth.loginWithMagicLink({ email });
|
|
79
|
+
}
|
|
80
|
+
async connectViaOauth(provider) {
|
|
81
|
+
return (await this.getMagicWallet()).oauth2.loginWithRedirect({
|
|
82
|
+
provider,
|
|
83
|
+
redirectURI: window.location.origin
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
async disconnect() {
|
|
87
|
+
const magicWallet = await this.getMagicWallet();
|
|
88
|
+
if (!await magicWallet.user.isLoggedIn()) return;
|
|
89
|
+
await magicWallet.user.logout();
|
|
90
|
+
}
|
|
91
|
+
async getAddresses({ provider }) {
|
|
92
|
+
const magicWallet = await this.getMagicWallet();
|
|
93
|
+
if (!provider) try {
|
|
94
|
+
await magicWallet.oauth2.getRedirectResult();
|
|
95
|
+
} catch (_unused) {}
|
|
96
|
+
try {
|
|
97
|
+
const { publicAddress } = await magicWallet.user.getInfo();
|
|
98
|
+
if (!(publicAddress === null || publicAddress === void 0 ? void 0 : publicAddress.startsWith("inj"))) return [await magicWallet.cosmos.changeAddress("inj") || ""];
|
|
99
|
+
return [publicAddress || ""];
|
|
100
|
+
} catch (e) {
|
|
101
|
+
throw new __injectivelabs_exceptions.WalletException(new Error(e.message), {
|
|
102
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
103
|
+
type: __injectivelabs_exceptions.ErrorType.WalletError,
|
|
104
|
+
contextModule: __injectivelabs_wallet_base.WalletAction.GetAccounts
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async getSessionOrConfirm(address) {
|
|
109
|
+
return Promise.resolve(`0x${(0, __injectivelabs_sdk_ts.uint8ArrayToHex)((0, __injectivelabs_sdk_ts.stringToUint8Array)(`Confirmation for ${address} at time: ${Date.now()}`))}`);
|
|
110
|
+
}
|
|
111
|
+
async sendEvmTransaction(_transaction, _options) {
|
|
112
|
+
throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("sendEvmTransaction is not supported. Leap only supports sending cosmos transactions"), {
|
|
113
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
114
|
+
context: __injectivelabs_wallet_base.WalletAction.SendEvmTransaction
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
async sendTransaction(transaction, options) {
|
|
118
|
+
const { endpoints, txTimeout } = options;
|
|
119
|
+
if (!endpoints) throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("You have to pass endpoints.grpc within the options for using Magic wallet"));
|
|
120
|
+
const response = await new __injectivelabs_sdk_ts.TxGrpcApi(endpoints.grpc).broadcast(transaction, { txTimeout });
|
|
121
|
+
if (response.code !== 0) throw new __injectivelabs_exceptions.TransactionException(new Error(response.rawLog), {
|
|
122
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
123
|
+
contextCode: response.code,
|
|
124
|
+
contextModule: response.codespace
|
|
125
|
+
});
|
|
126
|
+
return response;
|
|
127
|
+
}
|
|
128
|
+
async signEip712TypedData(eip712json, _address) {
|
|
129
|
+
return `0x${await (await this.getMagicWallet()).cosmos.signTypedData(eip712json)}`;
|
|
130
|
+
}
|
|
131
|
+
async signCosmosTransaction(_transaction) {
|
|
132
|
+
throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("This wallet does not support signing Cosmos transactions"), {
|
|
133
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
134
|
+
type: __injectivelabs_exceptions.ErrorType.WalletError,
|
|
135
|
+
contextModule: __injectivelabs_wallet_base.WalletAction.SignTransaction
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
async signAminoCosmosTransaction(_transaction) {
|
|
139
|
+
throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("This wallet does not support signAminoCosmosTransaction"), {
|
|
140
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
141
|
+
type: __injectivelabs_exceptions.ErrorType.WalletError,
|
|
142
|
+
contextModule: __injectivelabs_wallet_base.WalletAction.SignTransaction
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
async signArbitrary(_signer, _data) {
|
|
146
|
+
throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("This wallet does not support signArbitrary"), {
|
|
147
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
148
|
+
type: __injectivelabs_exceptions.ErrorType.WalletError,
|
|
149
|
+
contextModule: __injectivelabs_wallet_base.WalletAction.SignTransaction
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
async getEthereumChainId() {
|
|
153
|
+
throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("getEthereumChainId is not supported on Magic wallet"), {
|
|
154
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
155
|
+
context: __injectivelabs_wallet_base.WalletAction.GetChainId
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
async getEvmTransactionReceipt(_txHash) {
|
|
159
|
+
throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("getEvmTransactionReceipt is not supported on Cosmostation"), {
|
|
160
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
161
|
+
type: __injectivelabs_exceptions.ErrorType.WalletError,
|
|
162
|
+
context: __injectivelabs_wallet_base.WalletAction.GetEvmTransactionReceipt
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
async getPubKey() {
|
|
166
|
+
throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("You can only fetch PubKey from Cosmos native wallets"));
|
|
167
|
+
}
|
|
168
|
+
async pollUserLoggedInState(timeout = 60 * 1e3) {
|
|
169
|
+
const magicWallet = await this.getMagicWallet();
|
|
170
|
+
const POLL_INTERVAL = 3 * 1e3;
|
|
171
|
+
for (let i = 0; i <= timeout / POLL_INTERVAL; i += 1) {
|
|
172
|
+
try {
|
|
173
|
+
const result = await magicWallet.user.isLoggedIn();
|
|
174
|
+
if (result) return result;
|
|
175
|
+
} catch (e) {
|
|
176
|
+
if (e instanceof __injectivelabs_exceptions.TransactionException) throw e;
|
|
177
|
+
}
|
|
178
|
+
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL));
|
|
179
|
+
}
|
|
180
|
+
throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error(`User did not verify sign in - timeout of ${timeout}ms`), {
|
|
181
|
+
context: "Wallet",
|
|
182
|
+
contextModule: "Magic-Wallet-pollUserLoggedInState"
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
async getMagicWallet() {
|
|
186
|
+
const { metadata } = this;
|
|
187
|
+
if (!this.magicWallet) {
|
|
188
|
+
var _metadata$magic, _metadata$magic2;
|
|
189
|
+
if (!(metadata === null || metadata === void 0 || (_metadata$magic = metadata.magic) === null || _metadata$magic === void 0 ? void 0 : _metadata$magic.apiKey)) throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("You have to pass the apiKey within metadata to use Magic wallet"));
|
|
190
|
+
if (!(metadata === null || metadata === void 0 || (_metadata$magic2 = metadata.magic) === null || _metadata$magic2 === void 0 ? void 0 : _metadata$magic2.rpcEndpoint)) throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("You have to pass the rpc url endpoint within metadata to use Magic wallet"));
|
|
191
|
+
this.magicWallet = new magic_sdk.Magic(metadata.magic.apiKey, { extensions: [new __magic_ext_oauth2.OAuthExtension(), new __magic_ext_cosmos.CosmosExtension({
|
|
192
|
+
rpcUrl: metadata.magic.rpcEndpoint,
|
|
193
|
+
chain: "inj"
|
|
194
|
+
})] });
|
|
195
|
+
}
|
|
196
|
+
return this.magicWallet;
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
//#endregion
|
|
201
|
+
exports.MagicStrategy = Magic;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { BaseConcreteStrategy, BrowserEip1993Provider, ConcreteWalletStrategy, MagicProvider, SendTransactionOptions, StdSignDoc, WalletDeviceType } from "@injectivelabs/wallet-base";
|
|
2
|
+
import { AccountAddress, EvmChainId } from "@injectivelabs/ts-types";
|
|
3
|
+
import { AminoSignResponse, DirectSignResponse, TxRaw } from "@injectivelabs/sdk-ts";
|
|
4
|
+
|
|
5
|
+
//#region src/strategy/strategy.d.ts
|
|
6
|
+
declare class Magic extends BaseConcreteStrategy implements ConcreteWalletStrategy {
|
|
7
|
+
provider: BrowserEip1993Provider | undefined;
|
|
8
|
+
private magicWallet;
|
|
9
|
+
getWalletDeviceType(): Promise<WalletDeviceType>;
|
|
10
|
+
enable({
|
|
11
|
+
email,
|
|
12
|
+
provider
|
|
13
|
+
}: {
|
|
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({
|
|
21
|
+
provider
|
|
22
|
+
}: {
|
|
23
|
+
provider: MagicProvider;
|
|
24
|
+
}): Promise<string[]>;
|
|
25
|
+
getSessionOrConfirm(address: AccountAddress): Promise<string>;
|
|
26
|
+
sendEvmTransaction(_transaction: unknown, _options: {
|
|
27
|
+
address: AccountAddress;
|
|
28
|
+
evmChainId: EvmChainId;
|
|
29
|
+
}): Promise<string>;
|
|
30
|
+
sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<any>;
|
|
31
|
+
signEip712TypedData(eip712json: string, _address: AccountAddress): Promise<string>;
|
|
32
|
+
signCosmosTransaction(_transaction: {
|
|
33
|
+
txRaw: TxRaw;
|
|
34
|
+
accountNumber: number;
|
|
35
|
+
chainId: string;
|
|
36
|
+
address: string;
|
|
37
|
+
}): Promise<DirectSignResponse>;
|
|
38
|
+
signAminoCosmosTransaction(_transaction: {
|
|
39
|
+
address: string;
|
|
40
|
+
signDoc: StdSignDoc;
|
|
41
|
+
}): Promise<AminoSignResponse>;
|
|
42
|
+
signArbitrary(_signer: AccountAddress, _data: string | Uint8Array): Promise<string>;
|
|
43
|
+
getEthereumChainId(): Promise<string>;
|
|
44
|
+
getEvmTransactionReceipt(_txHash: string): Promise<string>;
|
|
45
|
+
getPubKey(): Promise<string>;
|
|
46
|
+
private pollUserLoggedInState;
|
|
47
|
+
private getMagicWallet;
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { Magic as MagicStrategy };
|
package/dist/cjs/package.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
}
|
|
2
|
+
"type": "commonjs"
|
|
3
|
+
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1 +1,50 @@
|
|
|
1
|
-
|
|
1
|
+
import { AminoSignResponse, DirectSignResponse, TxRaw } from "@injectivelabs/sdk-ts";
|
|
2
|
+
import { BaseConcreteStrategy, BrowserEip1993Provider, ConcreteWalletStrategy, MagicProvider, SendTransactionOptions, StdSignDoc, WalletDeviceType } from "@injectivelabs/wallet-base";
|
|
3
|
+
import { AccountAddress, EvmChainId } from "@injectivelabs/ts-types";
|
|
4
|
+
|
|
5
|
+
//#region src/strategy/strategy.d.ts
|
|
6
|
+
declare class Magic extends BaseConcreteStrategy implements ConcreteWalletStrategy {
|
|
7
|
+
provider: BrowserEip1993Provider | undefined;
|
|
8
|
+
private magicWallet;
|
|
9
|
+
getWalletDeviceType(): Promise<WalletDeviceType>;
|
|
10
|
+
enable({
|
|
11
|
+
email,
|
|
12
|
+
provider
|
|
13
|
+
}: {
|
|
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({
|
|
21
|
+
provider
|
|
22
|
+
}: {
|
|
23
|
+
provider: MagicProvider;
|
|
24
|
+
}): Promise<string[]>;
|
|
25
|
+
getSessionOrConfirm(address: AccountAddress): Promise<string>;
|
|
26
|
+
sendEvmTransaction(_transaction: unknown, _options: {
|
|
27
|
+
address: AccountAddress;
|
|
28
|
+
evmChainId: EvmChainId;
|
|
29
|
+
}): Promise<string>;
|
|
30
|
+
sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<any>;
|
|
31
|
+
signEip712TypedData(eip712json: string, _address: AccountAddress): Promise<string>;
|
|
32
|
+
signCosmosTransaction(_transaction: {
|
|
33
|
+
txRaw: TxRaw;
|
|
34
|
+
accountNumber: number;
|
|
35
|
+
chainId: string;
|
|
36
|
+
address: string;
|
|
37
|
+
}): Promise<DirectSignResponse>;
|
|
38
|
+
signAminoCosmosTransaction(_transaction: {
|
|
39
|
+
address: string;
|
|
40
|
+
signDoc: StdSignDoc;
|
|
41
|
+
}): Promise<AminoSignResponse>;
|
|
42
|
+
signArbitrary(_signer: AccountAddress, _data: string | Uint8Array): Promise<string>;
|
|
43
|
+
getEthereumChainId(): Promise<string>;
|
|
44
|
+
getEvmTransactionReceipt(_txHash: string): Promise<string>;
|
|
45
|
+
getPubKey(): Promise<string>;
|
|
46
|
+
private pollUserLoggedInState;
|
|
47
|
+
private getMagicWallet;
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { Magic as MagicStrategy };
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1,201 @@
|
|
|
1
|
-
|
|
1
|
+
import { Magic as Magic$1 } from "magic-sdk";
|
|
2
|
+
import { OAuthExtension } from "@magic-ext/oauth2";
|
|
3
|
+
import { CosmosExtension } from "@magic-ext/cosmos";
|
|
4
|
+
import { TxGrpcApi, stringToUint8Array, uint8ArrayToHex } from "@injectivelabs/sdk-ts";
|
|
5
|
+
import { BaseConcreteStrategy, MagicProvider, WalletAction, WalletDeviceType } from "@injectivelabs/wallet-base";
|
|
6
|
+
import { CosmosWalletException, ErrorType, TransactionException, UnspecifiedErrorCode, WalletException } from "@injectivelabs/exceptions";
|
|
7
|
+
|
|
8
|
+
//#region \0@oxc-project+runtime@0.98.0/helpers/typeof.js
|
|
9
|
+
function _typeof(o) {
|
|
10
|
+
"@babel/helpers - typeof";
|
|
11
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
12
|
+
return typeof o$1;
|
|
13
|
+
} : function(o$1) {
|
|
14
|
+
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
15
|
+
}, _typeof(o);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region \0@oxc-project+runtime@0.98.0/helpers/toPrimitive.js
|
|
20
|
+
function toPrimitive(t, r) {
|
|
21
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
22
|
+
var e = t[Symbol.toPrimitive];
|
|
23
|
+
if (void 0 !== e) {
|
|
24
|
+
var i = e.call(t, r || "default");
|
|
25
|
+
if ("object" != _typeof(i)) return i;
|
|
26
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
27
|
+
}
|
|
28
|
+
return ("string" === r ? String : Number)(t);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region \0@oxc-project+runtime@0.98.0/helpers/toPropertyKey.js
|
|
33
|
+
function toPropertyKey(t) {
|
|
34
|
+
var i = toPrimitive(t, "string");
|
|
35
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region \0@oxc-project+runtime@0.98.0/helpers/defineProperty.js
|
|
40
|
+
function _defineProperty(e, r, t) {
|
|
41
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
42
|
+
value: t,
|
|
43
|
+
enumerable: !0,
|
|
44
|
+
configurable: !0,
|
|
45
|
+
writable: !0
|
|
46
|
+
}) : e[r] = t, e;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/strategy/strategy.ts
|
|
51
|
+
var Magic = class extends BaseConcreteStrategy {
|
|
52
|
+
constructor(..._args) {
|
|
53
|
+
super(..._args);
|
|
54
|
+
_defineProperty(this, "provider", void 0);
|
|
55
|
+
_defineProperty(this, "magicWallet", void 0);
|
|
56
|
+
}
|
|
57
|
+
async getWalletDeviceType() {
|
|
58
|
+
return Promise.resolve(WalletDeviceType.Browser);
|
|
59
|
+
}
|
|
60
|
+
async enable({ email, provider }) {
|
|
61
|
+
if (!provider) return Promise.resolve(true);
|
|
62
|
+
try {
|
|
63
|
+
if (provider === MagicProvider.Email) await this.connectViaEmail(email);
|
|
64
|
+
else await this.connectViaOauth(provider);
|
|
65
|
+
await this.pollUserLoggedInState();
|
|
66
|
+
return Promise.resolve(true);
|
|
67
|
+
} catch (e) {
|
|
68
|
+
throw new WalletException(new Error(e.message), {
|
|
69
|
+
code: UnspecifiedErrorCode,
|
|
70
|
+
type: ErrorType.WalletError,
|
|
71
|
+
contextModule: WalletAction.GetAccounts
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async connectViaEmail(email) {
|
|
76
|
+
const magicWallet = await this.getMagicWallet();
|
|
77
|
+
if (!email) throw new WalletException(/* @__PURE__ */ new Error("You have to pass the email for using Magic wallet"));
|
|
78
|
+
return magicWallet.auth.loginWithMagicLink({ email });
|
|
79
|
+
}
|
|
80
|
+
async connectViaOauth(provider) {
|
|
81
|
+
return (await this.getMagicWallet()).oauth2.loginWithRedirect({
|
|
82
|
+
provider,
|
|
83
|
+
redirectURI: window.location.origin
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
async disconnect() {
|
|
87
|
+
const magicWallet = await this.getMagicWallet();
|
|
88
|
+
if (!await magicWallet.user.isLoggedIn()) return;
|
|
89
|
+
await magicWallet.user.logout();
|
|
90
|
+
}
|
|
91
|
+
async getAddresses({ provider }) {
|
|
92
|
+
const magicWallet = await this.getMagicWallet();
|
|
93
|
+
if (!provider) try {
|
|
94
|
+
await magicWallet.oauth2.getRedirectResult();
|
|
95
|
+
} catch (_unused) {}
|
|
96
|
+
try {
|
|
97
|
+
const { publicAddress } = await magicWallet.user.getInfo();
|
|
98
|
+
if (!(publicAddress === null || publicAddress === void 0 ? void 0 : publicAddress.startsWith("inj"))) return [await magicWallet.cosmos.changeAddress("inj") || ""];
|
|
99
|
+
return [publicAddress || ""];
|
|
100
|
+
} catch (e) {
|
|
101
|
+
throw new WalletException(new Error(e.message), {
|
|
102
|
+
code: UnspecifiedErrorCode,
|
|
103
|
+
type: ErrorType.WalletError,
|
|
104
|
+
contextModule: WalletAction.GetAccounts
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async getSessionOrConfirm(address) {
|
|
109
|
+
return Promise.resolve(`0x${uint8ArrayToHex(stringToUint8Array(`Confirmation for ${address} at time: ${Date.now()}`))}`);
|
|
110
|
+
}
|
|
111
|
+
async sendEvmTransaction(_transaction, _options) {
|
|
112
|
+
throw new CosmosWalletException(/* @__PURE__ */ new Error("sendEvmTransaction is not supported. Leap only supports sending cosmos transactions"), {
|
|
113
|
+
code: UnspecifiedErrorCode,
|
|
114
|
+
context: WalletAction.SendEvmTransaction
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
async sendTransaction(transaction, options) {
|
|
118
|
+
const { endpoints, txTimeout } = options;
|
|
119
|
+
if (!endpoints) throw new WalletException(/* @__PURE__ */ new Error("You have to pass endpoints.grpc within the options for using Magic wallet"));
|
|
120
|
+
const response = await new TxGrpcApi(endpoints.grpc).broadcast(transaction, { txTimeout });
|
|
121
|
+
if (response.code !== 0) throw new TransactionException(new Error(response.rawLog), {
|
|
122
|
+
code: UnspecifiedErrorCode,
|
|
123
|
+
contextCode: response.code,
|
|
124
|
+
contextModule: response.codespace
|
|
125
|
+
});
|
|
126
|
+
return response;
|
|
127
|
+
}
|
|
128
|
+
async signEip712TypedData(eip712json, _address) {
|
|
129
|
+
return `0x${await (await this.getMagicWallet()).cosmos.signTypedData(eip712json)}`;
|
|
130
|
+
}
|
|
131
|
+
async signCosmosTransaction(_transaction) {
|
|
132
|
+
throw new WalletException(/* @__PURE__ */ 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(/* @__PURE__ */ 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(/* @__PURE__ */ 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(/* @__PURE__ */ new Error("getEthereumChainId is not supported on Magic wallet"), {
|
|
154
|
+
code: UnspecifiedErrorCode,
|
|
155
|
+
context: WalletAction.GetChainId
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
async getEvmTransactionReceipt(_txHash) {
|
|
159
|
+
throw new CosmosWalletException(/* @__PURE__ */ new Error("getEvmTransactionReceipt is not supported on Cosmostation"), {
|
|
160
|
+
code: UnspecifiedErrorCode,
|
|
161
|
+
type: ErrorType.WalletError,
|
|
162
|
+
context: WalletAction.GetEvmTransactionReceipt
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
async getPubKey() {
|
|
166
|
+
throw new WalletException(/* @__PURE__ */ new Error("You can only fetch PubKey from Cosmos native wallets"));
|
|
167
|
+
}
|
|
168
|
+
async pollUserLoggedInState(timeout = 60 * 1e3) {
|
|
169
|
+
const magicWallet = await this.getMagicWallet();
|
|
170
|
+
const POLL_INTERVAL = 3 * 1e3;
|
|
171
|
+
for (let i = 0; i <= timeout / POLL_INTERVAL; i += 1) {
|
|
172
|
+
try {
|
|
173
|
+
const result = await magicWallet.user.isLoggedIn();
|
|
174
|
+
if (result) return result;
|
|
175
|
+
} catch (e) {
|
|
176
|
+
if (e instanceof TransactionException) throw e;
|
|
177
|
+
}
|
|
178
|
+
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL));
|
|
179
|
+
}
|
|
180
|
+
throw new WalletException(/* @__PURE__ */ new Error(`User did not verify sign in - timeout of ${timeout}ms`), {
|
|
181
|
+
context: "Wallet",
|
|
182
|
+
contextModule: "Magic-Wallet-pollUserLoggedInState"
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
async getMagicWallet() {
|
|
186
|
+
const { metadata } = this;
|
|
187
|
+
if (!this.magicWallet) {
|
|
188
|
+
var _metadata$magic, _metadata$magic2;
|
|
189
|
+
if (!(metadata === null || metadata === void 0 || (_metadata$magic = metadata.magic) === null || _metadata$magic === void 0 ? void 0 : _metadata$magic.apiKey)) throw new WalletException(/* @__PURE__ */ new Error("You have to pass the apiKey within metadata to use Magic wallet"));
|
|
190
|
+
if (!(metadata === null || metadata === void 0 || (_metadata$magic2 = metadata.magic) === null || _metadata$magic2 === void 0 ? void 0 : _metadata$magic2.rpcEndpoint)) throw new WalletException(/* @__PURE__ */ new Error("You have to pass the rpc url endpoint within metadata to use Magic wallet"));
|
|
191
|
+
this.magicWallet = new Magic$1(metadata.magic.apiKey, { extensions: [new OAuthExtension(), new CosmosExtension({
|
|
192
|
+
rpcUrl: metadata.magic.rpcEndpoint,
|
|
193
|
+
chain: "inj"
|
|
194
|
+
})] });
|
|
195
|
+
}
|
|
196
|
+
return this.magicWallet;
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
//#endregion
|
|
201
|
+
export { Magic as MagicStrategy };
|
package/dist/esm/package.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
}
|
|
2
|
+
"type": "module"
|
|
3
|
+
}
|
package/package.json
CHANGED
|
@@ -1,23 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/wallet-magic",
|
|
3
|
+
"version": "1.16.38-alpha.0",
|
|
3
4
|
"description": "Magic wallet strategy for use with @injectivelabs/wallet-core.",
|
|
4
|
-
"
|
|
5
|
-
"sideEffects": false,
|
|
6
|
-
"type": "module",
|
|
5
|
+
"license": "Apache-2.0",
|
|
7
6
|
"author": {
|
|
8
7
|
"name": "InjectiveLabs",
|
|
9
8
|
"email": "admin@injectivelabs.org"
|
|
10
9
|
},
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"main": "dist/cjs/index.js",
|
|
14
|
-
"module": "dist/esm/index.js",
|
|
15
|
-
"files": [
|
|
16
|
-
"dist"
|
|
17
|
-
],
|
|
18
|
-
"_moduleAliases": {
|
|
19
|
-
"~wallet-magic": "dist"
|
|
20
|
-
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"sideEffects": false,
|
|
21
12
|
"exports": {
|
|
22
13
|
".": {
|
|
23
14
|
"react-native": {
|
|
@@ -40,38 +31,42 @@
|
|
|
40
31
|
}
|
|
41
32
|
}
|
|
42
33
|
},
|
|
34
|
+
"main": "dist/cjs/index.js",
|
|
35
|
+
"module": "dist/esm/index.js",
|
|
36
|
+
"types": "dist/cjs/index.d.ts",
|
|
37
|
+
"files": [
|
|
38
|
+
"dist"
|
|
39
|
+
],
|
|
43
40
|
"scripts": {
|
|
44
|
-
"build": "pnpm
|
|
45
|
-
"build:
|
|
46
|
-
"build:
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"test": "
|
|
51
|
-
"test:
|
|
52
|
-
"
|
|
53
|
-
"coverage": "jest --coverage",
|
|
41
|
+
"build": "pnpm type-check && tsdown",
|
|
42
|
+
"build:fast": "tsdown",
|
|
43
|
+
"build:watch": "tsdown --watch",
|
|
44
|
+
"clean": "shx rm -rf dist coverage *.log junit.xml && shx mkdir -p dist",
|
|
45
|
+
"type-check": "tsc --noEmit",
|
|
46
|
+
"test": "vitest",
|
|
47
|
+
"test:watch": "vitest --watch",
|
|
48
|
+
"test:ci": "vitest run --coverage --reporter=verbose",
|
|
49
|
+
"coverage": "vitest run --coverage",
|
|
54
50
|
"coverage:show": "live-server coverage",
|
|
55
51
|
"dev": "ts-node -r tsconfig-paths/register src/index.ts",
|
|
56
|
-
"start": "node dist/index.js"
|
|
52
|
+
"start": "node dist/index.js",
|
|
53
|
+
"lint": "eslint . --ext .ts,.js"
|
|
57
54
|
},
|
|
58
55
|
"dependencies": {
|
|
59
|
-
"@injectivelabs/exceptions": "1.16.
|
|
60
|
-
"@injectivelabs/sdk-ts": "1.16.
|
|
61
|
-
"@injectivelabs/ts-types": "1.16.
|
|
62
|
-
"@injectivelabs/utils": "1.16.
|
|
63
|
-
"@injectivelabs/wallet-base": "1.16.
|
|
56
|
+
"@injectivelabs/exceptions": "1.16.38-alpha.0",
|
|
57
|
+
"@injectivelabs/sdk-ts": "1.16.38-alpha.0",
|
|
58
|
+
"@injectivelabs/ts-types": "1.16.38-alpha.0",
|
|
59
|
+
"@injectivelabs/utils": "1.16.38-alpha.0",
|
|
60
|
+
"@injectivelabs/wallet-base": "1.16.38-alpha.0",
|
|
64
61
|
"@magic-ext/cosmos": "23.9.1",
|
|
65
62
|
"@magic-ext/oauth2": "9.9.0",
|
|
66
63
|
"magic-sdk": "29.1.0"
|
|
67
64
|
},
|
|
68
|
-
"
|
|
69
|
-
"
|
|
65
|
+
"publishConfig": {
|
|
66
|
+
"access": "public"
|
|
67
|
+
},
|
|
68
|
+
"_moduleAliases": {
|
|
69
|
+
"~wallet-magic": "dist"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
72
|
-
"typedoc": {
|
|
73
|
-
"entryPoint": "./src/index.ts",
|
|
74
|
-
"readmeFile": "./README.md",
|
|
75
|
-
"displayName": "wallet-magic API Documentation"
|
|
76
|
-
}
|
|
71
|
+
"gitHead": "35da21add71ed443fad349d811cf9458043baee7"
|
|
77
72
|
}
|
package/dist/cjs/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { Magic as MagicStrategy } from './strategy/strategy.js';
|
package/dist/cjs/index.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MagicStrategy = void 0;
|
|
4
|
-
var strategy_js_1 = require("./strategy/strategy.js");
|
|
5
|
-
Object.defineProperty(exports, "MagicStrategy", { enumerable: true, get: function () { return strategy_js_1.Magic; } });
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { MagicProvider, WalletDeviceType, BaseConcreteStrategy } from '@injectivelabs/wallet-base';
|
|
2
|
-
import type { AccountAddress, EvmChainId } from '@injectivelabs/ts-types';
|
|
3
|
-
import type { TxRaw, DirectSignResponse, AminoSignResponse } from '@injectivelabs/sdk-ts';
|
|
4
|
-
import type { StdSignDoc, BrowserEip1993Provider, ConcreteWalletStrategy, SendTransactionOptions } from '@injectivelabs/wallet-base';
|
|
5
|
-
export declare class Magic extends BaseConcreteStrategy implements ConcreteWalletStrategy {
|
|
6
|
-
provider: BrowserEip1993Provider | undefined;
|
|
7
|
-
private magicWallet;
|
|
8
|
-
getWalletDeviceType(): Promise<WalletDeviceType>;
|
|
9
|
-
enable({ email, provider, }: {
|
|
10
|
-
email?: string;
|
|
11
|
-
provider?: MagicProvider;
|
|
12
|
-
}): Promise<boolean>;
|
|
13
|
-
connectViaEmail(email?: string): Promise<string | null>;
|
|
14
|
-
connectViaOauth(provider: MagicProvider): Promise<any>;
|
|
15
|
-
disconnect(): Promise<void>;
|
|
16
|
-
getAddresses({ provider, }: {
|
|
17
|
-
provider: MagicProvider;
|
|
18
|
-
}): Promise<string[]>;
|
|
19
|
-
getSessionOrConfirm(address: AccountAddress): Promise<string>;
|
|
20
|
-
sendEvmTransaction(_transaction: unknown, _options: {
|
|
21
|
-
address: AccountAddress;
|
|
22
|
-
evmChainId: EvmChainId;
|
|
23
|
-
}): Promise<string>;
|
|
24
|
-
sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<any>;
|
|
25
|
-
signEip712TypedData(eip712json: string, _address: AccountAddress): Promise<string>;
|
|
26
|
-
signCosmosTransaction(_transaction: {
|
|
27
|
-
txRaw: TxRaw;
|
|
28
|
-
accountNumber: number;
|
|
29
|
-
chainId: string;
|
|
30
|
-
address: string;
|
|
31
|
-
}): Promise<DirectSignResponse>;
|
|
32
|
-
signAminoCosmosTransaction(_transaction: {
|
|
33
|
-
address: string;
|
|
34
|
-
signDoc: StdSignDoc;
|
|
35
|
-
}): Promise<AminoSignResponse>;
|
|
36
|
-
signArbitrary(_signer: AccountAddress, _data: string | Uint8Array): Promise<string>;
|
|
37
|
-
getEthereumChainId(): Promise<string>;
|
|
38
|
-
getEvmTransactionReceipt(_txHash: string): Promise<string>;
|
|
39
|
-
getPubKey(): Promise<string>;
|
|
40
|
-
private pollUserLoggedInState;
|
|
41
|
-
private getMagicWallet;
|
|
42
|
-
}
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Magic = void 0;
|
|
4
|
-
const magic_sdk_1 = require("magic-sdk");
|
|
5
|
-
const sdk_ts_1 = require("@injectivelabs/sdk-ts");
|
|
6
|
-
const oauth2_1 = require("@magic-ext/oauth2");
|
|
7
|
-
const cosmos_1 = require("@magic-ext/cosmos");
|
|
8
|
-
const wallet_base_1 = require("@injectivelabs/wallet-base");
|
|
9
|
-
const exceptions_1 = require("@injectivelabs/exceptions");
|
|
10
|
-
class Magic extends wallet_base_1.BaseConcreteStrategy {
|
|
11
|
-
provider;
|
|
12
|
-
magicWallet;
|
|
13
|
-
async getWalletDeviceType() {
|
|
14
|
-
return Promise.resolve(wallet_base_1.WalletDeviceType.Browser);
|
|
15
|
-
}
|
|
16
|
-
async enable({ email, provider, }) {
|
|
17
|
-
if (!provider) {
|
|
18
|
-
return Promise.resolve(true);
|
|
19
|
-
}
|
|
20
|
-
try {
|
|
21
|
-
if (provider === wallet_base_1.MagicProvider.Email) {
|
|
22
|
-
await this.connectViaEmail(email);
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
await this.connectViaOauth(provider);
|
|
26
|
-
}
|
|
27
|
-
await this.pollUserLoggedInState();
|
|
28
|
-
return Promise.resolve(true);
|
|
29
|
-
}
|
|
30
|
-
catch (e) {
|
|
31
|
-
throw new exceptions_1.WalletException(new Error(e.message), {
|
|
32
|
-
code: exceptions_1.UnspecifiedErrorCode,
|
|
33
|
-
type: exceptions_1.ErrorType.WalletError,
|
|
34
|
-
contextModule: wallet_base_1.WalletAction.GetAccounts,
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
async connectViaEmail(email) {
|
|
39
|
-
const magicWallet = await this.getMagicWallet();
|
|
40
|
-
if (!email) {
|
|
41
|
-
throw new exceptions_1.WalletException(new Error('You have to pass the email for using Magic wallet'));
|
|
42
|
-
}
|
|
43
|
-
return magicWallet.auth.loginWithMagicLink({ email });
|
|
44
|
-
}
|
|
45
|
-
async connectViaOauth(provider) {
|
|
46
|
-
const magicWallet = await this.getMagicWallet();
|
|
47
|
-
return magicWallet.oauth2.loginWithRedirect({
|
|
48
|
-
provider: provider,
|
|
49
|
-
redirectURI: window.location.origin,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
async disconnect() {
|
|
53
|
-
const magicWallet = await this.getMagicWallet();
|
|
54
|
-
const isUserLoggedIn = await magicWallet.user.isLoggedIn();
|
|
55
|
-
if (!isUserLoggedIn) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
await magicWallet.user.logout();
|
|
59
|
-
}
|
|
60
|
-
async getAddresses({ provider, }) {
|
|
61
|
-
const magicWallet = await this.getMagicWallet();
|
|
62
|
-
if (!provider) {
|
|
63
|
-
try {
|
|
64
|
-
await magicWallet.oauth2.getRedirectResult();
|
|
65
|
-
}
|
|
66
|
-
catch {
|
|
67
|
-
// fail silently
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
try {
|
|
71
|
-
const { publicAddress } = await magicWallet.user.getInfo();
|
|
72
|
-
if (!publicAddress?.startsWith('inj')) {
|
|
73
|
-
const address = await magicWallet.cosmos.changeAddress('inj');
|
|
74
|
-
return [address || ''];
|
|
75
|
-
}
|
|
76
|
-
return [publicAddress || ''];
|
|
77
|
-
}
|
|
78
|
-
catch (e) {
|
|
79
|
-
throw new exceptions_1.WalletException(new Error(e.message), {
|
|
80
|
-
code: exceptions_1.UnspecifiedErrorCode,
|
|
81
|
-
type: exceptions_1.ErrorType.WalletError,
|
|
82
|
-
contextModule: wallet_base_1.WalletAction.GetAccounts,
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
async getSessionOrConfirm(address) {
|
|
87
|
-
return Promise.resolve(`0x${Buffer.from(`Confirmation for ${address} at time: ${Date.now()}`).toString('hex')}`);
|
|
88
|
-
}
|
|
89
|
-
async sendEvmTransaction(_transaction, _options) {
|
|
90
|
-
throw new exceptions_1.CosmosWalletException(new Error('sendEvmTransaction is not supported. Leap only supports sending cosmos transactions'), {
|
|
91
|
-
code: exceptions_1.UnspecifiedErrorCode,
|
|
92
|
-
context: wallet_base_1.WalletAction.SendEvmTransaction,
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
async sendTransaction(transaction, options) {
|
|
96
|
-
const { endpoints, txTimeout } = options;
|
|
97
|
-
if (!endpoints) {
|
|
98
|
-
throw new exceptions_1.WalletException(new Error('You have to pass endpoints.grpc within the options for using Magic wallet'));
|
|
99
|
-
}
|
|
100
|
-
const txApi = new sdk_ts_1.TxGrpcApi(endpoints.grpc);
|
|
101
|
-
const response = await txApi.broadcast(transaction, { txTimeout });
|
|
102
|
-
if (response.code !== 0) {
|
|
103
|
-
throw new exceptions_1.TransactionException(new Error(response.rawLog), {
|
|
104
|
-
code: exceptions_1.UnspecifiedErrorCode,
|
|
105
|
-
contextCode: response.code,
|
|
106
|
-
contextModule: response.codespace,
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
return response;
|
|
110
|
-
}
|
|
111
|
-
async signEip712TypedData(eip712json, _address) {
|
|
112
|
-
const magicWallet = await this.getMagicWallet();
|
|
113
|
-
const signature = await magicWallet.cosmos.signTypedData(eip712json);
|
|
114
|
-
return `0x${signature}`;
|
|
115
|
-
}
|
|
116
|
-
async signCosmosTransaction(_transaction) {
|
|
117
|
-
throw new exceptions_1.WalletException(new Error('This wallet does not support signing Cosmos transactions'), {
|
|
118
|
-
code: exceptions_1.UnspecifiedErrorCode,
|
|
119
|
-
type: exceptions_1.ErrorType.WalletError,
|
|
120
|
-
contextModule: wallet_base_1.WalletAction.SignTransaction,
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
async signAminoCosmosTransaction(_transaction) {
|
|
124
|
-
throw new exceptions_1.WalletException(new Error('This wallet does not support signAminoCosmosTransaction'), {
|
|
125
|
-
code: exceptions_1.UnspecifiedErrorCode,
|
|
126
|
-
type: exceptions_1.ErrorType.WalletError,
|
|
127
|
-
contextModule: wallet_base_1.WalletAction.SignTransaction,
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
async signArbitrary(_signer, _data) {
|
|
131
|
-
throw new exceptions_1.WalletException(new Error('This wallet does not support signArbitrary'), {
|
|
132
|
-
code: exceptions_1.UnspecifiedErrorCode,
|
|
133
|
-
type: exceptions_1.ErrorType.WalletError,
|
|
134
|
-
contextModule: wallet_base_1.WalletAction.SignTransaction,
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
async getEthereumChainId() {
|
|
138
|
-
throw new exceptions_1.CosmosWalletException(new Error('getEthereumChainId is not supported on Magic wallet'), {
|
|
139
|
-
code: exceptions_1.UnspecifiedErrorCode,
|
|
140
|
-
context: wallet_base_1.WalletAction.GetChainId,
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
async getEvmTransactionReceipt(_txHash) {
|
|
144
|
-
throw new exceptions_1.CosmosWalletException(new Error('getEvmTransactionReceipt is not supported on Cosmostation'), {
|
|
145
|
-
code: exceptions_1.UnspecifiedErrorCode,
|
|
146
|
-
type: exceptions_1.ErrorType.WalletError,
|
|
147
|
-
context: wallet_base_1.WalletAction.GetEvmTransactionReceipt,
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
async getPubKey() {
|
|
151
|
-
throw new exceptions_1.WalletException(new Error('You can only fetch PubKey from Cosmos native wallets'));
|
|
152
|
-
}
|
|
153
|
-
async pollUserLoggedInState(timeout = 60 * 1000) {
|
|
154
|
-
const magicWallet = await this.getMagicWallet();
|
|
155
|
-
const POLL_INTERVAL = 3 * 1000;
|
|
156
|
-
for (let i = 0; i <= timeout / POLL_INTERVAL; i += 1) {
|
|
157
|
-
try {
|
|
158
|
-
const result = await magicWallet.user.isLoggedIn();
|
|
159
|
-
if (result) {
|
|
160
|
-
return result;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
catch (e) {
|
|
164
|
-
// We throw only if the transaction failed on chain
|
|
165
|
-
if (e instanceof exceptions_1.TransactionException) {
|
|
166
|
-
throw e;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL));
|
|
170
|
-
}
|
|
171
|
-
// Transaction was not included in the block in the desired timeout
|
|
172
|
-
throw new exceptions_1.WalletException(new Error(`User did not verify sign in - timeout of ${timeout}ms`), {
|
|
173
|
-
context: 'Wallet',
|
|
174
|
-
contextModule: 'Magic-Wallet-pollUserLoggedInState',
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
async getMagicWallet() {
|
|
178
|
-
const { metadata } = this;
|
|
179
|
-
if (!this.magicWallet) {
|
|
180
|
-
if (!metadata?.magic?.apiKey) {
|
|
181
|
-
throw new exceptions_1.WalletException(new Error('You have to pass the apiKey within metadata to use Magic wallet'));
|
|
182
|
-
}
|
|
183
|
-
if (!metadata?.magic?.rpcEndpoint) {
|
|
184
|
-
throw new exceptions_1.WalletException(new Error('You have to pass the rpc url endpoint within metadata to use Magic wallet'));
|
|
185
|
-
}
|
|
186
|
-
this.magicWallet = new magic_sdk_1.Magic(metadata.magic.apiKey, {
|
|
187
|
-
extensions: [
|
|
188
|
-
new oauth2_1.OAuthExtension(),
|
|
189
|
-
new cosmos_1.CosmosExtension({
|
|
190
|
-
rpcUrl: metadata.magic.rpcEndpoint,
|
|
191
|
-
chain: 'inj',
|
|
192
|
-
}),
|
|
193
|
-
],
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
return this.magicWallet;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
exports.Magic = Magic;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { MagicProvider, WalletDeviceType, BaseConcreteStrategy } from '@injectivelabs/wallet-base';
|
|
2
|
-
import type { AccountAddress, EvmChainId } from '@injectivelabs/ts-types';
|
|
3
|
-
import type { TxRaw, DirectSignResponse, AminoSignResponse } from '@injectivelabs/sdk-ts';
|
|
4
|
-
import type { StdSignDoc, BrowserEip1993Provider, ConcreteWalletStrategy, SendTransactionOptions } from '@injectivelabs/wallet-base';
|
|
5
|
-
export declare class Magic extends BaseConcreteStrategy implements ConcreteWalletStrategy {
|
|
6
|
-
provider: BrowserEip1993Provider | undefined;
|
|
7
|
-
private magicWallet;
|
|
8
|
-
getWalletDeviceType(): Promise<WalletDeviceType>;
|
|
9
|
-
enable({ email, provider, }: {
|
|
10
|
-
email?: string;
|
|
11
|
-
provider?: MagicProvider;
|
|
12
|
-
}): Promise<boolean>;
|
|
13
|
-
connectViaEmail(email?: string): Promise<string | null>;
|
|
14
|
-
connectViaOauth(provider: MagicProvider): Promise<any>;
|
|
15
|
-
disconnect(): Promise<void>;
|
|
16
|
-
getAddresses({ provider, }: {
|
|
17
|
-
provider: MagicProvider;
|
|
18
|
-
}): Promise<string[]>;
|
|
19
|
-
getSessionOrConfirm(address: AccountAddress): Promise<string>;
|
|
20
|
-
sendEvmTransaction(_transaction: unknown, _options: {
|
|
21
|
-
address: AccountAddress;
|
|
22
|
-
evmChainId: EvmChainId;
|
|
23
|
-
}): Promise<string>;
|
|
24
|
-
sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<any>;
|
|
25
|
-
signEip712TypedData(eip712json: string, _address: AccountAddress): Promise<string>;
|
|
26
|
-
signCosmosTransaction(_transaction: {
|
|
27
|
-
txRaw: TxRaw;
|
|
28
|
-
accountNumber: number;
|
|
29
|
-
chainId: string;
|
|
30
|
-
address: string;
|
|
31
|
-
}): Promise<DirectSignResponse>;
|
|
32
|
-
signAminoCosmosTransaction(_transaction: {
|
|
33
|
-
address: string;
|
|
34
|
-
signDoc: StdSignDoc;
|
|
35
|
-
}): Promise<AminoSignResponse>;
|
|
36
|
-
signArbitrary(_signer: AccountAddress, _data: string | Uint8Array): Promise<string>;
|
|
37
|
-
getEthereumChainId(): Promise<string>;
|
|
38
|
-
getEvmTransactionReceipt(_txHash: string): Promise<string>;
|
|
39
|
-
getPubKey(): Promise<string>;
|
|
40
|
-
private pollUserLoggedInState;
|
|
41
|
-
private getMagicWallet;
|
|
42
|
-
}
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import { Magic as MagicWallet } from 'magic-sdk';
|
|
2
|
-
import { TxGrpcApi } from '@injectivelabs/sdk-ts';
|
|
3
|
-
import { OAuthExtension } from '@magic-ext/oauth2';
|
|
4
|
-
import { CosmosExtension } from '@magic-ext/cosmos';
|
|
5
|
-
import { WalletAction, MagicProvider, WalletDeviceType, BaseConcreteStrategy, } from '@injectivelabs/wallet-base';
|
|
6
|
-
import { ErrorType, WalletException, UnspecifiedErrorCode, TransactionException, CosmosWalletException, } from '@injectivelabs/exceptions';
|
|
7
|
-
export class Magic extends BaseConcreteStrategy {
|
|
8
|
-
provider;
|
|
9
|
-
magicWallet;
|
|
10
|
-
async getWalletDeviceType() {
|
|
11
|
-
return Promise.resolve(WalletDeviceType.Browser);
|
|
12
|
-
}
|
|
13
|
-
async enable({ email, provider, }) {
|
|
14
|
-
if (!provider) {
|
|
15
|
-
return Promise.resolve(true);
|
|
16
|
-
}
|
|
17
|
-
try {
|
|
18
|
-
if (provider === MagicProvider.Email) {
|
|
19
|
-
await this.connectViaEmail(email);
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
await this.connectViaOauth(provider);
|
|
23
|
-
}
|
|
24
|
-
await this.pollUserLoggedInState();
|
|
25
|
-
return Promise.resolve(true);
|
|
26
|
-
}
|
|
27
|
-
catch (e) {
|
|
28
|
-
throw new WalletException(new Error(e.message), {
|
|
29
|
-
code: UnspecifiedErrorCode,
|
|
30
|
-
type: ErrorType.WalletError,
|
|
31
|
-
contextModule: WalletAction.GetAccounts,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
async connectViaEmail(email) {
|
|
36
|
-
const magicWallet = await this.getMagicWallet();
|
|
37
|
-
if (!email) {
|
|
38
|
-
throw new WalletException(new Error('You have to pass the email for using Magic wallet'));
|
|
39
|
-
}
|
|
40
|
-
return magicWallet.auth.loginWithMagicLink({ email });
|
|
41
|
-
}
|
|
42
|
-
async connectViaOauth(provider) {
|
|
43
|
-
const magicWallet = await this.getMagicWallet();
|
|
44
|
-
return magicWallet.oauth2.loginWithRedirect({
|
|
45
|
-
provider: provider,
|
|
46
|
-
redirectURI: window.location.origin,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
async disconnect() {
|
|
50
|
-
const magicWallet = await this.getMagicWallet();
|
|
51
|
-
const isUserLoggedIn = await magicWallet.user.isLoggedIn();
|
|
52
|
-
if (!isUserLoggedIn) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
await magicWallet.user.logout();
|
|
56
|
-
}
|
|
57
|
-
async getAddresses({ provider, }) {
|
|
58
|
-
const magicWallet = await this.getMagicWallet();
|
|
59
|
-
if (!provider) {
|
|
60
|
-
try {
|
|
61
|
-
await magicWallet.oauth2.getRedirectResult();
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
// fail silently
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
try {
|
|
68
|
-
const { publicAddress } = await magicWallet.user.getInfo();
|
|
69
|
-
if (!publicAddress?.startsWith('inj')) {
|
|
70
|
-
const address = await magicWallet.cosmos.changeAddress('inj');
|
|
71
|
-
return [address || ''];
|
|
72
|
-
}
|
|
73
|
-
return [publicAddress || ''];
|
|
74
|
-
}
|
|
75
|
-
catch (e) {
|
|
76
|
-
throw new WalletException(new Error(e.message), {
|
|
77
|
-
code: UnspecifiedErrorCode,
|
|
78
|
-
type: ErrorType.WalletError,
|
|
79
|
-
contextModule: WalletAction.GetAccounts,
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
async getSessionOrConfirm(address) {
|
|
84
|
-
return Promise.resolve(`0x${Buffer.from(`Confirmation for ${address} at time: ${Date.now()}`).toString('hex')}`);
|
|
85
|
-
}
|
|
86
|
-
async sendEvmTransaction(_transaction, _options) {
|
|
87
|
-
throw new CosmosWalletException(new Error('sendEvmTransaction is not supported. Leap only supports sending cosmos transactions'), {
|
|
88
|
-
code: UnspecifiedErrorCode,
|
|
89
|
-
context: WalletAction.SendEvmTransaction,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
async sendTransaction(transaction, options) {
|
|
93
|
-
const { endpoints, txTimeout } = options;
|
|
94
|
-
if (!endpoints) {
|
|
95
|
-
throw new WalletException(new Error('You have to pass endpoints.grpc within the options for using Magic wallet'));
|
|
96
|
-
}
|
|
97
|
-
const txApi = new TxGrpcApi(endpoints.grpc);
|
|
98
|
-
const response = await txApi.broadcast(transaction, { txTimeout });
|
|
99
|
-
if (response.code !== 0) {
|
|
100
|
-
throw new TransactionException(new Error(response.rawLog), {
|
|
101
|
-
code: UnspecifiedErrorCode,
|
|
102
|
-
contextCode: response.code,
|
|
103
|
-
contextModule: response.codespace,
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
return response;
|
|
107
|
-
}
|
|
108
|
-
async signEip712TypedData(eip712json, _address) {
|
|
109
|
-
const magicWallet = await this.getMagicWallet();
|
|
110
|
-
const signature = await magicWallet.cosmos.signTypedData(eip712json);
|
|
111
|
-
return `0x${signature}`;
|
|
112
|
-
}
|
|
113
|
-
async signCosmosTransaction(_transaction) {
|
|
114
|
-
throw new WalletException(new Error('This wallet does not support signing Cosmos transactions'), {
|
|
115
|
-
code: UnspecifiedErrorCode,
|
|
116
|
-
type: ErrorType.WalletError,
|
|
117
|
-
contextModule: WalletAction.SignTransaction,
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
async signAminoCosmosTransaction(_transaction) {
|
|
121
|
-
throw new WalletException(new Error('This wallet does not support signAminoCosmosTransaction'), {
|
|
122
|
-
code: UnspecifiedErrorCode,
|
|
123
|
-
type: ErrorType.WalletError,
|
|
124
|
-
contextModule: WalletAction.SignTransaction,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
async signArbitrary(_signer, _data) {
|
|
128
|
-
throw new WalletException(new Error('This wallet does not support signArbitrary'), {
|
|
129
|
-
code: UnspecifiedErrorCode,
|
|
130
|
-
type: ErrorType.WalletError,
|
|
131
|
-
contextModule: WalletAction.SignTransaction,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
async getEthereumChainId() {
|
|
135
|
-
throw new CosmosWalletException(new Error('getEthereumChainId is not supported on Magic wallet'), {
|
|
136
|
-
code: UnspecifiedErrorCode,
|
|
137
|
-
context: WalletAction.GetChainId,
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
async getEvmTransactionReceipt(_txHash) {
|
|
141
|
-
throw new CosmosWalletException(new Error('getEvmTransactionReceipt is not supported on Cosmostation'), {
|
|
142
|
-
code: UnspecifiedErrorCode,
|
|
143
|
-
type: ErrorType.WalletError,
|
|
144
|
-
context: WalletAction.GetEvmTransactionReceipt,
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
async getPubKey() {
|
|
148
|
-
throw new WalletException(new Error('You can only fetch PubKey from Cosmos native wallets'));
|
|
149
|
-
}
|
|
150
|
-
async pollUserLoggedInState(timeout = 60 * 1000) {
|
|
151
|
-
const magicWallet = await this.getMagicWallet();
|
|
152
|
-
const POLL_INTERVAL = 3 * 1000;
|
|
153
|
-
for (let i = 0; i <= timeout / POLL_INTERVAL; i += 1) {
|
|
154
|
-
try {
|
|
155
|
-
const result = await magicWallet.user.isLoggedIn();
|
|
156
|
-
if (result) {
|
|
157
|
-
return result;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
catch (e) {
|
|
161
|
-
// We throw only if the transaction failed on chain
|
|
162
|
-
if (e instanceof TransactionException) {
|
|
163
|
-
throw e;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL));
|
|
167
|
-
}
|
|
168
|
-
// Transaction was not included in the block in the desired timeout
|
|
169
|
-
throw new WalletException(new Error(`User did not verify sign in - timeout of ${timeout}ms`), {
|
|
170
|
-
context: 'Wallet',
|
|
171
|
-
contextModule: 'Magic-Wallet-pollUserLoggedInState',
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
async getMagicWallet() {
|
|
175
|
-
const { metadata } = this;
|
|
176
|
-
if (!this.magicWallet) {
|
|
177
|
-
if (!metadata?.magic?.apiKey) {
|
|
178
|
-
throw new WalletException(new Error('You have to pass the apiKey within metadata to use Magic wallet'));
|
|
179
|
-
}
|
|
180
|
-
if (!metadata?.magic?.rpcEndpoint) {
|
|
181
|
-
throw new WalletException(new Error('You have to pass the rpc url endpoint within metadata to use Magic wallet'));
|
|
182
|
-
}
|
|
183
|
-
this.magicWallet = new MagicWallet(metadata.magic.apiKey, {
|
|
184
|
-
extensions: [
|
|
185
|
-
new OAuthExtension(),
|
|
186
|
-
new CosmosExtension({
|
|
187
|
-
rpcUrl: metadata.magic.rpcEndpoint,
|
|
188
|
-
chain: 'inj',
|
|
189
|
-
}),
|
|
190
|
-
],
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
return this.magicWallet;
|
|
194
|
-
}
|
|
195
|
-
}
|