@openocean.finance/wallet 0.4.8 → 0.4.11

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.
@@ -0,0 +1,16 @@
1
+ import { EnumChains, EnumWalletName, EnumWalletType } from "../types";
2
+ import BaseWallet from "./BaseWallet";
3
+ import Web3 from "web3";
4
+ declare class BitKeepWallet extends BaseWallet {
5
+ name: EnumWalletName;
6
+ icon: any;
7
+ supportChains: EnumChains[];
8
+ type: EnumWalletType;
9
+ sdk: Web3 | null;
10
+ /**
11
+ * connect metamask and get wallet address
12
+ * @param chainId specific chainId,throw error when not match
13
+ */
14
+ requestConnect(chainId?: number): Promise<string>;
15
+ }
16
+ export default BitKeepWallet;
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ var __importDefault = (this && this.__importDefault) || function (mod) {
54
+ return (mod && mod.__esModule) ? mod : { "default": mod };
55
+ };
56
+ Object.defineProperty(exports, "__esModule", { value: true });
57
+ /**
58
+ * @name BitKeepWallet
59
+ * @author openocean
60
+ * @date 2021/4/21
61
+ * @desc
62
+ */
63
+ // @ts-ignore
64
+ var bitkeep_svg_1 = __importDefault(require("../assets/bitkeep.svg"));
65
+ var types_1 = require("../types");
66
+ var BaseWallet_1 = __importDefault(require("./BaseWallet"));
67
+ var web3_1 = __importDefault(require("web3"));
68
+ var BitKeepWallet = /** @class */ (function (_super) {
69
+ __extends(BitKeepWallet, _super);
70
+ function BitKeepWallet() {
71
+ var _this = _super !== null && _super.apply(this, arguments) || this;
72
+ _this.name = types_1.EnumWalletName.BitKeepWallet;
73
+ _this.icon = bitkeep_svg_1.default;
74
+ _this.supportChains = [
75
+ types_1.EnumChains.ETH,
76
+ types_1.EnumChains.ROPSTEN,
77
+ types_1.EnumChains.RINKEBY,
78
+ types_1.EnumChains.BSC,
79
+ types_1.EnumChains.BSCTEST,
80
+ types_1.EnumChains.Polygon,
81
+ types_1.EnumChains.OKEX,
82
+ types_1.EnumChains.XDai,
83
+ types_1.EnumChains.HECO,
84
+ types_1.EnumChains.Fantom,
85
+ types_1.EnumChains.Avalanche,
86
+ types_1.EnumChains.Arbitrum,
87
+ types_1.EnumChains.Optimism,
88
+ types_1.EnumChains.Boba,
89
+ types_1.EnumChains.Moonriver,
90
+ types_1.EnumChains.Aurora,
91
+ types_1.EnumChains.Cronos,
92
+ types_1.EnumChains.Harmony
93
+ ];
94
+ _this.type = types_1.EnumWalletType.Extension;
95
+ _this.sdk = null;
96
+ return _this;
97
+ }
98
+ /**
99
+ * connect metamask and get wallet address
100
+ * @param chainId specific chainId,throw error when not match
101
+ */
102
+ BitKeepWallet.prototype.requestConnect = function (chainId) {
103
+ return __awaiter(this, void 0, void 0, function () {
104
+ var address, currentChainId;
105
+ return __generator(this, function (_a) {
106
+ switch (_a.label) {
107
+ case 0:
108
+ if (!(window.isBitKeep && window.bitkeep.ethereum)) {
109
+ throw new Error(types_1.EnumErrors.NoBitKeep);
110
+ }
111
+ this.sdk = new web3_1.default(window.bitkeep.ethereum);
112
+ return [4 /*yield*/, this.sdk.eth.requestAccounts()];
113
+ case 1:
114
+ address = (_a.sent())[0];
115
+ return [4 /*yield*/, this.sdk.eth.getChainId()];
116
+ case 2:
117
+ currentChainId = _a.sent();
118
+ if (chainId && currentChainId !== chainId) {
119
+ throw new Error(types_1.EnumErrors.ChainIdNotMath);
120
+ }
121
+ this.address = address;
122
+ this.chainId = currentChainId;
123
+ return [2 /*return*/, address];
124
+ }
125
+ });
126
+ });
127
+ };
128
+ return BitKeepWallet;
129
+ }(BaseWallet_1.default));
130
+ exports.default = BitKeepWallet;
@@ -6,10 +6,14 @@ declare class NearWallet extends BaseWallet {
6
6
  supportChains: EnumChains[];
7
7
  type: EnumWalletType;
8
8
  sdk: any | null;
9
+ private keyStore;
10
+ private config;
11
+ init(): Promise<void>;
9
12
  /**
10
13
  * connect metamask and get wallet address
11
14
  * @param chainId specific chainId,throw error when not match
12
15
  */
13
16
  requestConnect(): Promise<any>;
17
+ constructor();
14
18
  }
15
19
  export default NearWallet;
@@ -61,46 +61,72 @@ Object.defineProperty(exports, "__esModule", { value: true });
61
61
  * @desc
62
62
  */
63
63
  // @ts-ignore
64
- var metamask_svg_1 = __importDefault(require("../assets/metamask.svg"));
64
+ var near_svg_1 = __importDefault(require("../assets/near.svg"));
65
65
  var types_1 = require("../types");
66
66
  var BaseWallet_1 = __importDefault(require("./BaseWallet"));
67
67
  var near_api_js_1 = require("near-api-js");
68
68
  var NearWallet = /** @class */ (function (_super) {
69
69
  __extends(NearWallet, _super);
70
70
  function NearWallet() {
71
- var _this = _super !== null && _super.apply(this, arguments) || this;
71
+ var _this = _super.call(this) || this;
72
72
  _this.name = types_1.EnumWalletName.NearWallet;
73
- _this.icon = metamask_svg_1.default;
73
+ _this.icon = near_svg_1.default;
74
74
  _this.supportChains = [
75
75
  types_1.EnumChains.NEAR
76
76
  ];
77
77
  _this.type = types_1.EnumWalletType.Extension;
78
78
  _this.sdk = null;
79
+ _this.keyStore = new near_api_js_1.keyStores.BrowserLocalStorageKeyStore();
80
+ _this.config = {
81
+ networkId: "mainnet",
82
+ keyStore: _this.keyStore,
83
+ nodeUrl: "https://public-rpc.blockpi.io/http/near",
84
+ walletUrl: "https://wallet.mainnet.near.org",
85
+ helperUrl: "https://helper.mainnet.near.org",
86
+ explorerUrl: "https://explorer.mainnet.near.org",
87
+ };
88
+ _this.init();
79
89
  return _this;
80
90
  }
91
+ NearWallet.prototype.init = function () {
92
+ return __awaiter(this, void 0, void 0, function () {
93
+ var account_id, query, vars, i, pair, _a;
94
+ return __generator(this, function (_b) {
95
+ switch (_b.label) {
96
+ case 0:
97
+ account_id = '';
98
+ query = window.location.search.substring(1);
99
+ vars = query.split("&");
100
+ for (i = 0; i < vars.length; i++) {
101
+ pair = vars[i].split("=");
102
+ if (pair[0] == 'account_id') {
103
+ account_id = pair[1];
104
+ }
105
+ }
106
+ if (!account_id) return [3 /*break*/, 2];
107
+ _a = near_api_js_1.WalletConnection.bind;
108
+ return [4 /*yield*/, near_api_js_1.connect(this.config)];
109
+ case 1:
110
+ new (_a.apply(near_api_js_1.WalletConnection, [void 0, _b.sent(), 'openOcen']))();
111
+ _b.label = 2;
112
+ case 2: return [2 /*return*/];
113
+ }
114
+ });
115
+ });
116
+ };
81
117
  /**
82
118
  * connect metamask and get wallet address
83
119
  * @param chainId specific chainId,throw error when not match
84
120
  */
85
121
  NearWallet.prototype.requestConnect = function () {
86
122
  return __awaiter(this, void 0, void 0, function () {
87
- var keyStore, config, near, account, address;
123
+ var near, account, address;
88
124
  return __generator(this, function (_a) {
89
125
  switch (_a.label) {
90
- case 0:
91
- keyStore = new near_api_js_1.keyStores.BrowserLocalStorageKeyStore();
92
- config = {
93
- networkId: "mainnet",
94
- keyStore: keyStore,
95
- nodeUrl: "https://rpc.mainnet.near.org",
96
- walletUrl: "https://wallet.mainnet.near.org",
97
- helperUrl: "https://helper.mainnet.near.org",
98
- explorerUrl: "https://explorer.mainnet.near.org",
99
- };
100
- return [4 /*yield*/, near_api_js_1.connect(config)];
126
+ case 0: return [4 /*yield*/, near_api_js_1.connect(this.config)];
101
127
  case 1:
102
128
  near = _a.sent();
103
- this.sdk = new near_api_js_1.WalletConnection(near, null);
129
+ this.sdk = new near_api_js_1.WalletConnection(near, 'openOcen');
104
130
  if (!this.sdk._authData.accountId) {
105
131
  this.sdk.requestSignIn({
106
132
  contractId: 'v2.ref-farming.near',
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg width="33px" height="33px" viewBox="0 0 33 33" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
3
+ <title>BitKeep</title>
4
+ <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
5
+ <g id="BitKeep" transform="translate(0.300000, 0.300000)">
6
+ <rect id="Rectangle" x="3.55271368e-15" y="1.42108547e-14" width="32" height="32"></rect>
7
+ <path d="M16,2.84217094e-14 L16,2.84217094e-14 C24.8375,2.84217094e-14 32,7.1625 32,16 L32,16 C32,24.8375 24.8375,32 16,32 L16,32 C7.1625,32 3.55271368e-15,24.8375 3.55271368e-15,16 L3.55271368e-15,16 C3.55271368e-15,7.165625 7.1625,2.84217094e-14 16,2.84217094e-14 Z" id="Path" fill="#7524F9"></path>
8
+ <path d="M25.95,11.071875 L25.95,12.203125 C25.95,12.425 25.83125,12.63125 25.640625,12.740625 L21.996875,14.84375 L25.25,16.715625 C25.684375,16.965625 25.95,17.428125 25.95,17.928125 L25.95,20.940625 C25.95,21.440625 25.68125,21.903125 25.246875,22.153125 L16.690625,27.0625 C16.259375,27.309375 15.728125,27.309375 15.29375,27.059375 L12.49375,25.440625 C12.2875,25.321875 12.2875,25.021875 12.49375,24.903125 L21.7375,19.58125 C21.840625,19.521875 21.840625,19.371875 21.7375,19.3125 L18.303125,17.328125 C18.1125,17.215625 17.875,17.215625 17.68125,17.328125 L8.2875,22.740625 C8.14375,22.821875 7.965625,22.825 7.821875,22.740625 L6.759375,22.13125 C6.325,21.88125 6.05625,21.41875 6.05625,20.915625 L6.05625,19.68125 C6.05625,19.515625 6.146875,19.359375 6.290625,19.278125 L19.75625,11.540625 C19.859375,11.48125 19.859375,11.33125 19.75625,11.271875 L16.31875,9.28125 C16.128125,9.16875 15.890625,9.16875 15.696875,9.28125 L6.521875,14.559375 C6.315625,14.678125 6.05625,14.528125 6.05625,14.290625 L6.05625,11.05625 C6.05625,10.55625 6.325,10.09375 6.759375,9.84375 L15.315625,4.934375 C15.746875,4.6875 16.278125,4.6875 16.709375,4.934375 L25.246875,9.859375 C25.68125,10.1125 25.95,10.571875 25.95,11.071875 Z" id="Path" fill="#FFFFFF"></path>
9
+ </g>
10
+ </g>
11
+ </svg>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg width="32px" height="32px" viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
3
+ <title>near</title>
4
+ <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
5
+ <g id="near" fill-rule="nonzero">
6
+ <circle id="Oval" fill="#FFFFFF" cx="16" cy="16" r="16"></circle>
7
+ <path d="M22.0444,7.02222 L17.8667,13.22222 C17.5778,13.64444 18.1333,14.15556 18.5333,13.8 L22.6444,10.22222 C22.7556,10.13333 22.9111,10.2 22.9111,10.35556 L22.9111,21.5333 C22.9111,21.6889 22.7111,21.7556 22.6222,21.6444 L10.17778,6.755556 C9.77778,6.266667 9.2,6 8.55556,6 L8.11111,6 C6.955556,6 6,6.955556 6,8.13333 L6,23.8667 C6,25.0444 6.955556,26 8.13333,26 C8.86667,26 9.55556,25.6222 9.95556,24.9778 L14.13333,18.7778 C14.42222,18.3556 13.86667,17.8444 13.46667,18.2 L9.35556,21.7556 C9.24444,21.8444 9.08889,21.7778 9.08889,21.6222 L9.08889,10.46667 C9.08889,10.31111 9.28889,10.24444 9.37778,10.35556 L21.8222,25.2444 C22.2222,25.7333 22.8222,26 23.4444,26 L23.8889,26 C25.0667,26 26.0222,25.0444 26.0222,23.8667 L26.0222,8.13333 C26,6.955556 25.0444,6 23.8667,6 C23.1333,6 22.4444,6.377778 22.0444,7.02222 Z" id="Path" fill="#000000"></path>
8
+ </g>
9
+ </g>
10
+ </svg>
package/lib/index.d.ts CHANGED
@@ -33,6 +33,7 @@ import KeplrWallet from "./Wallets/KeplrWallet";
33
33
  import BraveWallet from "./Wallets/BraveWallet";
34
34
  import CryptoCom from './Wallets/CryptoCom';
35
35
  import NearWallet from './Wallets/NearWallet';
36
+ import BitKeepWallet from './Wallets/BitKeepWallet';
36
37
  import { EnumChains } from "./types";
37
38
  export default WalletManager;
38
- export { WalletManager, MetaMask, BscWallet, Cyano, TronLink, EnumChains, Sollet, SolletIo, OntoMobile, WalletConnect, MathWallet, OntoWallet, SafePalWallet, ImTokenWallet, TokenPocket, TrustWallet, Coin98, Phantom, OKExWallet, TerraStation, CoinbaseWallet, CloverWallet, XDEFIWallet, SlopeWallet, SolflareWallet, MetaXWallet, KeplrWallet, BraveWallet, CryptoCom, NearWallet };
39
+ export { WalletManager, MetaMask, BscWallet, Cyano, TronLink, EnumChains, Sollet, SolletIo, OntoMobile, WalletConnect, MathWallet, OntoWallet, SafePalWallet, ImTokenWallet, TokenPocket, TrustWallet, Coin98, Phantom, OKExWallet, TerraStation, CoinbaseWallet, CloverWallet, XDEFIWallet, SlopeWallet, SolflareWallet, MetaXWallet, KeplrWallet, BraveWallet, CryptoCom, NearWallet, BitKeepWallet };
package/lib/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.NearWallet = exports.CryptoCom = exports.BraveWallet = exports.KeplrWallet = exports.MetaXWallet = exports.SolflareWallet = exports.SlopeWallet = exports.XDEFIWallet = exports.CloverWallet = exports.CoinbaseWallet = exports.TerraStation = exports.OKExWallet = exports.Phantom = exports.Coin98 = exports.TrustWallet = exports.TokenPocket = exports.ImTokenWallet = exports.SafePalWallet = exports.OntoWallet = exports.MathWallet = exports.WalletConnect = exports.OntoMobile = exports.SolletIo = exports.Sollet = exports.EnumChains = exports.TronLink = exports.Cyano = exports.BscWallet = exports.MetaMask = exports.WalletManager = void 0;
6
+ exports.BitKeepWallet = exports.NearWallet = exports.CryptoCom = exports.BraveWallet = exports.KeplrWallet = exports.MetaXWallet = exports.SolflareWallet = exports.SlopeWallet = exports.XDEFIWallet = exports.CloverWallet = exports.CoinbaseWallet = exports.TerraStation = exports.OKExWallet = exports.Phantom = exports.Coin98 = exports.TrustWallet = exports.TokenPocket = exports.ImTokenWallet = exports.SafePalWallet = exports.OntoWallet = exports.MathWallet = exports.WalletConnect = exports.OntoMobile = exports.SolletIo = exports.Sollet = exports.EnumChains = exports.TronLink = exports.Cyano = exports.BscWallet = exports.MetaMask = exports.WalletManager = void 0;
7
7
  /**
8
8
  * wallets-manager entry
9
9
  * @author openocean
@@ -68,6 +68,8 @@ var CryptoCom_1 = __importDefault(require("./Wallets/CryptoCom"));
68
68
  exports.CryptoCom = CryptoCom_1.default;
69
69
  var NearWallet_1 = __importDefault(require("./Wallets/NearWallet"));
70
70
  exports.NearWallet = NearWallet_1.default;
71
+ var BitKeepWallet_1 = __importDefault(require("./Wallets/BitKeepWallet"));
72
+ exports.BitKeepWallet = BitKeepWallet_1.default;
71
73
  var types_1 = require("./types");
72
74
  Object.defineProperty(exports, "EnumChains", { enumerable: true, get: function () { return types_1.EnumChains; } });
73
75
  var process = {};
package/lib/types.d.ts CHANGED
@@ -70,7 +70,8 @@ export declare enum EnumWalletName {
70
70
  MetaXWallet = "MetaX Wallet",
71
71
  keplrWallet = "Keplr Wallet",
72
72
  BraveWallet = "Brave Wallet",
73
- CryptoCom = "Crypto.com DeFi Wallet"
73
+ CryptoCom = "Crypto.com DeFi Wallet",
74
+ BitKeepWallet = "BitKeep Wallet"
74
75
  }
75
76
  export declare enum EnumErrors {
76
77
  NotMetamask = "40001",
@@ -97,7 +98,8 @@ export declare enum EnumErrors {
97
98
  OntoChainIdNotMath = "40023",
98
99
  NoKeplr = "40024",
99
100
  NoBrave = "40025",
100
- NoCryptoCom = "40026"
101
+ NoCryptoCom = "40026",
102
+ NoBitKeep = "40027"
101
103
  }
102
104
  export interface ConnectResult {
103
105
  chain: EnumChains;
package/lib/types.js CHANGED
@@ -73,6 +73,7 @@ var EnumWalletName;
73
73
  EnumWalletName["keplrWallet"] = "Keplr Wallet";
74
74
  EnumWalletName["BraveWallet"] = "Brave Wallet";
75
75
  EnumWalletName["CryptoCom"] = "Crypto.com DeFi Wallet";
76
+ EnumWalletName["BitKeepWallet"] = "BitKeep Wallet";
76
77
  })(EnumWalletName = exports.EnumWalletName || (exports.EnumWalletName = {}));
77
78
  var EnumErrors;
78
79
  (function (EnumErrors) {
@@ -101,4 +102,5 @@ var EnumErrors;
101
102
  EnumErrors["NoKeplr"] = "40024";
102
103
  EnumErrors["NoBrave"] = "40025";
103
104
  EnumErrors["NoCryptoCom"] = "40026";
105
+ EnumErrors["NoBitKeep"] = "40027";
104
106
  })(EnumErrors = exports.EnumErrors || (exports.EnumErrors = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openocean.finance/wallet",
3
- "version": "0.4.8",
3
+ "version": "0.4.11",
4
4
  "description": "A multi-chain wallets manager",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {