From ca0186c747c1daae945caf8a1bb0af84b020d299 Mon Sep 17 00:00:00 2001 From: Thiendekaco Date: Mon, 19 Feb 2024 00:32:43 +0700 Subject: [PATCH] Add substrate wallet into wallet module list, and resolve transaction off WalletConnect for substrate account --- packages/core/src/utils.ts | 16 ++++ .../src/views/connect/WalletButton.svelte | 23 ++++- packages/demo/package.json | 4 + packages/demo/src/utils/api/substrateApi.ts | 18 ++-- packages/demo/src/web3-onboard.ts | 24 +++-- packages/injected/src/wallets.ts | 2 +- packages/polkadotJs/package.json | 73 +++++++++++++++ packages/polkadotJs/src/constant.ts | 6 ++ packages/polkadotJs/src/icon.ts | 12 +++ packages/polkadotJs/src/index.ts | 92 +++++++++++++++++++ packages/polkadotJs/tsconfig.json | 16 ++++ packages/subwallet/package.json | 74 +++++++++++++++ packages/subwallet/src/constant.ts | 4 + packages/subwallet/src/icon.ts | 17 ++++ packages/subwallet/src/index.ts | 54 +++++++++++ packages/subwallet/src/types.ts | 6 ++ packages/subwallet/tsconfig.json | 16 ++++ packages/subwalletPolkadot/package.json | 73 +++++++++++++++ packages/subwalletPolkadot/src/constant.ts | 6 ++ packages/subwalletPolkadot/src/icon.ts | 17 ++++ packages/subwalletPolkadot/src/index.ts | 92 +++++++++++++++++++ packages/subwalletPolkadot/tsconfig.json | 16 ++++ packages/talisman/package.json | 74 +++++++++++++++ packages/talisman/src/constant.ts | 6 ++ packages/talisman/src/icon.ts | 13 +++ packages/talisman/src/index.ts | 92 +++++++++++++++++++ packages/talisman/tsconfig.json | 16 ++++ .../src/walletConnect.ts | 1 - 28 files changed, 839 insertions(+), 24 deletions(-) create mode 100644 packages/polkadotJs/package.json create mode 100644 packages/polkadotJs/src/constant.ts create mode 100644 packages/polkadotJs/src/icon.ts create mode 100644 packages/polkadotJs/src/index.ts create mode 100644 packages/polkadotJs/tsconfig.json create mode 100644 packages/subwallet/package.json create mode 100644 packages/subwallet/src/constant.ts create mode 100644 packages/subwallet/src/icon.ts create mode 100644 packages/subwallet/src/index.ts create mode 100644 packages/subwallet/src/types.ts create mode 100644 packages/subwallet/tsconfig.json create mode 100644 packages/subwalletPolkadot/package.json create mode 100644 packages/subwalletPolkadot/src/constant.ts create mode 100644 packages/subwalletPolkadot/src/icon.ts create mode 100644 packages/subwalletPolkadot/src/index.ts create mode 100644 packages/subwalletPolkadot/tsconfig.json create mode 100644 packages/talisman/package.json create mode 100644 packages/talisman/src/constant.ts create mode 100644 packages/talisman/src/icon.ts create mode 100644 packages/talisman/src/index.ts create mode 100644 packages/talisman/tsconfig.json diff --git a/packages/core/src/utils.ts b/packages/core/src/utils.ts index 8c6bba7a7..28cad91a4 100644 --- a/packages/core/src/utils.ts +++ b/packages/core/src/utils.ts @@ -406,6 +406,10 @@ export async function getBalanceSubstrate({ url, data } : clientAxiosProps){ const TypeWalletEvmPlatformByLabel : Record = { + 'SubWallet': { + platform: ['Extension'], + namespace: 'SubWallet' + }, 'Arcana Auth' : { platform: ['Extension', 'WebApp'] }, @@ -528,6 +532,18 @@ const TypeWalletSubstratePlatformByLabel : Record { let txHash_ = ''; - await transferExtrinsic.signAndSend(senderAddress, { signer }, ({ status, txHash }) => { + await transferExtrinsic.signAndSend(senderAddress, { signer }, ({ status, txHash }) => { if (status.isInBlock) { txHash_ = txHash.toString(); console.log(`Completed at block hash #${status.asInBlock.toString()}`); @@ -39,14 +39,14 @@ export class substrateApi { }) return txHash_ } - const txDetails = { - to: recipientAddress, - value: amount - } + const txDetails = { + to: recipientAddress, + value: amount + } - const hash = await sendTransaction(); + const hash = await sendTransaction(); console.log(hash, 'hash') - } catch (e) { + } catch (e) { console.log(':( transaction failed', e); } @@ -65,8 +65,7 @@ export class substrateApi { transactionPayload: payload }; - const signature = (await provider.request(args)) as HexString; - console.log(signature); + const { signature } = (await provider.request(args)) as Pick; return { id: 0, signature }; } } @@ -108,4 +107,3 @@ export class substrateApi { } - diff --git a/packages/demo/src/web3-onboard.ts b/packages/demo/src/web3-onboard.ts index 7c8bd56aa..8b783bce6 100644 --- a/packages/demo/src/web3-onboard.ts +++ b/packages/demo/src/web3-onboard.ts @@ -1,9 +1,13 @@ -import injectedModule from '@subwallet_connect/injected-wallets' -import { init } from '@subwallet_connect/react' -import walletConnectPolkadotModule from '@subwallet_connect/walletconnect-polkadot' +import injectedModule from '@subwallet_connect/injected-wallets'; +import { init } from '@subwallet_connect/react'; +import walletConnectPolkadotModule from '@subwallet_connect/walletconnect-polkadot'; import ledgerPolkadot from "@subwallet_connect/ledgerpolkadot"; -import metamaskSDK from '@subwallet_connect/metamask' +import metamaskSDK from '@subwallet_connect/metamask'; +import subwalletModule from '@subwallet_connect/subwallet'; +import talismanModule from '@subwallet_connect/talisman'; +import polkadot_jsModule from '@subwallet_connect/polkadot_js'; +import subwalletPolkadotModule from '@subwallet_connect/subwallet-polkadot' import {TransactionHandlerReturn} from "@subwallet_connect/core/dist/types"; import { SubWallet } from "../assets"; @@ -40,8 +44,10 @@ const metamaskSDKWallet = metamaskSDK({ } } }) - - +const subwalletWallet = subwalletModule(); +const polkadotWallet = polkadot_jsModule(); +const subwalletPolkadotWalet = subwalletPolkadotModule(); +const talismanWallet = talismanModule(); @@ -107,9 +113,13 @@ export default init({ // An array of wallet modules that you would like to be presented to the user to select from when connecting a wallet. wallets: [ - metamaskSDKWallet, + subwalletWallet, + subwalletPolkadotWalet, walletConnectPolkadot, + metamaskSDKWallet, ledgerPolkadot_, + talismanWallet, + polkadotWallet, injected ], // An array of Chains that your app supports diff --git a/packages/injected/src/wallets.ts b/packages/injected/src/wallets.ts index 4efbccd6e..5be4fbdf1 100644 --- a/packages/injected/src/wallets.ts +++ b/packages/injected/src/wallets.ts @@ -30,7 +30,7 @@ declare const window: CustomWindow const UNSUPPORTED_METHOD = null -const DAPP_NAME = 'SubWallet Connect_v2'; +const DAPP_NAME = 'SubConnect'; function getInjectedInterface( identity: string, diff --git a/packages/polkadotJs/package.json b/packages/polkadotJs/package.json new file mode 100644 index 000000000..4e0fee495 --- /dev/null +++ b/packages/polkadotJs/package.json @@ -0,0 +1,73 @@ +{ + "name": "@subwallet_connect/polkadot_js", + "version": "1.0.0", + "description": "Polkadot{.js} Wallet SDK wallet module for connecting to Web3-Onboard. Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardized spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.", + "keywords": [ + "Ethereum", + "Web3", + "EVM", + "dapp", + "Multichain", + "Wallet", + "Transaction", + "Provider", + "Hardware Wallet", + "Notifications", + "React", + "Svelte", + "Vue", + "Next", + "Nuxt", + "MetaMask", + "Coinbase", + "WalletConnect", + "Ledger", + "Trezor", + "Connect Wallet", + "Ethereum Hooks", + "Blocknative", + "Mempool", + "pending", + "confirmed", + "Injected Wallet", + "Crypto", + "Crypto Wallet", + "Enkrypt", + "SubWallet" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/blocknative/web3-onboard.git", + "directory": "packages/subwallet" + }, + "homepage": "https://www.blocknative.com/onboard", + "bugs": { + "url": "https://github.com/blocknative/web3-onboard/issues" + }, + "module": "dist/index.js", + "browser": "dist/index.js", + "main": "dist/index.js", + "type": "module", + "typings": "dist/index.d.ts", + "files": [ + "dist" + ], + "scripts": { + "build": "tsc", + "dev": "tsc -w", + "type-check": "tsc --noEmit" + }, + "license": "MIT", + "devDependencies": { + "@polkadot/dev": "^0.78.7", + "typescript": "^4.5.5", + "window": "^4.2.7", + "@types/node": "17.0.19" + }, + "dependencies": { + "@polkadot/extension-inject": "^0.46.5", + "@subwallet_connect/common": "^1.0.2", + "events": "^3.3.0" + }, + "author": "" +} diff --git a/packages/polkadotJs/src/constant.ts b/packages/polkadotJs/src/constant.ts new file mode 100644 index 000000000..1e6f81027 --- /dev/null +++ b/packages/polkadotJs/src/constant.ts @@ -0,0 +1,6 @@ +export const DAPP_NAME = 'SubConnect'; + +export const EXTENSION_NAME = 'polkadot-js'; + + +export const URL_INSTALL = 'https://polkadot.js.org/extension' diff --git a/packages/polkadotJs/src/icon.ts b/packages/polkadotJs/src/icon.ts new file mode 100644 index 000000000..858277316 --- /dev/null +++ b/packages/polkadotJs/src/icon.ts @@ -0,0 +1,12 @@ +export default ` + + + + + + + + + + +` diff --git a/packages/polkadotJs/src/index.ts b/packages/polkadotJs/src/index.ts new file mode 100644 index 000000000..34a70780c --- /dev/null +++ b/packages/polkadotJs/src/index.ts @@ -0,0 +1,92 @@ +import type { WalletInit, EIP1193Provider } from '@subwallet_connect/common' +import { SubstrateProvider, WalletInterfaceSubstrate} from "@subwallet_connect/common"; +import { InjectedMetadata, InjectedWindow } from "@polkadot/extension-inject/types"; +import EventEmitter from "events"; +import { Signer } from "@polkadot/types/types"; +import { EXTENSION_NAME, DAPP_NAME, URL_INSTALL} from "./constant.js"; + +function SubWallet (): WalletInit { + if (typeof window === 'undefined') return () => null + + return () => { + + return { + label: 'Polkadot{.js}', + type: 'substrate', + getIcon: async () => (await import('./icon.js')).default, + platforms: ['desktop'], + getInterface: async (): Promise => { + const isInstalled = (extensionName: string) => { + const injectedWindow = window as unknown as Window & InjectedWindow; + const injectedExtension = + injectedWindow?.injectedWeb3[extensionName] + return !!injectedExtension; + } + + if(!isInstalled(EXTENSION_NAME)){ + window.open(URL_INSTALL, '_blank'); + throw new Error('Please Install Polkadot{.js} wallet to use this wallet'); + } + const getRawExtension = (extensionName: string) => { + const injectedWindow = window as unknown as Window & InjectedWindow; + return injectedWindow?.injectedWeb3[extensionName]; + } + const emitter = new EventEmitter() + const provider: SubstrateProvider = { + async enable() { + + try { + const injectedExtension = getRawExtension(EXTENSION_NAME); + + if (!injectedExtension || !injectedExtension.enable) { + return; + } + + const rawExtension = await injectedExtension.enable(DAPP_NAME); + if (!rawExtension) { + return; + } + const accounts = await rawExtension.accounts.get(); + + return { + signer: rawExtension.signer as Signer, + metadata: rawExtension.metadata as InjectedMetadata, + address: accounts.map( + (account: { address: string }) => account.address + ) + } + } catch (e) { + console.log('error', (e as Error).message); + } + }, + async signDummy(address: string, data: string, + signer: Signer) { + if (signer && signer.signRaw) { + return (await signer.signRaw({ + address: address, + data: 'This is dummy message', + type: 'bytes' + })).signature as string; + } + return '0x0' + }, + + async request() {}, + + async disconnect() {}, + + on: emitter.on.bind(emitter), + removeListener: emitter.removeListener.bind(emitter) + + } + + return { + provider + } + }, + } + } + +} + +export default SubWallet diff --git a/packages/polkadotJs/tsconfig.json b/packages/polkadotJs/tsconfig.json new file mode 100644 index 000000000..42d08d48d --- /dev/null +++ b/packages/polkadotJs/tsconfig.json @@ -0,0 +1,16 @@ +{ + "extends": "../../tsconfig.json", + "include": ["src/**/*"], + + "compilerOptions": { + "outDir": "dist", + "rootDir": "src", + "allowSyntheticDefaultImports": true, + "declaration": true, + "declarationDir": "dist", + "paths": { + "*": ["./src/*", "./node_modules/*"] + }, + "typeRoots": ["node_modules/@types"] + } +} diff --git a/packages/subwallet/package.json b/packages/subwallet/package.json new file mode 100644 index 000000000..fe1a296f1 --- /dev/null +++ b/packages/subwallet/package.json @@ -0,0 +1,74 @@ +{ + "name": "@subwallet_connect/subwallet", + "version": "1.0.0", + "description": "SubWallet Wallet SDK wallet module for connecting to Web3-Onboard. Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardized spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.", + "keywords": [ + "Ethereum", + "Web3", + "EVM", + "dapp", + "Multichain", + "Wallet", + "Transaction", + "Provider", + "Hardware Wallet", + "Notifications", + "React", + "Svelte", + "Vue", + "Next", + "Nuxt", + "MetaMask", + "Coinbase", + "WalletConnect", + "Ledger", + "Trezor", + "Connect Wallet", + "Ethereum Hooks", + "Blocknative", + "Mempool", + "pending", + "confirmed", + "Injected Wallet", + "Crypto", + "Crypto Wallet", + "Enkrypt", + "SubWallet" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/blocknative/web3-onboard.git", + "directory": "packages/subwallet" + }, + "homepage": "https://www.blocknative.com/onboard", + "bugs": { + "url": "https://github.com/blocknative/web3-onboard/issues" + }, + "module": "dist/index.js", + "browser": "dist/index.js", + "main": "dist/index.js", + "type": "module", + "typings": "dist/index.d.ts", + "files": [ + "dist" + ], + "scripts": { + "build": "tsc", + "dev": "tsc -w", + "type-check": "tsc --noEmit" + }, + "license": "MIT", + "devDependencies": { + "@ethersproject/providers": "^5.5.0", + "@types/node": "^17.0.21", + "ts-node": "^10.2.1", + "typescript": "^4.5.5", + "window": "^4.2.7" + }, + "dependencies": { + "@polkadot/extension-inject": "^0.46.5", + "@subwallet_connect/common": "^1.0.2", + "events": "^3.3.0" + }, + "author": "" +} diff --git a/packages/subwallet/src/constant.ts b/packages/subwallet/src/constant.ts new file mode 100644 index 000000000..e01e3a662 --- /dev/null +++ b/packages/subwallet/src/constant.ts @@ -0,0 +1,4 @@ + + + +export const URL_INSTALL = 'https://www.subwallet.app/download.html' diff --git a/packages/subwallet/src/icon.ts b/packages/subwallet/src/icon.ts new file mode 100644 index 000000000..b0c2210ba --- /dev/null +++ b/packages/subwallet/src/icon.ts @@ -0,0 +1,17 @@ +export default ` + + + + + + + + + + + + + + + +` diff --git a/packages/subwallet/src/index.ts b/packages/subwallet/src/index.ts new file mode 100644 index 000000000..2c0931b7d --- /dev/null +++ b/packages/subwallet/src/index.ts @@ -0,0 +1,54 @@ +import type { WalletInit, EIP1193Provider } from '@subwallet_connect/common' +import { + createEIP1193Provider, + SimpleEventEmitter, + WalletInterface +} from "@subwallet_connect/common"; +import { CustomWindow } from "./types.js"; +import { URL_INSTALL } from "./constant.js"; +declare const window: CustomWindow + +function SubWallet (): WalletInit { + if (typeof window === 'undefined') return () => null + + return () => { + + return { + label: 'SubWallet', + type: 'evm', + getIcon: async () => (await import('./icon.js')).default, + platforms: ['desktop'], + getInterface: async ():Promise => { + const subwalletExist = window.hasOwnProperty('SubWallet'); + + + if(subwalletExist){ + + const subwalletProvider : EIP1193Provider = window.SubWallet as EIP1193Provider + + const addListener: SimpleEventEmitter['on'] = + subwalletProvider.on.bind(subwalletProvider) + + subwalletProvider.on = (event, func) => { + addListener(event, func) + } + const provider = createEIP1193Provider(subwalletProvider) + + provider.removeListener = (event, func) => {} + + return { + provider + } + }else{ + window.open(URL_INSTALL, '_blank') + throw new Error('Please Install Subwallet wallet to use this wallet') + } + + }, + + } + } + +} + +export default SubWallet diff --git a/packages/subwallet/src/types.ts b/packages/subwallet/src/types.ts new file mode 100644 index 000000000..3f2c92107 --- /dev/null +++ b/packages/subwallet/src/types.ts @@ -0,0 +1,6 @@ +import { ExternalProvider } from "@ethersproject/providers"; + +export interface CustomWindow extends Window { + SubWallet: ExternalProvider + +} diff --git a/packages/subwallet/tsconfig.json b/packages/subwallet/tsconfig.json new file mode 100644 index 000000000..42d08d48d --- /dev/null +++ b/packages/subwallet/tsconfig.json @@ -0,0 +1,16 @@ +{ + "extends": "../../tsconfig.json", + "include": ["src/**/*"], + + "compilerOptions": { + "outDir": "dist", + "rootDir": "src", + "allowSyntheticDefaultImports": true, + "declaration": true, + "declarationDir": "dist", + "paths": { + "*": ["./src/*", "./node_modules/*"] + }, + "typeRoots": ["node_modules/@types"] + } +} diff --git a/packages/subwalletPolkadot/package.json b/packages/subwalletPolkadot/package.json new file mode 100644 index 000000000..6afca1167 --- /dev/null +++ b/packages/subwalletPolkadot/package.json @@ -0,0 +1,73 @@ +{ + "name": "@subwallet_connect/subwallet-polkadot", + "version": "1.0.0", + "description": "SubWallet Wallet SDK wallet module for connecting to Web3-Onboard. Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardized spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.", + "keywords": [ + "Ethereum", + "Web3", + "EVM", + "dapp", + "Multichain", + "Wallet", + "Transaction", + "Provider", + "Hardware Wallet", + "Notifications", + "React", + "Svelte", + "Vue", + "Next", + "Nuxt", + "MetaMask", + "Coinbase", + "WalletConnect", + "Ledger", + "Trezor", + "Connect Wallet", + "Ethereum Hooks", + "Blocknative", + "Mempool", + "pending", + "confirmed", + "Injected Wallet", + "Crypto", + "Crypto Wallet", + "Enkrypt", + "SubWallet" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/blocknative/web3-onboard.git", + "directory": "packages/subwallet" + }, + "homepage": "https://www.blocknative.com/onboard", + "bugs": { + "url": "https://github.com/blocknative/web3-onboard/issues" + }, + "module": "dist/index.js", + "browser": "dist/index.js", + "main": "dist/index.js", + "type": "module", + "typings": "dist/index.d.ts", + "files": [ + "dist" + ], + "scripts": { + "build": "tsc", + "dev": "tsc -w", + "type-check": "tsc --noEmit" + }, + "license": "MIT", + "devDependencies": { + "@polkadot/dev": "^0.78.7", + "typescript": "^4.5.5", + "window": "^4.2.7", + "@types/node": "17.0.19" + }, + "dependencies": { + "@polkadot/extension-inject": "^0.46.5", + "@subwallet_connect/common": "^1.0.2", + "events": "^3.3.0" + }, + "author": "" +} diff --git a/packages/subwalletPolkadot/src/constant.ts b/packages/subwalletPolkadot/src/constant.ts new file mode 100644 index 000000000..dff0297a1 --- /dev/null +++ b/packages/subwalletPolkadot/src/constant.ts @@ -0,0 +1,6 @@ +export const DAPP_NAME = 'SubConnect'; + +export const EXTENSION_NAME = 'subwallet-js'; + + +export const URL_INSTALL = 'https://www.subwallet.app/download.html' diff --git a/packages/subwalletPolkadot/src/icon.ts b/packages/subwalletPolkadot/src/icon.ts new file mode 100644 index 000000000..b0c2210ba --- /dev/null +++ b/packages/subwalletPolkadot/src/icon.ts @@ -0,0 +1,17 @@ +export default ` + + + + + + + + + + + + + + + +` diff --git a/packages/subwalletPolkadot/src/index.ts b/packages/subwalletPolkadot/src/index.ts new file mode 100644 index 000000000..2bc604ad4 --- /dev/null +++ b/packages/subwalletPolkadot/src/index.ts @@ -0,0 +1,92 @@ +import type { WalletInit, EIP1193Provider } from '@subwallet_connect/common' +import { SubstrateProvider, WalletInterfaceSubstrate} from "@subwallet_connect/common"; +import { InjectedMetadata, InjectedWindow } from "@polkadot/extension-inject/types"; +import EventEmitter from "events"; +import { Signer } from "@polkadot/types/types"; +import { EXTENSION_NAME, DAPP_NAME, URL_INSTALL} from "./constant.js"; + +function SubWallet (): WalletInit { + if (typeof window === 'undefined') return () => null + + return () => { + + return { + label: 'SubWallet', + type: 'substrate', + getIcon: async () => (await import('./icon.js')).default, + platforms: ['desktop'], + getInterface: async (): Promise => { + const isInstalled = (extensionName: string) => { + const injectedWindow = window as unknown as Window & InjectedWindow; + const injectedExtension = + injectedWindow?.injectedWeb3[extensionName] + return !!injectedExtension; + } + + if(!isInstalled(EXTENSION_NAME)){ + window.open(URL_INSTALL, '_blank'); + throw new Error('Please Install SubWallet wallet to use this wallet'); + } + const getRawExtension = (extensionName: string) => { + const injectedWindow = window as unknown as Window & InjectedWindow; + return injectedWindow?.injectedWeb3[extensionName]; + } + const emitter = new EventEmitter() + const provider: SubstrateProvider = { + async enable() { + + try { + const injectedExtension = getRawExtension(EXTENSION_NAME); + + if (!injectedExtension || !injectedExtension.enable) { + return; + } + + const rawExtension = await injectedExtension.enable(DAPP_NAME); + if (!rawExtension) { + return; + } + const accounts = await rawExtension.accounts.get(); + + return { + signer: rawExtension.signer as Signer, + metadata: rawExtension.metadata as InjectedMetadata, + address: accounts.map( + (account: { address: string }) => account.address + ) + } + } catch (e) { + console.log('error', (e as Error).message); + } + }, + async signDummy(address: string, data: string, + signer: Signer) { + if (signer && signer.signRaw) { + return (await signer.signRaw({ + address: address, + data: 'This is dummy message', + type: 'bytes' + })).signature as string; + } + return '0x0' + }, + + async request() {}, + + async disconnect() {}, + + on: emitter.on.bind(emitter), + removeListener: emitter.removeListener.bind(emitter) + + } + + return { + provider + } + }, + } + } + +} + +export default SubWallet diff --git a/packages/subwalletPolkadot/tsconfig.json b/packages/subwalletPolkadot/tsconfig.json new file mode 100644 index 000000000..42d08d48d --- /dev/null +++ b/packages/subwalletPolkadot/tsconfig.json @@ -0,0 +1,16 @@ +{ + "extends": "../../tsconfig.json", + "include": ["src/**/*"], + + "compilerOptions": { + "outDir": "dist", + "rootDir": "src", + "allowSyntheticDefaultImports": true, + "declaration": true, + "declarationDir": "dist", + "paths": { + "*": ["./src/*", "./node_modules/*"] + }, + "typeRoots": ["node_modules/@types"] + } +} diff --git a/packages/talisman/package.json b/packages/talisman/package.json new file mode 100644 index 000000000..485b78d66 --- /dev/null +++ b/packages/talisman/package.json @@ -0,0 +1,74 @@ +{ + "name": "@subwallet_connect/talisman", + "version": "1.0.0", + "description": "Talisman Wallet SDK wallet module for connecting to Web3-Onboard. Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardized spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.", + "keywords": [ + "Ethereum", + "Web3", + "EVM", + "dapp", + "Multichain", + "Wallet", + "Transaction", + "Provider", + "Hardware Wallet", + "Notifications", + "React", + "Svelte", + "Vue", + "Next", + "Nuxt", + "MetaMask", + "Coinbase", + "WalletConnect", + "Ledger", + "Trezor", + "Connect Wallet", + "Ethereum Hooks", + "Blocknative", + "Mempool", + "pending", + "confirmed", + "Injected Wallet", + "Crypto", + "Crypto Wallet", + "Enkrypt", + "SubWallet", + "Talisman" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/blocknative/web3-onboard.git", + "directory": "packages/subwallet" + }, + "homepage": "https://www.blocknative.com/onboard", + "bugs": { + "url": "https://github.com/blocknative/web3-onboard/issues" + }, + "module": "dist/index.js", + "browser": "dist/index.js", + "main": "dist/index.js", + "type": "module", + "typings": "dist/index.d.ts", + "files": [ + "dist" + ], + "scripts": { + "build": "tsc", + "dev": "tsc -w", + "type-check": "tsc --noEmit" + }, + "license": "MIT", + "devDependencies": { + "@polkadot/dev": "^0.78.7", + "typescript": "^4.5.5", + "window": "^4.2.7", + "@types/node": "17.0.19" + }, + "dependencies": { + "@polkadot/extension-inject": "^0.46.5", + "@subwallet_connect/common": "^1.0.2", + "events": "^3.3.0" + }, + "author": "" +} diff --git a/packages/talisman/src/constant.ts b/packages/talisman/src/constant.ts new file mode 100644 index 000000000..74c21859b --- /dev/null +++ b/packages/talisman/src/constant.ts @@ -0,0 +1,6 @@ +export const DAPP_NAME = 'SubConnect'; + +export const EXTENSION_NAME = 'talisman'; + + +export const URL_INSTALL = 'https://www.talisman.xyz/download' diff --git a/packages/talisman/src/icon.ts b/packages/talisman/src/icon.ts new file mode 100644 index 000000000..3670e2a0b --- /dev/null +++ b/packages/talisman/src/icon.ts @@ -0,0 +1,13 @@ +export default ` + + + + + + + + + + + +` diff --git a/packages/talisman/src/index.ts b/packages/talisman/src/index.ts new file mode 100644 index 000000000..c35fce939 --- /dev/null +++ b/packages/talisman/src/index.ts @@ -0,0 +1,92 @@ +import type { WalletInit, EIP1193Provider } from '@subwallet_connect/common' +import { SubstrateProvider, WalletInterfaceSubstrate} from "@subwallet_connect/common"; +import { InjectedMetadata, InjectedWindow } from "@polkadot/extension-inject/types"; +import EventEmitter from "events"; +import { Signer } from "@polkadot/types/types"; +import { EXTENSION_NAME, DAPP_NAME, URL_INSTALL} from "./constant.js"; + +function SubWallet (): WalletInit { + if (typeof window === 'undefined') return () => null + + return () => { + + return { + label: 'Talisman', + type: 'substrate', + getIcon: async () => (await import('./icon.js')).default, + platforms: ['desktop'], + getInterface: async (): Promise => { + const isInstalled = (extensionName: string) => { + const injectedWindow = window as unknown as Window & InjectedWindow; + const injectedExtension = + injectedWindow?.injectedWeb3[extensionName] + return !!injectedExtension; + } + + if(!isInstalled(EXTENSION_NAME)){ + window.open(URL_INSTALL, '_blank'); + throw new Error('Please Install Talisman wallet to use this wallet'); + } + const getRawExtension = (extensionName: string) => { + const injectedWindow = window as unknown as Window & InjectedWindow; + return injectedWindow?.injectedWeb3[extensionName]; + } + const emitter = new EventEmitter() + const provider: SubstrateProvider = { + async enable() { + + try { + const injectedExtension = getRawExtension(EXTENSION_NAME); + + if (!injectedExtension || !injectedExtension.enable) { + return; + } + + const rawExtension = await injectedExtension.enable(DAPP_NAME); + if (!rawExtension) { + return; + } + const accounts = await rawExtension.accounts.get(); + + return { + signer: rawExtension.signer as Signer, + metadata: rawExtension.metadata as InjectedMetadata, + address: accounts.map( + (account: { address: string }) => account.address + ) + } + } catch (e) { + console.log('error', (e as Error).message); + } + }, + async signDummy(address: string, data: string, + signer: Signer) { + if (signer && signer.signRaw) { + return (await signer.signRaw({ + address: address, + data: 'This is dummy message', + type: 'bytes' + })).signature as string; + } + return '0x0' + }, + + async request() {}, + + async disconnect() {}, + + on: emitter.on.bind(emitter), + removeListener: emitter.removeListener.bind(emitter) + + } + + return { + provider + } + }, + } + } + +} + +export default SubWallet diff --git a/packages/talisman/tsconfig.json b/packages/talisman/tsconfig.json new file mode 100644 index 000000000..42d08d48d --- /dev/null +++ b/packages/talisman/tsconfig.json @@ -0,0 +1,16 @@ +{ + "extends": "../../tsconfig.json", + "include": ["src/**/*"], + + "compilerOptions": { + "outDir": "dist", + "rootDir": "src", + "allowSyntheticDefaultImports": true, + "declaration": true, + "declarationDir": "dist", + "paths": { + "*": ["./src/*", "./node_modules/*"] + }, + "typeRoots": ["node_modules/@types"] + } +} diff --git a/packages/walletconnectPolkadot/src/walletConnect.ts b/packages/walletconnectPolkadot/src/walletConnect.ts index c74d68cda..eaff2fc22 100644 --- a/packages/walletconnectPolkadot/src/walletConnect.ts +++ b/packages/walletconnectPolkadot/src/walletConnect.ts @@ -11,7 +11,6 @@ import type { } from '@subwallet_connect/common' import {UniversalProviderOpts, RequestArguments} from "@walletconnect/universal-provider"; import { Signer } from '@polkadot/types/types/extrinsic.js' -import polkadotjs from "@subwallet_connect/injected-wallets/dist/icons/polkadotjs"; // methods that require user interaction const methods = [