@fastnear/near-connect 0.10.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,83 @@
1
+ # 0.10.0
2
+
3
+ - Add **signInAndSignMessage** method
4
+ - Fix footer branding bugs
5
+ - Remove default HOT Branding
6
+ - Make icon in branding optional
7
+
8
+ # 0.9.0
9
+
10
+ - Add connect.use(WalletPlugin): **Experimental** feature to override wallet methods
11
+ - Add footerBranding property to disable or override footer UI
12
+ - Add signDelegateAction
13
+
14
+ # 0.8.2
15
+
16
+ - Fix css styles
17
+
18
+ # 0.8.0
19
+
20
+ - Remove WalletConnect as optional dep
21
+ - Change types for UseGlobalContractAction and DeployGlobalContractAction
22
+
23
+ # 0.7.0
24
+
25
+ - Add UseGlobalContractAction, DeployGlobalContractAction
26
+ - Support Actions from @near-js
27
+
28
+ # 0.6.11
29
+
30
+ - Add `signIn` to setup limited access key (deprecated flow)
31
+
32
+ # 0.6.10
33
+
34
+ - Fix SSR issues
35
+ - Fix random class name
36
+
37
+ # 0.6.9
38
+
39
+ - Fix SSR issues
40
+ - Move styles to isolated className
41
+
42
+ # 0.6.8
43
+
44
+ - Add fallback for manifest
45
+ - Remove contractId and methods from signIn method
46
+
47
+ # 0.6.7
48
+
49
+ - Move all intents specific code and multichain connector to @hot-labs/wibe3
50
+ - remove connectWithKey option
51
+ - add excludeWallets, providers and isBannedNearAddress options
52
+ - some cache improvements
53
+
54
+ # 0.6.4
55
+
56
+ - Add Intents class and more exports
57
+
58
+ # 0.6.3
59
+
60
+ - Add autoConnect option for NearConnector (usable for ParentFrameWallets)
61
+
62
+ # 0.6.2
63
+
64
+ - Improve html templater, fix ui bugs
65
+
66
+ # 0.6.1
67
+
68
+ - Fix MultichainPopup ui bug
69
+
70
+ # 0.6.0
71
+
72
+ - add html templater and improve Popup lifecycle render flow
73
+ - add debug manifests
74
+ - improve styles
75
+
76
+ # 0.5.7
77
+
78
+ - fix returns types for `signAndSendTransactions` in `InjectedWallet`
79
+
80
+ # 0.5.6
81
+
82
+ - Add `HotConnector.disconnect(type, { silent: true })`
83
+ - Change `signIntentsWithAuth` for NearWallet, use accountId as signerId for intents
package/README.md ADDED
@@ -0,0 +1,267 @@
1
+ # NEAR Connect
2
+
3
+ ![ezgif-26d74832f88c3c](https://github.com/user-attachments/assets/c4422057-38bb-4cd9-8bd0-568e29f46280)
4
+
5
+ This is a FastNear fork of the MIT licensed https://github.com/azbang/near-connect that makes modifications such that a function-call access key can reside in local storage and not prompt the end user to sign each time. Every transaction that contains a non-zero deposit still triggers the wallet confirmation.
6
+
7
+ Zero-dependency, robust, secure and lightweight wallet connector for the NEAR blockchain with **easily updatable** wallets code
8
+
9
+ `yarn add @hot-labs/near-connect`
10
+
11
+ ## How it works
12
+
13
+ Unlike near-wallet-selector, this library provides a secure execution environment for integrating wallets. This eliminates the need for a single registry of code for all wallets.
14
+
15
+ ## Available wallets in manifest
16
+
17
+ - HOT Wallet
18
+ - Meteor Wallet
19
+ - Intear Wallet
20
+ - MyNearWallet
21
+ - Nightly Wallet
22
+ - Near Mobile Wallet
23
+ - Unity Wallet
24
+ - OKX Wallet
25
+ - any wallet via WalletConnect
26
+
27
+ ## Dapp integration
28
+
29
+ ```ts
30
+ import { NearConnector } from "@hot-labs/near-connect";
31
+
32
+ const connector = new NearConnector();
33
+
34
+ connector.on("wallet:signOut", async () => {});
35
+ ```
36
+
37
+ ### Listen for "sign in" events
38
+
39
+ ```ts
40
+ // Listen for account sign in
41
+ connector.on("wallet:signIn", async (t) => {
42
+ const source = t.source; // "signIn" or "signInAndSignMessage" (see below)
43
+ const wallet = await connector.wallet();
44
+ const address = t.accounts[0].accountId;
45
+ });
46
+
47
+ // Listen for account sign in (including signed message)
48
+ connector.on("wallet:signInAndSignMessage", async (t) => {
49
+ const wallet = await connector.wallet();
50
+ const address = t.accounts[0].accountId;
51
+ const signedMessage = t.accounts[0].signedMessage;
52
+ });
53
+ ```
54
+
55
+ ### Initialize connection to wallet and sign in
56
+
57
+ ```ts
58
+ // Initiate connector and sign in (account only) and trigger "wallet:signIn"
59
+ await connector.connect();
60
+
61
+ // Initiate connector and sign in (account and a signed message)
62
+ // Triggers "wallet:signInAndSignMessage" (and "wallet:signIn" with "source" = "signInAndSignMessage")
63
+ await connector.connect({
64
+ signMessageParams: {
65
+ message: "Sign in to Example App",
66
+ recipient: "Demo app",
67
+ nonce
68
+ }
69
+ });
70
+ ```
71
+
72
+ ## WalletConnect support (optional)
73
+
74
+ Some wallets only work when you pass WalletConnect sign client to NearConnector, without it these wallets do not appear as an option to connect
75
+
76
+ ```ts
77
+ // Or use Reown appKit
78
+ import SignClient from "@walletconnect/sign-client";
79
+ const walletConnect = SignClient.init({ projectId: "...", metadata: {} });
80
+
81
+ import { NearConnector } from "@hot-labs/near-connect";
82
+ const connector = new NearConnector({ walletConnect });
83
+ ```
84
+
85
+ ## SignIn with limited key
86
+
87
+ ```ts
88
+ new NearConnector({ signIn: { contractId: "game.near", methods: ["action"] } });
89
+ ```
90
+
91
+ Some wallets allow adding a limited-access key to a contract as soon as the user connects their wallet. This enables the app to sign non-payable transactions without requiring wallet approval each time. However, this approach requires the user to submit an on-chain transaction during the initial connection, which may negatively affect the user experience. A better practice is to add the limited-access key after the user has already begun actively interacting with your application.
92
+
93
+ ## SignAndSendTransaction format actions
94
+
95
+ This library supports two types of actions when using methods like `signAndSendTransaction`:
96
+
97
+ 1. **near-wallet-selector Action format**
98
+ For backward compatibility, you can use actions in the same format as [near-wallet-selector], with all action types defined in [`./src/actions/types`](./src/actions/types.ts) (such as FunctionCall, Transfer, AddKey, etc.).
99
+
100
+ 2. **near-api-js actionsCreator format**
101
+ You can also use actions created via the `actionsCreator` functions from `near-api-js` (for example, `transactions.functionCall(...)` and other actions from the package).
102
+
103
+ You can use the old action format or the near-api-js format (recommended).
104
+
105
+ ## Wallet integration
106
+
107
+ The developer writes a self-hosted script that implements the integration of their wallet and adds a description to the common [manifest](./repository/manifest.json):
108
+
109
+ ```json
110
+ {
111
+ "id": "hot-wallet",
112
+ "version": "1.0.0",
113
+ "name": "HOT Wallet",
114
+ "description": "Secure Multichain wallet. Manage assets, refuel gas, and mine $HOT on any device with HOT Wallet",
115
+ "icon": "https://app.hot-labs.org/images/hot/hot-icon.png",
116
+ "website": "https://hot-labs.org/wallet",
117
+
118
+ "executor": "https://raw.githubusercontent.com/hot-dao/near-selector/refs/heads/main/repository/hotwallet.js",
119
+ "type": "sandbox",
120
+
121
+ "platform": {
122
+ "android": "https://play.google.com/store/apps/details?id=app.herewallet.hot&hl=en",
123
+ "ios": "https://apps.apple.com/us/app/hot-wallet/id6740916148",
124
+ "chrome": "https://chromewebstore.google.com/detail/hot-wallet/mpeengabcnhhjjgleiodimegnkpcenbk",
125
+ "firefox": "https://addons.mozilla.org/en-US/firefox/addon/hot-wallet",
126
+ "tga": "https://t.me/hot_wallet"
127
+ },
128
+
129
+ "features": {
130
+ "signMessage": true,
131
+ "signTransaction": true,
132
+ "signAndSendTransaction": true,
133
+ "signAndSendTransactions": true,
134
+ "signInWithoutAddKey": true,
135
+ "verifyOwner": false,
136
+ "testnet": false
137
+ },
138
+
139
+ "permissions": {
140
+ "storage": true,
141
+ "allowsOpen": ["https://hot-labs.org", "https://t.me/hot_wallet", "hotwallet://"]
142
+ }
143
+ }
144
+ ```
145
+
146
+ The `executor` endpoint called in a standalone iframe if the user decides to use this wallet on the site. The script implements the [NearWallet](./near-connect/src/types/wallet.ts) wallet class and registers it in a special object
147
+ `window.selector.ready(yourNearWallet)`
148
+
149
+ After that, the library delegates user requests directly to `yourNearWallet` via `iframe.postMessage` communication.
150
+ In addition, the script has the ability to draw any UI in the area allocated for the iframe that is necessary for interaction with the wallet.
151
+
152
+ ## Sandbox limitations
153
+
154
+ For security, the wallet script runs in a sandboxed iframe, which has many limitations. It cannot call modals or access an external page or use localStorage.
155
+ The `window.selector` implements some features for this:
156
+
157
+ ```ts
158
+ interface NearSelector {
159
+ location: string; // initial dapp location href
160
+ ready: (wallet: any) => void; // must call executor script for register wallet
161
+ open: (url: string, newTab = false) => void; // used for my-near-wallet
162
+
163
+ // use instead of localStorage
164
+ storage: {
165
+ set: (key: string, value: string) => Promise<void>;
166
+ get: (key: string) => Promise<string>;
167
+ remove: (key: string) => Promise<void>;
168
+ keys: () => Promise<string[]>;
169
+ };
170
+ }
171
+ ```
172
+
173
+ ## Manifest permissions
174
+
175
+ - `{ "storage": true }`: Use window.selector.storage in execution script
176
+ - `{ "allowsOpen": ["https://wallet.app"] }` Use window.selector.open for `allow` domains
177
+ - `{ "location": true }`: Use window.selector.location for initial url from dapp
178
+ - `{ "walletConnect": true }`: Use window.selector.walletConnect for use client
179
+
180
+ ## Manifest features
181
+
182
+ Each wallet must specify in the manifest a list of features that are supported.
183
+ This will help dApps filter wallets by the required features. As soon as the wallet starts supporting the required feature -- it simply adds it to the manifest and updates its execution script, all dapps automatically download the updates without the need to update the frontend.
184
+
185
+ ```ts
186
+ const selector = new NearConnector({
187
+ // Show wallets that support signMessage and testnet env
188
+ features: { signMessage: true, testnet: true },
189
+ });
190
+ ```
191
+
192
+ ## Branding UI
193
+
194
+ Currently, the library is branded as NEAR Connector in the footer of modal windows. You can set your own brand or completely disable the footer using this method:
195
+
196
+ ```ts
197
+ const selector = new NearConnector({
198
+ // or { icon: "url", heading: "", link: "", linkText: "" }
199
+ footerBranding: null,
200
+ });
201
+ ```
202
+
203
+ ## How to add my wallet?
204
+
205
+ When you develop a connector for your wallet, you can immediately test your code on real applications that use NEAR Connect. Super easy!
206
+ Once you have written your executor script and tested it - you only need to send a PR to update repository/manifest.json. After review, your wallet will automatically become available to all dApps that use the NEAR Connect.
207
+
208
+ ![Preview](https://github.com/user-attachments/assets/80855260-82f3-4c35-ae27-034e263c7b71)
209
+
210
+ ## Injected wallets
211
+
212
+ Like [Ethereum Multi Injected Provider Standart](https://eips.ethereum.org/EIPS/eip-6963) this library supports injected wallets for extenstions and in-app browsers. Your injection script can dispatch custom event with your wallet:
213
+
214
+ ```js
215
+ class NearWallet {
216
+ manifest: { ... };
217
+ signIn() {}
218
+ // all implementation
219
+ }
220
+
221
+ window.addEventListener("near-selector-ready", () => {
222
+ window.dispatchEvent(new CustomEvent("near-wallet-injected", { detail: new NearWallet() }));
223
+ });
224
+ ```
225
+
226
+ ## Background and future audit scope
227
+
228
+ Maintaining the current near-wallet-selector takes a lot of time and effort, wallet developers wait a long time to get an update to their connector inside a monolithic code base. After which they can wait months for applications to integrate their wallet into their site or update their frontend to update the wallet connector. This requires a lot of work on the review side of the near-wallet-selector team and STILL does not ensure the security of internal packages that will be installed in applications (for example, RHEA Finance or Near Intents).
229
+ All these problems prompted us to write a new solution that will:
230
+
231
+ 1. safely and isolatedly execute the code for connecting to wallets
232
+ 2. quickly and conveniently update wallets on all sites
233
+ 3. Save the internal near-wallet-selector team from endlessly maintaining a huge code base, because now only the wallet itself is responsible for the connection of each wallet and hosts its script wherever it wants.
234
+
235
+ The auditor does not need to look for vulnerabilities in the connection code of each wallet, this is the responsibility of the wallet team and their own audits.
236
+ The selector audit should be aimed at investigating the risks of interaction with the isolated code that is launched at the moment of connection to the wallet. The auditor should assess the reliability of the permissions that are described in the manifest and API for interaction of the isolated code with the host.
237
+ In fact, main target for audit is `src/wallets/near-wallets/SandboxedWallet/*`.
238
+
239
+ Additional:
240
+ Auditing `src/helpers` will help assess the correctness of the coding algorithms.
241
+ Auditing `src/popups` will help assess the correctness of interaction with the DOM, the presence of potential XSS attacks.
242
+
243
+ ## Publishing
244
+
245
+ To publish a new version of `@fastnear/near-connect`:
246
+
247
+ 1. Build the library:
248
+ ```sh
249
+ yarn build
250
+ ```
251
+
252
+ 2. Bump the version in the root `package.json`.
253
+
254
+ 3. Publish to npm:
255
+ ```sh
256
+ yarn npm publish --access public --otp <code>
257
+ ```
258
+
259
+ > **Note:** Only `@fastnear/near-connect` is published to npm. The `near-wallets/` package is not published separately — it builds executor scripts into `./repository/` and CDN bundles into `./cdn/`, which are referenced by the manifest.
260
+
261
+ ## Contributions
262
+
263
+ **Main contributor:**
264
+
265
+ Andrei Zhevlakov (CTO at HOT Labs)
266
+
267
+ andrey@herewallet.app
@@ -0,0 +1,24 @@
1
+ import { Account, FinalExecutionOutcome, NearWalletBase, Network, SignAndSendTransactionParams, SignAndSendTransactionsParams, SignDelegateActionsParams, SignDelegateActionsResponse, SignedMessage, SignMessageParams, type AccountWithSignedMessage, type SignInAndSignMessageParams } from "./types";
2
+ import { NearConnector } from "./NearConnector";
3
+ export declare class InjectedWallet {
4
+ readonly connector: NearConnector;
5
+ readonly wallet: NearWalletBase;
6
+ constructor(connector: NearConnector, wallet: NearWalletBase);
7
+ get manifest(): import("./types").WalletManifest;
8
+ signIn(data?: {
9
+ network?: Network;
10
+ contractId?: string;
11
+ methodNames?: Array<string>;
12
+ }): Promise<Array<Account>>;
13
+ signInAndSignMessage(data: SignInAndSignMessageParams): Promise<Array<AccountWithSignedMessage>>;
14
+ signOut(data?: {
15
+ network?: Network;
16
+ }): Promise<void>;
17
+ getAccounts(data?: {
18
+ network?: Network;
19
+ }): Promise<Array<Account>>;
20
+ signAndSendTransaction(params: SignAndSendTransactionParams): Promise<FinalExecutionOutcome>;
21
+ signAndSendTransactions(params: SignAndSendTransactionsParams): Promise<Array<FinalExecutionOutcome>>;
22
+ signMessage(params: SignMessageParams): Promise<SignedMessage>;
23
+ signDelegateActions(params: SignDelegateActionsParams): Promise<SignDelegateActionsResponse>;
24
+ }
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InjectedWallet = void 0;
4
+ const actions_1 = require("./actions");
5
+ class InjectedWallet {
6
+ connector;
7
+ wallet;
8
+ constructor(connector, wallet) {
9
+ this.connector = connector;
10
+ this.wallet = wallet;
11
+ }
12
+ get manifest() {
13
+ return this.wallet.manifest;
14
+ }
15
+ async signIn(data) {
16
+ return this.wallet.signIn({
17
+ network: data?.network || this.connector.network,
18
+ contractId: data?.contractId,
19
+ methodNames: data?.methodNames,
20
+ });
21
+ }
22
+ async signInAndSignMessage(data) {
23
+ return this.wallet.signInAndSignMessage({
24
+ network: data?.network || this.connector.network,
25
+ contractId: data?.contractId,
26
+ methodNames: data?.methodNames,
27
+ messageParams: data.messageParams,
28
+ });
29
+ }
30
+ async signOut(data) {
31
+ await this.wallet.signOut({ network: data?.network || this.connector.network });
32
+ }
33
+ async getAccounts(data) {
34
+ return this.wallet.getAccounts({ network: data?.network || this.connector.network });
35
+ }
36
+ async signAndSendTransaction(params) {
37
+ const actions = (0, actions_1.nearActionsToConnectorActions)(params.actions);
38
+ const network = params.network || this.connector.network;
39
+ const result = await this.wallet.signAndSendTransaction({ ...params, actions, network });
40
+ if (!result)
41
+ throw new Error("No result from wallet");
42
+ // @ts-ignore
43
+ if (Array.isArray(result.transactions))
44
+ return result.transactions[0];
45
+ return result;
46
+ }
47
+ async signAndSendTransactions(params) {
48
+ const network = params.network || this.connector.network;
49
+ const transactions = params.transactions.map((transaction) => ({
50
+ actions: (0, actions_1.nearActionsToConnectorActions)(transaction.actions),
51
+ receiverId: transaction.receiverId,
52
+ }));
53
+ const result = await this.wallet.signAndSendTransactions({ ...params, transactions, network });
54
+ if (!result)
55
+ throw new Error("No result from wallet");
56
+ // @ts-ignore
57
+ if (Array.isArray(result.transactions))
58
+ return result.transactions;
59
+ return result;
60
+ }
61
+ async signMessage(params) {
62
+ return this.wallet.signMessage({ ...params, network: params.network || this.connector.network });
63
+ }
64
+ async signDelegateActions(params) {
65
+ return this.wallet.signDelegateActions({
66
+ ...params,
67
+ delegateActions: params.delegateActions.map((delegateAction) => ({
68
+ ...delegateAction,
69
+ actions: (0, actions_1.nearActionsToConnectorActions)(delegateAction.actions),
70
+ })),
71
+ network: params.network || this.connector.network,
72
+ });
73
+ }
74
+ }
75
+ exports.InjectedWallet = InjectedWallet;
76
+ //# sourceMappingURL=InjectedWallet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InjectedWallet.js","s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CAAC;IAChB,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,MAAyB;QACzC,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;IACnG,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,MAAiC;QACzD,OAAO,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC;YACrC,GAAG,MAAM;YACT,eAAe,EAAE,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;gBAC/D,GAAG,cAAc;gBACjB,OAAO,EAAE,IAAA,uCAA6B,EAAC,cAAc,CAAC,OAAO,CAAC;aAC/D,CAAC,CAAC;YACH,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,OAAO;SAClD,CAAC,CAAC;IACL,CAAC;CACF;AAzED,wCAyEC"}
@@ -0,0 +1,91 @@
1
+ import { EventEmitter } from "./helpers/events";
2
+ import { DataStorage } from "./helpers/storage";
3
+ import IndexedDB from "./helpers/indexdb";
4
+ import type { EventMap, WalletManifest, Network, WalletFeatures, Logger, NearWalletBase, AbstractWalletConnect, FooterBranding, NearConnector_ConnectOptions } from "./types";
5
+ import type { WalletPlugin } from "./types/plugin";
6
+ interface NearConnectorOptions {
7
+ providers?: {
8
+ mainnet?: string[];
9
+ testnet?: string[];
10
+ };
11
+ features?: Partial<WalletFeatures>;
12
+ excludedWallets?: string[];
13
+ autoConnect?: boolean;
14
+ network?: Network;
15
+ manifest?: string | {
16
+ wallets: WalletManifest[];
17
+ version: string;
18
+ };
19
+ walletConnect?: Promise<AbstractWalletConnect> | AbstractWalletConnect;
20
+ events?: EventEmitter<EventMap>;
21
+ storage?: DataStorage;
22
+ logger?: Logger;
23
+ /**
24
+ * Footer branding for the wallet selector popup. If not provided, default branding will be used. If provided null, footer will be hidden.
25
+ */
26
+ footerBranding?: FooterBranding | null;
27
+ /**
28
+ * @deprecated
29
+ * Some wallets allow adding a limited-access key to a contract as soon as the user connects their wallet.
30
+ * This enables the app to sign non-payable transactions without requiring wallet approval each time.
31
+ * However, this approach requires the user to submit an on-chain transaction during the initial connection, which may negatively affect the user experience.
32
+ * A better practice is to add the limited-access key after the user has already begun actively interacting with your application.
33
+ */
34
+ signIn?: {
35
+ contractId?: string;
36
+ methodNames?: Array<string>;
37
+ };
38
+ }
39
+ export declare class NearConnector {
40
+ private storage;
41
+ readonly events: EventEmitter<EventMap>;
42
+ readonly db: IndexedDB;
43
+ logger?: Logger;
44
+ wallets: NearWalletBase[];
45
+ manifest: {
46
+ wallets: WalletManifest[];
47
+ version: string;
48
+ };
49
+ features: Partial<WalletFeatures>;
50
+ network: Network;
51
+ providers: {
52
+ mainnet?: string[];
53
+ testnet?: string[];
54
+ };
55
+ signInData?: {
56
+ contractId?: string;
57
+ methodNames?: Array<string>;
58
+ };
59
+ walletConnect?: Promise<AbstractWalletConnect> | AbstractWalletConnect;
60
+ footerBranding: FooterBranding | null;
61
+ excludedWallets: string[];
62
+ autoConnect?: boolean;
63
+ readonly whenManifestLoaded: Promise<void>;
64
+ constructor(options?: NearConnectorOptions);
65
+ get availableWallets(): NearWalletBase[];
66
+ private _handleNearWalletInjected;
67
+ private _loadManifest;
68
+ switchNetwork(network: "mainnet" | "testnet", signInData?: {
69
+ contractId?: string;
70
+ methodNames?: Array<string>;
71
+ }): Promise<void>;
72
+ registerWallet(manifest: WalletManifest): Promise<void>;
73
+ registerDebugWallet(json: string | WalletManifest): Promise<WalletManifest>;
74
+ removeDebugWallet(id: string): Promise<void>;
75
+ selectWallet({ features }?: {
76
+ features?: Partial<WalletFeatures>;
77
+ }): Promise<string>;
78
+ connect(input?: NearConnector_ConnectOptions): Promise<NearWalletBase>;
79
+ disconnect(wallet?: NearWalletBase): Promise<void>;
80
+ getConnectedWallet(): Promise<{
81
+ wallet: NearWalletBase;
82
+ accounts: import("./types").Account[];
83
+ }>;
84
+ wallet(id?: string | null): Promise<NearWalletBase>;
85
+ use(plugin: WalletPlugin): Promise<void>;
86
+ on<K extends keyof EventMap>(event: K, callback: (payload: EventMap[K]) => void): void;
87
+ once<K extends keyof EventMap>(event: K, callback: (payload: EventMap[K]) => void): void;
88
+ off<K extends keyof EventMap>(event: K, callback: (payload: EventMap[K]) => void): void;
89
+ removeAllListeners<K extends keyof EventMap>(event?: K): void;
90
+ }
91
+ export {};
@@ -0,0 +1,326 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.NearConnector = void 0;
7
+ const events_1 = require("./helpers/events");
8
+ const NearWalletsPopup_1 = require("./popups/NearWalletsPopup");
9
+ const storage_1 = require("./helpers/storage");
10
+ const indexdb_1 = __importDefault(require("./helpers/indexdb"));
11
+ const ParentFrameWallet_1 = require("./ParentFrameWallet");
12
+ const InjectedWallet_1 = require("./InjectedWallet");
13
+ const SandboxedWallet_1 = require("./SandboxedWallet");
14
+ const defaultManifests = [
15
+ "https://raw.githubusercontent.com/azbang/near-connect/refs/heads/main/repository/manifest.json",
16
+ "https://cdn.jsdelivr.net/gh/azbang/near-connect/repository/manifest.json",
17
+ ];
18
+ function createFilterForWalletFeatures(features) {
19
+ return (wallet) => {
20
+ return Object.entries(features).every(([key, value]) => {
21
+ if (value && !wallet.manifest.features?.[key])
22
+ return false;
23
+ return true;
24
+ });
25
+ };
26
+ }
27
+ class NearConnector {
28
+ storage;
29
+ events;
30
+ db;
31
+ logger;
32
+ wallets = [];
33
+ manifest = { wallets: [], version: "1.0.0" };
34
+ features = {};
35
+ network = "mainnet";
36
+ providers = { mainnet: [], testnet: [] };
37
+ signInData;
38
+ walletConnect;
39
+ footerBranding;
40
+ excludedWallets = [];
41
+ autoConnect;
42
+ whenManifestLoaded;
43
+ constructor(options) {
44
+ this.db = new indexdb_1.default("hot-connector", "wallets");
45
+ this.storage = options?.storage ?? new storage_1.LocalStorage();
46
+ this.events = options?.events ?? new events_1.EventEmitter();
47
+ this.logger = options?.logger;
48
+ this.network = options?.network ?? "mainnet";
49
+ this.walletConnect = options?.walletConnect;
50
+ this.autoConnect = options?.autoConnect ?? true;
51
+ this.providers = options?.providers ?? { mainnet: [], testnet: [] };
52
+ this.excludedWallets = options?.excludedWallets ?? [];
53
+ this.features = options?.features ?? {};
54
+ this.signInData = options?.signIn;
55
+ if (options?.footerBranding !== undefined) {
56
+ this.footerBranding = options?.footerBranding;
57
+ }
58
+ else {
59
+ this.footerBranding = {
60
+ icon: "https://pages.near.org/wp-content/uploads/2023/11/NEAR_token.png",
61
+ heading: "NEAR Connector",
62
+ link: "https://wallet.near.org",
63
+ linkText: "Don't have a wallet?",
64
+ };
65
+ }
66
+ this.whenManifestLoaded = new Promise(async (resolve) => {
67
+ if (options?.manifest == null || typeof options.manifest === "string") {
68
+ this.manifest = await this._loadManifest(options?.manifest).catch(() => ({ wallets: [], version: "1.0.0" }));
69
+ }
70
+ else {
71
+ this.manifest = options?.manifest ?? { wallets: [], version: "1.0.0" };
72
+ }
73
+ const set = new Set(this.excludedWallets);
74
+ set.delete("hot-wallet"); // always include hot-wallet
75
+ this.manifest.wallets = this.manifest.wallets.filter((wallet) => {
76
+ // Remove wallet with walletConnect permission but no projectId is provided
77
+ if (wallet.permissions.walletConnect && !this.walletConnect)
78
+ return false;
79
+ if (set.has(wallet.id))
80
+ return false; // excluded wallets
81
+ return true;
82
+ });
83
+ await new Promise((resolve) => setTimeout(resolve, 100));
84
+ resolve();
85
+ });
86
+ if (typeof window !== "undefined") {
87
+ window.addEventListener("near-wallet-injected", this._handleNearWalletInjected);
88
+ window.dispatchEvent(new Event("near-selector-ready"));
89
+ window.addEventListener("message", async (event) => {
90
+ if (event.data.type === "near-wallet-injected") {
91
+ await this.whenManifestLoaded.catch(() => { });
92
+ this.wallets = this.wallets.filter((wallet) => wallet.manifest.id !== event.data.manifest.id);
93
+ this.wallets.unshift(new ParentFrameWallet_1.ParentFrameWallet(this, event.data.manifest));
94
+ this.events.emit("selector:walletsChanged", {});
95
+ if (this.autoConnect) {
96
+ this.connect({ walletId: event.data.manifest.id });
97
+ }
98
+ }
99
+ });
100
+ }
101
+ this.whenManifestLoaded.then(() => {
102
+ if (typeof window !== "undefined") {
103
+ window.parent.postMessage({ type: "near-selector-ready" }, "*");
104
+ }
105
+ this.manifest.wallets.forEach((wallet) => this.registerWallet(wallet));
106
+ this.storage.get("debug-wallets").then((json) => {
107
+ const debugWallets = JSON.parse(json ?? "[]");
108
+ debugWallets.forEach((wallet) => this.registerDebugWallet(wallet));
109
+ });
110
+ });
111
+ }
112
+ get availableWallets() {
113
+ const wallets = this.wallets.filter((wallet) => {
114
+ return Object.entries(this.features).every(([key, value]) => {
115
+ if (value && !wallet.manifest.features?.[key])
116
+ return false;
117
+ return true;
118
+ });
119
+ });
120
+ return wallets.filter((wallet) => {
121
+ if (this.network === "testnet" && !wallet.manifest.features?.testnet)
122
+ return false;
123
+ return true;
124
+ });
125
+ }
126
+ _handleNearWalletInjected = (event) => {
127
+ this.wallets = this.wallets.filter((wallet) => wallet.manifest.id !== event.detail.manifest.id);
128
+ this.wallets.unshift(new InjectedWallet_1.InjectedWallet(this, event.detail));
129
+ this.events.emit("selector:walletsChanged", {});
130
+ };
131
+ async _loadManifest(manifestUrl) {
132
+ const manifestEndpoints = manifestUrl ? [manifestUrl] : defaultManifests;
133
+ for (const endpoint of manifestEndpoints) {
134
+ const res = await fetch(endpoint).catch(() => null);
135
+ if (!res || !res.ok)
136
+ continue;
137
+ return await res.json(); // TODO: Validate this
138
+ }
139
+ throw new Error("Failed to load manifest");
140
+ }
141
+ async switchNetwork(network, signInData) {
142
+ if (this.network === network)
143
+ return;
144
+ await this.disconnect().catch(() => { });
145
+ if (signInData)
146
+ this.signInData = signInData;
147
+ this.network = network;
148
+ await this.connect();
149
+ }
150
+ async registerWallet(manifest) {
151
+ if (manifest.type !== "sandbox")
152
+ throw new Error("Only sandbox wallets are supported");
153
+ if (this.wallets.find((wallet) => wallet.manifest.id === manifest.id))
154
+ return;
155
+ this.wallets.push(new SandboxedWallet_1.SandboxWallet(this, manifest));
156
+ this.events.emit("selector:walletsChanged", {});
157
+ }
158
+ async registerDebugWallet(json) {
159
+ const manifest = typeof json === "string" ? JSON.parse(json) : json;
160
+ if (manifest.type !== "sandbox")
161
+ throw new Error("Only sandbox wallets type are supported");
162
+ if (!manifest.id)
163
+ throw new Error("Manifest must have an id");
164
+ if (!manifest.name)
165
+ throw new Error("Manifest must have a name");
166
+ if (!manifest.icon)
167
+ throw new Error("Manifest must have an icon");
168
+ if (!manifest.website)
169
+ throw new Error("Manifest must have a website");
170
+ if (!manifest.version)
171
+ throw new Error("Manifest must have a version");
172
+ if (!manifest.executor)
173
+ throw new Error("Manifest must have an executor");
174
+ if (!manifest.features)
175
+ throw new Error("Manifest must have features");
176
+ if (!manifest.permissions)
177
+ throw new Error("Manifest must have permissions");
178
+ if (this.wallets.find((wallet) => wallet.manifest.id === manifest.id))
179
+ throw new Error("Wallet already registered");
180
+ manifest.debug = true;
181
+ this.wallets.unshift(new SandboxedWallet_1.SandboxWallet(this, manifest));
182
+ this.events.emit("selector:walletsChanged", {});
183
+ const debugWallets = this.wallets.filter((wallet) => wallet.manifest.debug).map((wallet) => wallet.manifest);
184
+ this.storage.set("debug-wallets", JSON.stringify(debugWallets));
185
+ return manifest;
186
+ }
187
+ async removeDebugWallet(id) {
188
+ this.wallets = this.wallets.filter((wallet) => wallet.manifest.id !== id);
189
+ const debugWallets = this.wallets.filter((wallet) => wallet.manifest.debug).map((wallet) => wallet.manifest);
190
+ this.storage.set("debug-wallets", JSON.stringify(debugWallets));
191
+ this.events.emit("selector:walletsChanged", {});
192
+ }
193
+ async selectWallet({ features = {} } = {}) {
194
+ await this.whenManifestLoaded.catch(() => { });
195
+ return new Promise((resolve, reject) => {
196
+ const popup = new NearWalletsPopup_1.NearWalletsPopup({
197
+ footer: this.footerBranding,
198
+ wallets: this.availableWallets.filter(createFilterForWalletFeatures(features)).map((wallet) => wallet.manifest),
199
+ onRemoveDebugManifest: async (id) => this.removeDebugWallet(id),
200
+ onAddDebugManifest: async (wallet) => this.registerDebugWallet(wallet),
201
+ onReject: () => (reject(new Error("User rejected")), popup.destroy()),
202
+ onSelect: (id) => (resolve(id), popup.destroy()),
203
+ });
204
+ popup.create();
205
+ });
206
+ }
207
+ async connect(input = {}) {
208
+ let walletId = input.walletId;
209
+ const signMessageParams = input.signMessageParams;
210
+ await this.whenManifestLoaded.catch(() => { });
211
+ if (!walletId)
212
+ walletId = await this.selectWallet(input.signMessageParams != null ? { features: { signInAndSignMessage: true } } : undefined);
213
+ try {
214
+ const wallet = await this.wallet(walletId);
215
+ this.logger?.log(`Wallet available to connect`, wallet);
216
+ await this.storage.set("selected-wallet", walletId);
217
+ this.logger?.log(`Set preferred wallet, try to signIn${signMessageParams != null ? " (with signed message)" : ""}`, walletId);
218
+ if (signMessageParams != null) {
219
+ const accounts = await wallet.signInAndSignMessage({
220
+ contractId: this.signInData?.contractId,
221
+ methodNames: this.signInData?.methodNames,
222
+ messageParams: signMessageParams,
223
+ network: this.network,
224
+ });
225
+ if (!accounts?.length)
226
+ throw new Error("Failed to sign in");
227
+ this.logger?.log(`Signed in to wallet (with signed message)`, walletId, accounts);
228
+ this.events.emit("wallet:signInAndSignMessage", { wallet, accounts, success: true });
229
+ this.events.emit("wallet:signIn", {
230
+ wallet,
231
+ accounts: accounts.map((account) => ({
232
+ accountId: account.accountId,
233
+ publicKey: account.publicKey,
234
+ })),
235
+ success: true,
236
+ source: "signInAndSignMessage",
237
+ });
238
+ }
239
+ else {
240
+ const accounts = await wallet.signIn({
241
+ contractId: this.signInData?.contractId,
242
+ methodNames: this.signInData?.methodNames,
243
+ network: this.network,
244
+ });
245
+ if (!accounts?.length)
246
+ throw new Error("Failed to sign in");
247
+ this.logger?.log(`Signed in to wallet`, walletId, accounts);
248
+ this.events.emit("wallet:signIn", { wallet, accounts, success: true, source: "signIn" });
249
+ }
250
+ return wallet;
251
+ }
252
+ catch (e) {
253
+ this.logger?.log("Failed to connect to wallet", e);
254
+ throw e;
255
+ }
256
+ }
257
+ async disconnect(wallet) {
258
+ if (!wallet)
259
+ wallet = await this.wallet();
260
+ await wallet.signOut({ network: this.network });
261
+ await this.storage.remove("selected-wallet");
262
+ this.events.emit("wallet:signOut", { success: true });
263
+ }
264
+ async getConnectedWallet() {
265
+ await this.whenManifestLoaded.catch(() => { });
266
+ const id = await this.storage.get("selected-wallet");
267
+ const wallet = this.wallets.find((wallet) => wallet.manifest.id === id);
268
+ if (!wallet)
269
+ throw new Error("No wallet selected");
270
+ const accounts = await wallet.getAccounts();
271
+ if (!accounts?.length)
272
+ throw new Error("No accounts found");
273
+ return { wallet, accounts };
274
+ }
275
+ async wallet(id) {
276
+ await this.whenManifestLoaded.catch(() => { });
277
+ if (!id) {
278
+ return this.getConnectedWallet()
279
+ .then(({ wallet }) => wallet)
280
+ .catch(async () => {
281
+ await this.storage.remove("selected-wallet");
282
+ throw new Error("No accounts found");
283
+ });
284
+ }
285
+ const wallet = this.wallets.find((wallet) => wallet.manifest.id === id);
286
+ if (!wallet)
287
+ throw new Error("Wallet not found");
288
+ return wallet;
289
+ }
290
+ async use(plugin) {
291
+ await this.whenManifestLoaded.catch(() => { });
292
+ this.wallets = this.wallets.map((wallet) => {
293
+ return new Proxy(wallet, {
294
+ get(target, prop, receiver) {
295
+ const originalValue = Reflect.get(target, prop, receiver);
296
+ // If plugin has this method and it's a function on the wallet
297
+ if (prop in plugin && typeof originalValue === "function") {
298
+ const pluginMethod = plugin[prop];
299
+ // Act as middleware, can call next method in line via next()
300
+ return function (...args) {
301
+ const next = () => originalValue.apply(target, args);
302
+ // Pass all args if any exist, otherwise undefined
303
+ // this ensures next is always the last param
304
+ return args.length > 0 ? pluginMethod.call(this, ...args, next) : pluginMethod.call(this, undefined, next);
305
+ };
306
+ }
307
+ return originalValue;
308
+ },
309
+ });
310
+ });
311
+ }
312
+ on(event, callback) {
313
+ this.events.on(event, callback);
314
+ }
315
+ once(event, callback) {
316
+ this.events.once(event, callback);
317
+ }
318
+ off(event, callback) {
319
+ this.events.off(event, callback);
320
+ }
321
+ removeAllListeners(event) {
322
+ this.events.removeAllListeners(event);
323
+ }
324
+ }
325
+ exports.NearConnector = NearConnector;
326
+ //# sourceMappingURL=NearConnector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NearConnector.js","sourceRoot":"","sources":["../src/NearConnector.ts"],"names":[],"mappings":";;;;;;AAAA,6CAAgD;AAChD,gEAA6D;AAC7D,+CAA8D;AAC9D,gEAA0C;AAgB1C,2DAAwD;AACxD,qDAAkD;AAClD,uDAAkD;AA+BlD,MAAM,gBAAgB,GAAG;IACvB,gGAAgG;IAChG,0EAA0E;CAC3E,CAAC;AAEF,SAAS,6BAA6B,CAAC,QAAiC;IACtE,OAAO,CAAC,MAAsB,EAAE,EAAE;QAChC,OAAO,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YACrD,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,GAA2B,CAAC;gBAAE,OAAO,KAAK,CAAC;YACpF,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED,MAAa,aAAa;IAChB,OAAO,CAAc;IACpB,MAAM,CAAyB;IAC/B,EAAE,CAAY;IACvB,MAAM,CAAU;IAEhB,OAAO,GAAqB,EAAE,CAAC;IAC/B,QAAQ,GAAmD,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;IAC7F,QAAQ,GAA4B,EAAE,CAAC;IACvC,OAAO,GAAY,SAAS,CAAC;IAE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AAC;wBAC1D,MAAM,YAAY,GAAI,MAAc,CAAC,IAAI,CAAC,CAAC;wBAE3C,6DAA6D;wBAC7D,OAAO,UAAqB,GAAG,IAAW;4BACxC,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;4BACrD,kDAAkD;4BAClD,6CAA6C;4BAC7C,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;wBAC7G,CAAC,CAAC;oBACJ,CAAC;oBAED,OAAO,aAAa,CAAC;gBACvB,CAAC;aACF,CAAmB,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,EAAE,CAA2B,KAAQ,EAAE,QAAwC;QAC7E,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAClC,CAAC;IAED,IAAI,CAA2B,KAAQ,EAAE,QAAwC;QAC/E,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACpC,CAAC;IAED,GAAG,CAA2B,KAAQ,EAAE,QAAwC;QAC9E,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACnC,CAAC;IAED,kBAAkB,CAA2B,KAAS;QACpD,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;CACF;AAtUD,sCAsUC"}
@@ -0,0 +1,24 @@
1
+ import { NearConnector } from "./NearConnector";
2
+ import { Account, FinalExecutionOutcome, Network, SignAndSendTransactionsParams, SignAndSendTransactionParams, SignedMessage, SignMessageParams, WalletManifest, SignDelegateActionsParams, SignDelegateActionsResponse, type AccountWithSignedMessage, type SignInAndSignMessageParams } from "./types";
3
+ export declare class ParentFrameWallet {
4
+ readonly connector: NearConnector;
5
+ readonly manifest: WalletManifest;
6
+ constructor(connector: NearConnector, manifest: WalletManifest);
7
+ callParentFrame(method: string, params: any): Promise<unknown>;
8
+ signIn(data?: {
9
+ network?: Network;
10
+ contractId?: string;
11
+ methodNames?: Array<string>;
12
+ }): Promise<Array<Account>>;
13
+ signInAndSignMessage(data: SignInAndSignMessageParams): Promise<Array<AccountWithSignedMessage>>;
14
+ signOut(data?: {
15
+ network?: Network;
16
+ }): Promise<void>;
17
+ getAccounts(data?: {
18
+ network?: Network;
19
+ }): Promise<Array<Account>>;
20
+ signAndSendTransaction(params: SignAndSendTransactionParams): Promise<FinalExecutionOutcome>;
21
+ signAndSendTransactions(params: SignAndSendTransactionsParams): Promise<Array<FinalExecutionOutcome>>;
22
+ signMessage(params: SignMessageParams): Promise<SignedMessage>;
23
+ signDelegateActions(params: SignDelegateActionsParams): Promise<SignDelegateActionsResponse>;
24
+ }
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ParentFrameWallet = void 0;
4
+ const actions_1 = require("./actions");
5
+ const uuid_1 = require("./helpers/uuid");
6
+ class ParentFrameWallet {
7
+ connector;
8
+ manifest;
9
+ constructor(connector, manifest) {
10
+ this.connector = connector;
11
+ this.manifest = manifest;
12
+ }
13
+ callParentFrame(method, params) {
14
+ const id = (0, uuid_1.uuid4)();
15
+ window.parent.postMessage({ type: "near-wallet-injected-request", id, method, params }, "*");
16
+ return new Promise((resolve, reject) => {
17
+ const handler = (event) => {
18
+ if (event.data.type === "near-wallet-injected-response" && event.data.id === id) {
19
+ window.removeEventListener("message", handler);
20
+ if (event.data.success)
21
+ resolve(event.data.result);
22
+ else
23
+ reject(event.data.error);
24
+ }
25
+ };
26
+ window.addEventListener("message", handler);
27
+ });
28
+ }
29
+ async signIn(data) {
30
+ const result = await this.callParentFrame("near:signIn", {
31
+ network: data?.network || this.connector.network,
32
+ contractId: data?.contractId,
33
+ methodNames: data?.methodNames,
34
+ });
35
+ if (Array.isArray(result))
36
+ return result;
37
+ return [result];
38
+ }
39
+ async signInAndSignMessage(data) {
40
+ const result = await this.callParentFrame("near:signInAndSignMessage", {
41
+ network: data?.network || this.connector.network,
42
+ contractId: data?.contractId,
43
+ methodNames: data?.methodNames,
44
+ messageParams: data.messageParams,
45
+ });
46
+ if (Array.isArray(result))
47
+ return result;
48
+ return [result];
49
+ }
50
+ async signOut(data) {
51
+ const args = { ...data, network: data?.network || this.connector.network };
52
+ await this.callParentFrame("near:signOut", args);
53
+ }
54
+ async getAccounts(data) {
55
+ const args = { ...data, network: data?.network || this.connector.network };
56
+ return this.callParentFrame("near:getAccounts", args);
57
+ }
58
+ async signAndSendTransaction(params) {
59
+ const connectorActions = (0, actions_1.nearActionsToConnectorActions)(params.actions);
60
+ const args = { ...params, actions: connectorActions, network: params.network || this.connector.network };
61
+ return this.callParentFrame("near:signAndSendTransaction", args);
62
+ }
63
+ async signAndSendTransactions(params) {
64
+ const args = { ...params, network: params.network || this.connector.network };
65
+ args.transactions = args.transactions.map((transaction) => ({
66
+ actions: (0, actions_1.nearActionsToConnectorActions)(transaction.actions),
67
+ receiverId: transaction.receiverId,
68
+ }));
69
+ return this.callParentFrame("near:signAndSendTransactions", args);
70
+ }
71
+ async signMessage(params) {
72
+ const args = { ...params, network: params.network || this.connector.network };
73
+ return this.callParentFrame("near:signMessage", args);
74
+ }
75
+ async signDelegateActions(params) {
76
+ const args = {
77
+ ...params,
78
+ delegateActions: params.delegateActions.map((delegateAction) => ({
79
+ ...delegateAction,
80
+ actions: (0, actions_1.nearActionsToConnectorActions)(delegateAction.actions),
81
+ })),
82
+ network: params.network || this.connector.network,
83
+ };
84
+ return this.callParentFrame("near:signDelegateActions", args);
85
+ }
86
+ }
87
+ exports.ParentFrameWallet = ParentFrameWallet;
88
+ //# sourceMappingURL=ParentFrameW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A,uCAA6B,EAAC,cAAc,CAAC,OAAO,CAAC;aAC/D,CAAC,CAAC;YACH,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,OAAO;SAClD,CAAC;QAEF,OAAO,IAAI,CAAC,eAAe,CAAC,0BAA0B,EAAE,IAAI,CAAyC,CAAC;IACxG,CAAC;CACF;AAtFD,8CAsFC"}
@@ -0,0 +1,9 @@
1
+ export { type DataStorage, LocalStorage } from "./helpers/storage";
2
+ export { ParentFrameWallet } from "./ParentFrameWallet";
3
+ export { SandboxWallet } from "./SandboxedWallet";
4
+ export { InjectedWallet } from "./InjectedWallet";
5
+ export { NearConnector } from "./NearConnector";
6
+ export { nearActionsToConnectorActions } from "./actions";
7
+ export type { ConnectorAction } from "./actions/types";
8
+ export type { WalletPlugin } from "./types/plugin";
9
+ export type { FooterBranding, NearWalletBase, WalletManifest, EventNearWalletInjected, SignMessageParams, SignedMessage, SignAndSendTransactionParams, SignAndSendTransactionsParams, SignDelegateActionsParams as SignDelegateActionParams, SignDelegateActionResult, SignInAndSignMessageParams, AccountWithSignedMessage, } from "./types";
package/build/index.js ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nearActionsToConnectorActions = exports.NearConnector = exports.InjectedWallet = exports.SandboxWallet = exports.ParentFrameWallet = exports.LocalStorage = void 0;
4
+ var storage_1 = require("./helpers/storage");
5
+ Object.defineProperty(exports, "LocalStorage", { enumerable: true, get: function () { return storage_1.LocalStorage; } });
6
+ var ParentFrameWallet_1 = require("./ParentFrameWallet");
7
+ Object.defineProperty(exports, "ParentFrameWallet", { enumerable: true, get: function () { return ParentFrameWallet_1.ParentFrameWallet; } });
8
+ var SandboxedWallet_1 = require("./SandboxedWallet");
9
+ Object.defineProperty(exports, "SandboxWallet", { enumerable: true, get: function () { return SandboxedWallet_1.SandboxWallet; } });
10
+ var InjectedWallet_1 = require("./InjectedWallet");
11
+ Object.defineProperty(exports, "InjectedWallet", { enumerable: true, get: function () { return InjectedWallet_1.InjectedWallet; } });
12
+ var NearConnector_1 = require("./NearConnector");
13
+ Object.defineProperty(exports, "NearConnector", { enumerable: true, get: function () { return NearConnector_1.NearConnector; } });
14
+ var actions_1 = require("./actions");
15
+ Object.defineProperty(exports, "nearActionsToConnectorActions", { enumerable: true, get: function () { return actions_1.nearActionsToConnectorActions; } });
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6CAAmE;AAAxC,uGAAA,YAAY,OAAA;AACvC,yDAAwD;AAA/C,sHAAA,iBAAiB,OAAA;AAC1B,qDAAkD;AAAzC,gHAAA,aAAa,OAAA;AACtB,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AAEtB,qCAA0D;AAAjD,wHAAA,6BAA6B,OAAA"}
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@fastnear/near-connect",
3
+ "version": "0.10.1",
4
+ "type": "commonjs",
5
+ "main": "./build/index.js",
6
+ "types": "./build/index.d.ts",
7
+ "license": "MIT",
8
+ "author": "HOT Labs and FastNear",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/fastnear/near-connect"
12
+ },
13
+ "homepage": "https://github.com/fastnear/near-connect",
14
+ "directories": {
15
+ "build": "build"
16
+ },
17
+ "files": [
18
+ "build/*"
19
+ ],
20
+ "scripts": {
21
+ "example": "cd example && yarn && yarn start",
22
+ "build:wallets": "cd near-wallets && yarn build:wallets",
23
+ "build": "rm -rf build && yarn tsc",
24
+ "cdn": "vite build",
25
+ "type-check": "tsc --noEmit"
26
+ },
27
+ "devDependencies": {
28
+ "@near-js/transactions": "^2.5.1",
29
+ "@near-js/types": "^2.5.1",
30
+ "typescript": "^5.2.2",
31
+ "vite": "^7.2.2",
32
+ "vite-plugin-node-polyfills": "^0.24.0"
33
+ }
34
+ }