{"_id":"@dharitri-sdk/wallet-connect-provider","name":"@dharitri-sdk/wallet-connect-provider","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@dharitri-sdk/wallet-connect-provider","version":"0.0.1","description":"Signing provider for dApps: WalletConnect","main":"out/index.js","types":"out/index.d.js","scripts":{"compile":"tsc -p tsconfig.json","pretest":"npm run compile","prepare":"npm run compile"},"author":{"name":"Dharitri"},"license":"MIT","dependencies":{"@walletconnect/sign-client":"2.13.3","@walletconnect/utils":"2.13.3","bech32":"1.1.4"},"devDependencies":{"@types/node":"17.0.23","@walletconnect/types":"2.13.3","esmify":"2.1.1","tslib":"2.4.0","typescript":"4.1.2"},"peerDependencies":{"@dharitri-sdk/core":"0.0.1"},"_id":"@dharitri-sdk/wallet-connect-provider@0.0.1","gitHead":"b7382ef1458aefe39a5476d9d7e5f2cf1533c7b9","_nodeVersion":"18.20.4","_npmVersion":"10.7.0","dist":{"integrity":"sha512-HiAv89GdjXSncBGeF4yp1oTubaIRgsQoFOdYtNncRNre/rVfbYHcG0W9RGWTf0YaSIWXonCE9yZCcY5teq0RxQ==","shasum":"11456157f62b254828ac0fd057958f2ad3a8a6b0","tarball":"https://registry.npmjs.org/@dharitri-sdk/wallet-connect-provider/-/wallet-connect-provider-0.0.1.tgz","fileCount":24,"unpackedSize":86449,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDGa+Fa2useMM+Ah3gIRNIbp3lm9RtbJs2+mCyjjr3C8AiEA1aPkI8KPPYmY+HTryjsNO6g488qT6T2Y+TLYX38eU2o="}]},"_npmUser":{"name":"xfactor-toml","email":"xfactor.toml@gmail.com"},"directories":{},"maintainers":[{"name":"xfactor-toml","email":"xfactor.toml@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/wallet-connect-provider_0.0.1_1730277813986_0.23419447521500603"},"_hasShrinkwrap":false}},"time":{"created":"2024-10-30T08:43:33.899Z","0.0.1":"2024-10-30T08:43:34.191Z","modified":"2024-10-30T08:43:34.490Z"},"maintainers":[{"name":"xfactor-toml","email":"xfactor.toml@gmail.com"}],"description":"Signing provider for dApps: WalletConnect","author":{"name":"Dharitri"},"license":"MIT","readme":"# drt-sdk-js-wallet-connect-provider\n\nSigning provider for dApps: WalletConnect.\n\nDocumentation is available on [docs.dharitri.org](https://docs.dharitri.org/sdk-and-tools/sdk-js/sdk-js-signing-providers/#the-wallet-connect-provider), while an integration example can be found [here](https://github.com/DharitriOne/drt-sdk-js-examples/tree/main/signing-providers).\n\nNote that **we recommend using [sdk-dapp](https://github.com/DharitriOne/drt-sdk-dapp)** instead of integrating the signing provider on your own.\n\nYou can check out the integration with `sdk-dapp` in the [Template dApp](https://github.com/DharitriOne/drt-template-dapp) repository with a live example [here](https://devnet.template-dapp.dharitri.org).\n\n## Distribution\n\n[npm](https://www.npmjs.com/package/@dharitri-sdk/wallet-connect-provider)\n\n## Installation\n\n`sdk-wallet-connect-provider` is delivered via [npm](https://www.npmjs.com/package/@dharitri-sdk/wallet-connect-provider), therefore it can be installed as follows:\n\n```bash\nnpm install @dharitri-sdk/wallet-connect-provider\n```\n\n### Building the library\n\nIn order to compile the library, run the following:\n\n```bash\nnpm install\nnpm run compile\n```\n\n## Project ID\n\nThe WalletConnect 2.0 Signing Provider can use the [WalletConnect Cloud Relay](https://docs.walletconnect.com/2.0/cloud/relay) default address: `wss://relay.walletconnect.com`, in order to be able to access the Cloud Relay you will need to generate a Project ID\n\nThe Project ID can be generated for free here: [https://cloud.walletconnect.com/sign-in](https://cloud.walletconnect.com/sign-in)\n\nThe WalletConnect Project ID grants you access to the WalletConnect Cloud Relay that securely manages communication between the device and the dApp.\n\n## Usage Examples\n\nFor this example we will use the WalletConnect 2.0 provider since 1.0 is [deprecated](https://medium.com/walletconnect/weve-reset-the-clock-on-the-walletconnect-v1-0-shutdown-now-scheduled-for-june-28-2023-ead2d953b595)\n\nFirst, let's see a (simple) way to build a QR dialog using [`qrcode`](https://www.npmjs.com/package/qrcode) (and bootstrap):\n\n```js\nimport QRCode from \"qrcode\";\n\nasync function openModal(connectorUri) {\n  const svg = await QRCode.toString(connectorUri, { type: \"svg\" });\n\n  // The referenced elements must be added to your page, in advance\n  $(\"#MyWalletConnectQRContainer\").html(svg);\n  $(\"#MyWalletConnectModal\").modal(\"show\");\n}\n\nfunction closeModal() {\n  $(\"#MyWalletConnectModal\").modal(\"hide\");\n}\n```\n\nIn order to create an instance of the provider, do as follows:\n\n```js\nimport { WalletConnectV2Provider } from \"@dharitri-sdk/wallet-connect-provider\";\n\n// Generate your own WalletConnect 2 ProjectId here:\n// https://cloud.walletconnect.com/app\nconst projectId = \"9b1a9564f91cb6...\";\n// The default WalletConnect V2 Cloud Relay\nconst relayUrl = \"wss://relay.walletconnect.com\";\n// T for Testnet, D for Devnet and 1 for Mainnet\nconst chainId = \"T\";\n\nconst callbacks = {\n  onClientLogin: async function () {\n    // closeModal() is defined above\n    closeModal();\n    const address = await provider.getAddress();\n    console.log(\"Address:\", address);\n  },\n  onClientLogout: async function () {\n    console.log(\"onClientLogout()\");\n  },\n  onClientEvent: async function (event) {\n    console.log(\"onClientEvent()\", event);\n  },\n};\n\nconst provider = new WalletConnectProvider(\n  callbacks,\n  chainId,\n  relayUrl,\n  projectId\n);\n```\n\n> You can customize the Core WalletConnect functionality by passing `WalletConnectProvider` an optional 5th parameter: `options`\n> For example `metadata` and `storage` for [React Native](https://docs.walletconnect.com/2.0/javascript/guides/react-native) or `{ logger: 'debug' }` for a detailed under the hood logging\n\nBefore performing any operation, make sure to initialize the provider:\n\n```js\nawait provider.init();\n```\n\n### Login and logout\n\nThen, ask the user to login using xPortal on her phone:\n\n```js\nconst { uri, approval } = await provider.connect();\n// connect will provide the uri required for the qr code display\n// and an approval Promise that will return the connection session\n// once the user confirms the login\n\n// openModal() is defined above\nopenModal(uri);\n\n// pass the approval Promise\nawait provider.login({ approval });\n```\n\nThe `login()` method supports the `token` parameter (similar to other providers):\n\n```js\n// A custom identity token (opaque to the signing provider)\nconst authToken = \"aaaabbbbaaaabbbb\";\n\nawait provider.login({ approval, token: authToken });\n\nconsole.log(\"Address:\", provider.address);\nconsole.log(\"Token signature:\", provider.signature);\n```\n\n> The pairing proposal between a wallet and a dapp is made using an [URI](https://docs.walletconnect.com/2.0/specs/clients/core/pairing/pairing-uri). In WalletConnect v2.0 the session and pairing are decoupled from each other. This means that a URI is shared to construct a pairing proposal, and only after settling the pairing the dapp can propose a session using that pairing. In simpler words, the dapp generates an URI that can be used by the wallet for pairing.\n\nOnce the user confirms the login, the `onClientLogin()` callback (declared above) is executed.\n\nIn order to log out, do as follows:\n\n```js\nawait provider.logout();\n```\n\n### Signing transactions\n\nTransactions can be signed as follows:\n\n```js\nimport { Transaction } from \"@dharitri-sdk/core\";\n\nconst firstTransaction = new Transaction({ ... });\nconst secondTransaction = new Transaction({ ... });\n\nawait provider.signTransactions([firstTransaction, secondTransaction]);\n\n// \"firstTransaction\" and \"secondTransaction\" can now be broadcasted.\n```\n\nAlternatively, one can sign a single transaction using the method `signTransaction()`.\n\n### Signing messages\n\nArbitrary messages can be signed as follows:\n\n```js\nimport { SignableMessage } from \"@dharitri-sdk/core\";\n\nconst message = new SignableMessage({\n  message: Buffer.from(\"hello\"),\n});\n\nawait provider.signMessage(message);\n\nconsole.log(message.toJSON());\n```\n\n## Namespaces\n\nDharitri Namespace: `drt`\n\nReference: `1` for `Mainnet`, `T` for `Testnet`, `D` for `Devnet` ( same as the Dharitri chainID )\n\nThe Dharitri namespaces respect the [CAIP Standards](https://namespaces.chainagnostic.org).\n\n### Example of a Dharitri WalletConnect Proposal Namespace\n\n```json\n{\n  \"requiredNamespaces\": {\n    \"drt\": {\n      \"chains\": [\"drt:D\"],\n      \"methods\": [\n        \"drt_signTransaction\",\n        \"drt_signTransactions\",\n        \"drt_signMessage\"\n      ],\n      \"events\": []\n    }\n  }\n}\n```\n\nIf the wallet (or the user) does NOT approve the session, then it is rejected. Otherwise, the wallet responds with a slightly different namespace schema: Session Namespace.\n\n### Example of a Dharitri WalletConnect Session Namespace\n\n```json\n{\n  \"sessionNamespaces\": {\n    \"drt\": {\n      \"chains\": [\"drt:D\"],\n      \"methods\": [\n        \"drt_signTransaction\",\n        \"drt_signTransactions\",\n        \"drt_signMessage\"\n      ],\n      \"events\": [],\n      \"accounts\": [\n        \"drt:D:moa1p47hljmqsetgzc4yqp700z6443r655zfkkg9lfkh0tx2wzyxl8sa5jdjq\"\n      ]\n    }\n  }\n}\n```\n\n### Optional Methods\n\nThe default methods are `drt_signTransaction`, `drt_signTransactions` and `drt_signMessage`.\n\nA detailed documentation for the default methods is available [here](https://specs.walletconnect.com/2.0/blockchain-rpc/dharitri-rpc).\n\nAny additional methods must be passed in the `.connect` step\n\n```js\nconst { uri, approval } = await provider.connect({\n  methods: [\"drt_signNativeAuthToken\", \"drt_cancelAction\"],\n});\n```\n\n- `drt_signLoginToken` - Included by default for now for compatibility reasons. Subject to change as it will be replaced by the `drt_signNativeAuthToken` method soon.\n- `drt_signNativeAuthToken` - Used while logging in with a nativeAuth token, this will offer a special UI based on that format.\n- `drt_cancelAction` - The dApp can trigger a `sendCustomRequest` event that will cancel the current signing flow on the device.\n\n### WalletConnect JSON-RPC Methods\n\nThe available Dharitri JSON-RPC Methods and the structure can be checked on WalletConnect's [Specs](https://specs.walletconnect.com/2.0/blockchain-rpc/dharitri-rpc) and on [Dharitri Docs](https://docs.dharitri.org/integrators/walletconnect-json-rpc-methods).\n","readmeFilename":"README.md"}