diff --git a/packages/wallets/blocknine/CHANGELOG.md b/packages/wallets/blocknine/CHANGELOG.md new file mode 100644 index 000000000..e08d7f452 --- /dev/null +++ b/packages/wallets/blocknine/CHANGELOG.md @@ -0,0 +1,20 @@ +Changelog +[0.0.7] - 2025-07-30 +Initial Release +First version of Block Nine Wallet for Solana. +Added + +Wallet creation and import +Send and receive SOL and SPL tokens +Transaction signing +Jupiter DEX integration +NFT support +Chrome extension +Password protection + +Technical + +Solana Web3.js v1.98.0 +React 18.2.0 +TypeScript 5.3.3 +Chrome Web Store: https://chromewebstore.google.com/detail/block-nine/aignndpbjoegbcggdkpanehihgeefjpd \ No newline at end of file diff --git a/packages/wallets/blocknine/LICENSE b/packages/wallets/blocknine/LICENSE new file mode 100644 index 000000000..d64569567 --- /dev/null +++ b/packages/wallets/blocknine/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/packages/wallets/blocknine/README.md b/packages/wallets/blocknine/README.md new file mode 100644 index 000000000..915d77494 --- /dev/null +++ b/packages/wallets/blocknine/README.md @@ -0,0 +1,47 @@ +Discription +BlockNine Wallet: Experience the Future of Crypto with Secure, Easy, and Lightning-Fast Transactions + +In the ever-evolving world of digital finance, managing cryptocurrencies securely and efficiently has become more critical than ever. From long-time investors to first-time users, everyone wants a crypto wallet that’s fast, secure, and user-friendly. That’s where BlockNine Wallet steps in—a next-generation Web3 wallet built to deliver a seamless and powerful experience in managing digital assets. Whether you're storing Bitcoin, trading tokens on the Solana chain, or interacting with decentralized applications (dApps), BlockNine is designed to keep you ahead of the curve. + +User-Centric Design Meets Powerful Functionality The first thing users notice about BlockNine is its intuitive interface. Unlike clunky wallets that demand a steep learning curve, BlockNine offers a minimalist, responsive design that welcomes both beginners and experienced traders. + +Clean, Modern UI: Navigating BlockNine is refreshingly simple. Clear tabs, categorized assets, one-tap actions, and real-time portfolio tracking ensure users always know where their funds are and how they’re performing. + +Unmatched Security—You Hold the Keys One of the defining features of BlockNine is its commitment to user sovereignty and security. Your assets are protected not just by technology but by philosophy—Not your keys, not your crypto is a principle BlockNine takes seriously. + +End-to-End Encryption: All sensitive user data, including private keys and seed phrases, are encrypted on-device. BlockNine never stores or accesses your keys on its servers, making unauthorized access nearly impossible. + +Secure Seed Phrase Storage: Users can choose to store their encrypted seed phrases locally or back them up via secure cold storage integrations. BlockNine also offers encrypted cloud backups as an optional feature—with zero-knowledge architecture. + +Transaction Signing Transparency: Every transaction requires explicit user approval. You see exactly what you’re signing, reducing the risk of malicious smart contract interactions. + +Lightning-Fast Transactions with Minimal Fees One of the most impressive aspects of BlockNine Wallet is its transaction speed—especially on chains like Solana and Avalanche, which the wallet is deeply optimized for. Time-sensitive trades and on-the-go transactions become effortless. + +Instant Swaps: Thanks to integrated decentralized exchange (DEX) aggregators, users can swap tokens with real-time price comparisons, minimal slippage, and zero unnecessary delays. + +Seamless dApp Interaction and Web3 Connectivity Web3 is growing fast, and BlockNine Wallet is your gateway to explore everything from decentralized finance to NFTs and blockchain With a single click, users can connect their wallet to any supported dApp. + +One-Tap dApp Authorization: No more repeated approvals or confusing permission screens. BlockNine simplifies access with one-tap, transparent authorization. + +Customizable and Scalable for Power Users BlockNine understands that not all users are the same. While casual users benefit from simplicity, power users crave control—and BlockNine delivers both. + +Multiple Wallet Management: Manage multiple wallets in one interface. Great for investors who separate personal, business, and high-security accounts. + +Advanced Analytics Dashboard: Track real-time portfolio value, PnL (profit and loss), asset distribution, and transaction history—all with beautiful data visualizations. + +Token Customization: Manually add custom tokens, adjust slippage tolerances, set alerts, and manage watchlists. + +Regular Community Polls: BlockNine actively includes its community in roadmap decisions. You get a say in which features are prioritized next. + +Privacy First, Always BlockNine believes privacy is a right, not an upgrade. That’s why the wallet collects zero personal data. There are no trackers, no surveillance, and no selling of data to third parties. + +Anonymous by Default: No KYC needed to start. You control your identity and presence. + +Private Transaction Support: For supported chains, BlockNine allows optional use of privacy tools like Clocked Feature. + +Why BlockNine Is the Future of Crypto Wallets +In a crowded market of wallets that often compromise either usability or security, BlockNine stands out by mastering both. It offers a user experience that’s as smooth as traditional finance apps but with the power and control of true decentralized technology. Whether you’re a crypto veteran managing diverse assets across chains, or a beginner simply looking to store and send tokens safely, BlockNine is built for you. + +Fast. Secure. Intuitive. Future-proof. + +Experience the future of crypto today—only with BlockNine Wallet. \ No newline at end of file diff --git a/packages/wallets/blocknine/package.json b/packages/wallets/blocknine/package.json new file mode 100644 index 000000000..59b64e1c7 --- /dev/null +++ b/packages/wallets/blocknine/package.json @@ -0,0 +1,157 @@ +{ + "name": "block-nine", + "displayName": "Block Nine", + "version": "0.0.7", + "description": "Block Nine - The Ultimate Crypto Wallet for Solana Ecosystem", + "author": "Jasim", + "license": "MIT", + "homepage": "https://blocknine.com/", + "repository": { + "type": "git", + "url": "https://github.com/BlockNineWallet/block-nine-wallet" + }, + "bugs": { + "url": "https://github.com/BlockNineWallet/block-nine-wallet" + }, + "keywords": [ + "solana", + "Bitcoin", + "Etheureme", + "BNB", + "Bitcoin Cash", + "Base", + "Litecoin", + "XRP", + "wallet", + "crypto", + "blockchain", + "defi", + "nft", + "browser-extension", + "web3" + ], + "engines": { + "node": ">=18.0.0", + "npm": ">=8.0.0" + }, + "scripts": { + "dev": "plasmo dev", + "build": "plasmo build", + "package": "plasmo package", + "clean": "rimraf build dist .plasmo", + "lint": "eslint src --ext .ts,.tsx", + "lint:fix": "eslint src --ext .ts,.tsx --fix", + "type-check": "tsc --noEmit", + "format": "prettier --write src/**/*.{ts,tsx,json}", + "test": "jest", + "test:watch": "jest --watch" + }, + "dependencies": { + "@solana/web3.js": "^1.98.0", + "@solana/spl-token": "^0.4.13", + "@metaplex-foundation/js": "^0.18.0", + "@metaplex-foundation/mpl-auction-house": "^2.5.1", + "@metaplex-foundation/mpl-token-metadata": "^3.4.0", + "@jup-ag/core": "4.0.0-beta.21", + "bip39": "^3.1.0", + "ed25519-hd-key": "^1.3.0", + "tweetnacl": "^1.0.3", + "crypto-js": "^4.2.0", + "bs58": "^6.0.0", + "react": "18.2.0", + "react-dom": "18.2.0", + "plasmo": "0.90.3", + "@reduxjs/toolkit": "^2.7.0", + "react-redux": "^9.2.0", + "react-router-dom": "^7.3.0", + "@headlessui/react": "^2.2.1", + "lucide-react": "^0.479.0", + "recharts": "^2.15.1", + "react-toastify": "^11.0.5", + "axios": "^1.8.4", + "dotenv": "^16.4.7" + }, + "devDependencies": { + "@types/bip39": "^3.0.4", + "@types/bs58": "^4.0.4", + "@types/chrome": "0.0.258", + "@types/node": "^22.13.13", + "@types/react": "18.2.48", + "@types/react-dom": "18.2.18", + "@ianvs/prettier-plugin-sort-imports": "4.1.1", + "autoprefixer": "^10.4.21", + "postcss": "^8.5.3", + "tailwindcss": "3", + "typescript": "5.3.3", + "prettier": "3.2.4", + "eslint": "^8.57.0", + "@typescript-eslint/eslint-plugin": "^6.0.0", + "@typescript-eslint/parser": "^6.0.0", + "rimraf": "^5.0.0", + "jest": "^29.0.0", + "@types/jest": "^29.0.0" + }, + "manifest": { + "manifest_version": 3, + "name": "Block Nine", + "description": "The Ultimate Crypto Wallet for Solana Ecosystem", + "version": "0.0.2", + "permissions": [ + "storage", + "activeTab", + "scripting" + ], + "host_permissions": [ + "https://api.blockchain.info/*", + "https://api.coingecko.com/*", + "https://api.mainnet-beta.solana.com/*", + "https://api.devnet.solana.com/*", + "https://quote-api.jup.ag/*" + ], + "action": { + "default_popup": "popup.html", + "default_title": "Block Nine Wallet" + }, + "icons": { + "16": "assets/icon-16.png", + "32": "assets/icon-32.png", + "48": "assets/icon-48.png", + "128": "assets/icon-128.png" + }, + "background": { + "service_worker": "background.js" + }, + "content_scripts": [ + { + "matches": [""], + "js": ["content.js"], + "run_at": "document_start" + } + ], + "web_accessible_resources": [ + { + "resources": ["injected.js"], + "matches": [""] + } + ] + }, + "plasmo": { + "manifest": { + "host_permissions": [ + "https://api.blockchain.info/*", + "https://api.coingecko.com/*", + "https://api.mainnet-beta.solana.com/*", + "https://api.devnet.solana.com/*", + "https://quote-api.jup.ag/*" + ] + } + }, + "browserslist": [ + "defaults", + "not IE 11" + ], + "funding": { + "type": "github", + "url": "https://github.com/BlockNineWallet/block-nine-wallet" + } +} \ No newline at end of file diff --git a/packages/wallets/blocknine/src/adapter.ts b/packages/wallets/blocknine/src/adapter.ts new file mode 100644 index 000000000..8dadb9f74 --- /dev/null +++ b/packages/wallets/blocknine/src/adapter.ts @@ -0,0 +1,305 @@ +import type { EventEmitter, SendTransactionOptions, WalletName } from '@solana/wallet-adapter-base'; +import { + BaseMessageSignerWalletAdapter, + isIosAndRedirectable, + isVersionedTransaction, + scopePollingDetectionStrategy, + WalletAccountError, + WalletConnectionError, + WalletDisconnectedError, + WalletDisconnectionError, + WalletError, + WalletNotConnectedError, + WalletNotReadyError, + WalletPublicKeyError, + WalletReadyState, + WalletSendTransactionError, + WalletSignMessageError, + WalletSignTransactionError, +} from '@solana/wallet-adapter-base'; +import type { + Connection, + SendOptions, + Transaction, + TransactionSignature, + TransactionVersion, + VersionedTransaction, +} from '@solana/web3.js'; +import { PublicKey } from '@solana/web3.js'; + +interface BlockNineWalletEvents { + connect(...args: unknown[]): unknown; + disconnect(...args: unknown[]): unknown; + accountChanged(newPublicKey: PublicKey): unknown; +} + +interface BlockNineWallet extends EventEmitter { + isBlockNine?: boolean; + publicKey?: { toBytes(): Uint8Array }; + isConnected: boolean; + signTransaction(transaction: T): Promise; + signAllTransactions(transactions: T[]): Promise; + signAndSendTransaction( + transaction: T, + options?: SendOptions + ): Promise<{ signature: TransactionSignature }>; + signMessage(message: Uint8Array): Promise<{ signature: Uint8Array }>; + connect(): Promise; + disconnect(): Promise; +} + +interface BlockNineWindow extends Window { + blockNine?: { + solana?: BlockNineWallet; + }; + solana?: BlockNineWallet; +} + +declare const window: BlockNineWindow; + +export interface BlockNineWalletAdapterConfig {} + +export const BlockNineWalletName = 'BlockNine' as WalletName<'BlockNine'>; + +export class BlockNineWalletAdapter extends BaseMessageSignerWalletAdapter { + name = BlockNineWalletName; + url = 'https://blocknine.io'; + icon = + 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDgiIGhlaWdodD0iMTA4IiB2aWV3Qm94PSIwIDAgMTA4IDEwOCIgZmlsbD0ibm9uZSI+CjxyZWN0IHdpZHRoPSIxMDgiIGhlaWdodD0iMTA4IiByeD0iMjYiIGZpbGw9IiMwMDdBRkYiLz4KPHRleHQgeD0iNTQiIHk9IjU0IiBmb250LWZhbWlseT0iQXJpYWwiIGZvbnQtc2l6ZT0iMjQiIGZpbGw9IndoaXRlIiB0ZXh0LWFuY2hvcj0ibWlkZGxlIiBkeT0iLjNlbSI+QjkgPC90ZXh0Pgo8L3N2Zz4='; + supportedTransactionVersions: ReadonlySet = new Set(['legacy', 0]); + + private _connecting: boolean; + private _wallet: BlockNineWallet | null; + private _publicKey: PublicKey | null; + private _readyState: WalletReadyState = + typeof window === 'undefined' || typeof document === 'undefined' + ? WalletReadyState.Unsupported + : WalletReadyState.NotDetected; + + constructor(config: BlockNineWalletAdapterConfig = {}) { + super(); + this._connecting = false; + this._wallet = null; + this._publicKey = null; + + if (this._readyState !== WalletReadyState.Unsupported) { + if (isIosAndRedirectable()) { + // when in iOS (not webview), set BlockNine as loadable instead of checking for install + this._readyState = WalletReadyState.Loadable; + this.emit('readyStateChange', this._readyState); + } else { + scopePollingDetectionStrategy(() => { + if (window.blockNine?.solana?.isBlockNine || window.solana?.isBlockNine) { + this._readyState = WalletReadyState.Installed; + this.emit('readyStateChange', this._readyState); + return true; + } + return false; + }); + } + } + } + + get publicKey() { + return this._publicKey; + } + + get connecting() { + return this._connecting; + } + + get readyState() { + return this._readyState; + } + + async autoConnect(): Promise { + // Skip autoconnect in the Loadable state + // We can't redirect to a universal link without user input + if (this.readyState === WalletReadyState.Installed) { + await this.connect(); + } + } + + async connect(): Promise { + try { + if (this.connected || this.connecting) return; + + if (this.readyState === WalletReadyState.Loadable) { + // redirect to the BlockNine extension/app + const url = encodeURIComponent(window.location.href); + const ref = encodeURIComponent(window.location.origin); + window.location.href = `chrome-extension://blocknine/popup.html?url=${url}&ref=${ref}`; + return; + } + + if (this.readyState !== WalletReadyState.Installed) throw new WalletNotReadyError(); + + this._connecting = true; + + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const wallet = window.blockNine?.solana || window.solana!; + + if (!wallet.isConnected) { + try { + await wallet.connect(); + } catch (error: any) { + throw new WalletConnectionError(error?.message, error); + } + } + + if (!wallet.publicKey) throw new WalletAccountError(); + + let publicKey: PublicKey; + try { + publicKey = new PublicKey(wallet.publicKey.toBytes()); + } catch (error: any) { + throw new WalletPublicKeyError(error?.message, error); + } + + wallet.on('disconnect', this._disconnected); + wallet.on('accountChanged', this._accountChanged); + + this._wallet = wallet; + this._publicKey = publicKey; + + this.emit('connect', publicKey); + } catch (error: any) { + this.emit('error', error); + throw error; + } finally { + this._connecting = false; + } + } + + async disconnect(): Promise { + const wallet = this._wallet; + if (wallet) { + wallet.off('disconnect', this._disconnected); + wallet.off('accountChanged', this._accountChanged); + + this._wallet = null; + this._publicKey = null; + + try { + await wallet.disconnect(); + } catch (error: any) { + this.emit('error', new WalletDisconnectionError(error?.message, error)); + } + } + + this.emit('disconnect'); + } + + async sendTransaction( + transaction: T, + connection: Connection, + options: SendTransactionOptions = {} + ): Promise { + try { + const wallet = this._wallet; + if (!wallet) throw new WalletNotConnectedError(); + + try { + const { signers, ...sendOptions } = options; + + if (isVersionedTransaction(transaction)) { + signers?.length && transaction.sign(signers); + } else { + transaction = (await this.prepareTransaction(transaction, connection, sendOptions)) as T; + signers?.length && (transaction as Transaction).partialSign(...signers); + } + + sendOptions.preflightCommitment = sendOptions.preflightCommitment || connection.commitment; + + const { signature } = await wallet.signAndSendTransaction(transaction, sendOptions); + return signature; + } catch (error: any) { + if (error instanceof WalletError) throw error; + throw new WalletSendTransactionError(error?.message, error); + } + } catch (error: any) { + this.emit('error', error); + throw error; + } + } + + async signTransaction(transaction: T): Promise { + try { + const wallet = this._wallet; + if (!wallet) throw new WalletNotConnectedError(); + + try { + return (await wallet.signTransaction(transaction)) || transaction; + } catch (error: any) { + throw new WalletSignTransactionError(error?.message, error); + } + } catch (error: any) { + this.emit('error', error); + throw error; + } + } + + async signAllTransactions(transactions: T[]): Promise { + try { + const wallet = this._wallet; + if (!wallet) throw new WalletNotConnectedError(); + + try { + return (await wallet.signAllTransactions(transactions)) || transactions; + } catch (error: any) { + throw new WalletSignTransactionError(error?.message, error); + } + } catch (error: any) { + this.emit('error', error); + throw error; + } + } + + async signMessage(message: Uint8Array): Promise { + try { + const wallet = this._wallet; + if (!wallet) throw new WalletNotConnectedError(); + + try { + const { signature } = await wallet.signMessage(message); + return signature; + } catch (error: any) { + throw new WalletSignMessageError(error?.message, error); + } + } catch (error: any) { + this.emit('error', error); + throw error; + } + } + + private _disconnected = () => { + const wallet = this._wallet; + if (wallet) { + wallet.off('disconnect', this._disconnected); + wallet.off('accountChanged', this._accountChanged); + + this._wallet = null; + this._publicKey = null; + + this.emit('error', new WalletDisconnectedError()); + this.emit('disconnect'); + } + }; + + private _accountChanged = (newPublicKey: PublicKey) => { + const publicKey = this._publicKey; + if (!publicKey) return; + + try { + newPublicKey = new PublicKey(newPublicKey.toBytes()); + } catch (error: any) { + this.emit('error', new WalletPublicKeyError(error?.message, error)); + return; + } + + if (publicKey.equals(newPublicKey)) return; + + this._publicKey = newPublicKey; + this.emit('connect', newPublicKey); + }; +} \ No newline at end of file diff --git a/packages/wallets/blocknine/src/index.ts b/packages/wallets/blocknine/src/index.ts new file mode 100644 index 000000000..d9c74bd6d --- /dev/null +++ b/packages/wallets/blocknine/src/index.ts @@ -0,0 +1 @@ +export * from './adapter.js'; \ No newline at end of file diff --git a/packages/wallets/blocknine/tsconfig.base.json b/packages/wallets/blocknine/tsconfig.base.json new file mode 100644 index 000000000..edb1b0441 --- /dev/null +++ b/packages/wallets/blocknine/tsconfig.base.json @@ -0,0 +1,74 @@ +{ + "compilerOptions": { + "target": "ES2020", + "lib": [ + "DOM", + "DOM.Iterable", + "ES2020" + ], + "allowJs": true, + "skipLibCheck": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "moduleResolution": "bundler", + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": false, + "jsx": "react-jsx", + "declaration": true, + "declarationMap": true, + "sourceMap": true, + "incremental": true, + + // Strict type-checking options + "noImplicitAny": true, + "noImplicitReturns": true, + "noImplicitThis": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedIndexedAccess": false, + "noImplicitOverride": true, + "exactOptionalPropertyTypes": false, + + // Advanced options + "useDefineForClassFields": true, + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + + // Type checking for unused code + "noUnusedLocals": false, + "noUnusedParameters": false, + + // Path mapping + "baseUrl": ".", + "paths": { + "~/*": ["./src/*"], + "@/*": ["./src/*"] + }, + + // Types + "types": [ + "chrome", + "node", + "react", + "react-dom" + ] + }, + "include": [ + "src", + "*.ts", + "*.tsx" + ], + "exclude": [ + "node_modules", + "dist", + "build", + ".plasmo", + "lib", + "**/*.test.ts", + "**/*.test.tsx", + "**/*.spec.ts", + "**/*.spec.tsx" + ] +} \ No newline at end of file diff --git a/packages/wallets/blocknine/tsconfig.cjs.json b/packages/wallets/blocknine/tsconfig.cjs.json new file mode 100644 index 000000000..378a2ea0e --- /dev/null +++ b/packages/wallets/blocknine/tsconfig.cjs.json @@ -0,0 +1,74 @@ +{ + "extends": "./tsconfig.base.json", + "include": [ + "src/**/*", + "contents/**/*", + "background/**/*", + "popup/**/*", + "options/**/*" + ], + "exclude": [ + "node_modules", + "dist", + "build", + ".plasmo", + "**/*.test.ts", + "**/*.test.tsx", + "**/*.spec.ts", + "**/*.spec.tsx" + ], + "compilerOptions": { + "target": "ES2020", + "module": "CommonJS", + "moduleResolution": "node", + "outDir": "lib/cjs", + "rootDir": ".", + "declaration": true, + "declarationMap": true, + "sourceMap": true, + "strict": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": false, + "incremental": true, + "tsBuildInfoFile": ".tsbuildinfo-cjs", + "lib": [ + "DOM", + "DOM.Iterable", + "ES2020" + ], + "types": [ + "chrome", + "node", + "react", + "react-dom" + ], + "jsx": "react-jsx", + "allowJs": true, + "noFallthroughCasesInSwitch": true, + "noImplicitReturns": true, + "noImplicitAny": true, + "noImplicitThis": true, + "noUnusedLocals": false, + "noUnusedParameters": false, + "exactOptionalPropertyTypes": false, + "paths": { + "~/*": ["./src/*"], + "@/*": ["./src/*"], + "~background/*": ["./background/*"], + "~contents/*": ["./contents/*"], + "~popup/*": ["./popup/*"], + "~options/*": ["./options/*"] + } + }, + "ts-node": { + "esm": false, + "compilerOptions": { + "module": "CommonJS" + } + } +} \ No newline at end of file diff --git a/packages/wallets/blocknine/tsconfig.esm.json b/packages/wallets/blocknine/tsconfig.esm.json new file mode 100644 index 000000000..378a2ea0e --- /dev/null +++ b/packages/wallets/blocknine/tsconfig.esm.json @@ -0,0 +1,74 @@ +{ + "extends": "./tsconfig.base.json", + "include": [ + "src/**/*", + "contents/**/*", + "background/**/*", + "popup/**/*", + "options/**/*" + ], + "exclude": [ + "node_modules", + "dist", + "build", + ".plasmo", + "**/*.test.ts", + "**/*.test.tsx", + "**/*.spec.ts", + "**/*.spec.tsx" + ], + "compilerOptions": { + "target": "ES2020", + "module": "CommonJS", + "moduleResolution": "node", + "outDir": "lib/cjs", + "rootDir": ".", + "declaration": true, + "declarationMap": true, + "sourceMap": true, + "strict": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": false, + "incremental": true, + "tsBuildInfoFile": ".tsbuildinfo-cjs", + "lib": [ + "DOM", + "DOM.Iterable", + "ES2020" + ], + "types": [ + "chrome", + "node", + "react", + "react-dom" + ], + "jsx": "react-jsx", + "allowJs": true, + "noFallthroughCasesInSwitch": true, + "noImplicitReturns": true, + "noImplicitAny": true, + "noImplicitThis": true, + "noUnusedLocals": false, + "noUnusedParameters": false, + "exactOptionalPropertyTypes": false, + "paths": { + "~/*": ["./src/*"], + "@/*": ["./src/*"], + "~background/*": ["./background/*"], + "~contents/*": ["./contents/*"], + "~popup/*": ["./popup/*"], + "~options/*": ["./options/*"] + } + }, + "ts-node": { + "esm": false, + "compilerOptions": { + "module": "CommonJS" + } + } +} \ No newline at end of file diff --git a/packages/wallets/blocknine/tsconfig.json b/packages/wallets/blocknine/tsconfig.json new file mode 100644 index 000000000..ca6987ae4 --- /dev/null +++ b/packages/wallets/blocknine/tsconfig.json @@ -0,0 +1,102 @@ +{ + "extends": "./tsconfig.base.json", + "include": [ + "src/**/*", + "contents/**/*", + "background/**/*", + "popup/**/*", + "options/**/*", + "components/**/*", + "utils/**/*", + "types/**/*", + "hooks/**/*", + "store/**/*" + ], + "exclude": [ + "node_modules", + "dist", + "build", + ".plasmo", + "lib", + "**/*.test.ts", + "**/*.test.tsx", + "**/*.spec.ts", + "**/*.spec.tsx" + ], + "compilerOptions": { + "target": "ES2020", + "module": "ESNext", + "moduleResolution": "bundler", + "outDir": "dist", + "rootDir": ".", + "declaration": true, + "declarationDir": "lib/types", + "declarationMap": true, + "sourceMap": true, + "strict": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": false, + "incremental": true, + "tsBuildInfoFile": ".tsbuildinfo", + "lib": [ + "DOM", + "DOM.Iterable", + "ES2020", + "WebWorker" + ], + "types": [ + "chrome", + "node", + "react", + "react-dom", + "webextension-polyfill" + ], + "jsx": "react-jsx", + "allowJs": true, + "checkJs": false, + "noFallthroughCasesInSwitch": true, + "noImplicitReturns": true, + "noImplicitAny": true, + "noImplicitThis": true, + "noUnusedLocals": false, + "noUnusedParameters": false, + "exactOptionalPropertyTypes": false, + "useDefineForClassFields": true, + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "paths": { + "~/*": ["./src/*"], + "@/*": ["./src/*"], + "@/components/*": ["./src/components/*"], + "@/utils/*": ["./src/utils/*"], + "@/types/*": ["./src/types/*"], + "@/hooks/*": ["./src/hooks/*"], + "@/store/*": ["./src/store/*"], + "@/constants/*": ["./src/constants/*"], + "@/services/*": ["./src/services/*"], + "~background/*": ["./background/*"], + "~contents/*": ["./contents/*"], + "~popup/*": ["./popup/*"], + "~options/*": ["./options/*"] + }, + "baseUrl": ".", + "plugins": [ + { + "name": "@plasmo/parcel-transformer-typescript" + } + ] + }, + "ts-node": { + "esm": true, + "compilerOptions": { + "module": "ESNext", + "target": "ES2020" + } + } + +} \ No newline at end of file