@hashgraph/hedera-wallet-connect 0.1.0 → 1.0.2
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/.github/ISSUE_TEMPLATE/bug_report.md +35 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +17 -0
- package/.github/ISSUE_TEMPLATE/hip_820.md +16 -0
- package/.github/dependabot.yml +17 -0
- package/.github/workflows/prettier.yml +28 -0
- package/.github/workflows/publish.yml +35 -0
- package/.github/workflows/test.yml +32 -0
- package/.husky/pre-commit +4 -0
- package/.lintstagedrc.json +5 -0
- package/.prettierignore +3 -0
- package/LICENSE +201 -21
- package/README.md +132 -107
- package/dist/browser-cjs-metafile.json +1 -0
- package/dist/browser-cjs.js +240 -0
- package/dist/browser-esm-metafile.json +1 -0
- package/dist/browser-esm.js +240 -0
- package/dist/node-cjs-metafile.json +1 -0
- package/dist/node-cjs.js +11391 -0
- package/dist/node-esm-metafile.json +1 -0
- package/dist/node-esm.js +11391 -0
- package/jest.config.ts +33 -0
- package/package.json +59 -31
- package/scripts/examples/build.mjs +54 -0
- package/scripts/examples/dev.mjs +54 -0
- package/scripts/lib/build.mjs +40 -0
- package/scripts/lib/context.mjs +71 -0
- package/scripts/lib/watch.mjs +28 -0
- package/typedoc.json +10 -0
- package/.editorconfig +0 -19
- package/.github/workflows/npm-publish.yml +0 -18
- package/lib/esm/Connector.js +0 -81
- package/lib/esm/Connector.js.map +0 -1
- package/lib/esm/DAppConnector.js +0 -118
- package/lib/esm/DAppConnector.js.map +0 -1
- package/lib/esm/ErrorHelper.js +0 -97
- package/lib/esm/ErrorHelper.js.map +0 -1
- package/lib/esm/Utils.js +0 -99
- package/lib/esm/Utils.js.map +0 -1
- package/lib/esm/WCSigner.js +0 -241
- package/lib/esm/WCSigner.js.map +0 -1
- package/lib/esm/WalletConnector.js +0 -203
- package/lib/esm/WalletConnector.js.map +0 -1
- package/lib/esm/index.js +0 -4
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/types/Connector.d.ts +0 -18
- package/lib/esm/types/Connector.d.ts.map +0 -1
- package/lib/esm/types/DAppConnector.d.ts +0 -27
- package/lib/esm/types/DAppConnector.d.ts.map +0 -1
- package/lib/esm/types/ErrorHelper.d.ts +0 -15
- package/lib/esm/types/ErrorHelper.d.ts.map +0 -1
- package/lib/esm/types/Utils.d.ts +0 -39
- package/lib/esm/types/Utils.d.ts.map +0 -1
- package/lib/esm/types/WCSigner.d.ts +0 -33
- package/lib/esm/types/WCSigner.d.ts.map +0 -1
- package/lib/esm/types/WalletConnector.d.ts +0 -21
- package/lib/esm/types/WalletConnector.d.ts.map +0 -1
- package/lib/esm/types/index.d.ts +0 -4
- package/lib/esm/types/index.d.ts.map +0 -1
package/README.md
CHANGED
@@ -1,119 +1,144 @@
|
|
1
|
-
#
|
1
|
+
# Overview
|
2
2
|
|
3
|
-
This
|
3
|
+
This library is the result of Hedera community collaboration to bring Hedera into the
|
4
|
+
WalletConnect ecosystem and vice versa.
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
```
|
6
|
+
The goal of this repository is to be a reference for wallets and dApps integrating the
|
7
|
+
WalletConnect <> Hedera JSON-RPC reference. Additionally, this library is meant to be included
|
8
|
+
in projects supporting WalletConnect and Hedera, providing utility functions useful to
|
9
|
+
validating requests and resposes in both the WalletConnect JSON-RPC context as well as the
|
10
|
+
Hedera context.
|
11
11
|
|
12
|
-
|
13
|
-
1. Import `DAppConnector` from `hedera-wallet-connect` package:
|
14
|
-
```typescript
|
15
|
-
import {DAppConnector} from "hedera-wallet-connect";
|
16
|
-
```
|
17
|
-
2. Create an instance of DAppConnector: `this.dAppConnector = new DAppConnector();`.
|
18
|
-
You can optionally pass application metadata to the constructor.
|
19
|
-
Metadata is a general WalletConnect metadata with provided structure:
|
20
|
-
```typescript
|
21
|
-
type Metadata = {
|
22
|
-
name: string; // Name of your DApp
|
23
|
-
description: string; // Description for your DApp
|
24
|
-
url: string; // URL adress of your DApp
|
25
|
-
icons: string[]; // Icons for displaying in connector
|
26
|
-
}
|
27
|
-
```
|
28
|
-
If not specified metadata will be automatically composed using website meta content.
|
29
|
-
3. Execute `init` method on instance of DAppConnector. You can pass array of custom event names you would like to receive from Wallet (They will be sent by wallet only if supported).
|
30
|
-
```typescript
|
31
|
-
await this.dAppConnector.init(["someEventName"])
|
32
|
-
```
|
33
|
-
4. In order to request connection to the Wallet run `connect` method. You can pass LedgerId to this method in order to select other than MAINNET Ledger.
|
34
|
-
```typescript
|
35
|
-
await this.dAppConnector.connect(LedgerId.TESTNET)
|
36
|
-
```
|
37
|
-
If app is reloading calling `connect` method will try to resume existing session instead of opening new pairing window.
|
38
|
-
5. When connection is established you should request signers array by calling `getSigners` method.
|
39
|
-
```typescript
|
40
|
-
await this.dAppConnector.getSigners()
|
41
|
-
```
|
42
|
-
This will return array of Signer (HIP-338) interfaces for all allowed by Wallet accounts.
|
43
|
-
Use them to execute methods on behalf of wallet account.
|
44
|
-
You can also subscribe to the events sent by the connected Wallet. Use `events$` subscription provided by DAppConnector.
|
45
|
-
```typescript
|
46
|
-
this.dAppConnector.$events.subscribe(
|
47
|
-
({name, data}: {name: string, data: any}) => {
|
48
|
-
console.log(`Event ${name}: ${JSON.stringify(data)}`);
|
49
|
-
})
|
50
|
-
```
|
12
|
+
A few useful resources include:
|
51
13
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
6. Wallet can also send events to the dApp using method `sendEvent`. With name and payload:
|
95
|
-
```typescript
|
96
|
-
await this.walletConnector.sendEvent(name, data);
|
97
|
-
```
|
14
|
+
- [HIP-820](https://hips.hedera.com/hip/hip-820)
|
15
|
+
- [WalletConnect <> Hedera JSON-RPC spec](https://specs.walletconnect.com/2.0/blockchain-rpc/hedera-rpc).
|
16
|
+
|
17
|
+
> WalletConnect brings the ecosystem together by enabling wallets and apps to securely connect
|
18
|
+
> and interact.
|
19
|
+
>
|
20
|
+
> -- <cite> https://walletconnect.com
|
21
|
+
|
22
|
+
Hedera aims to be:
|
23
|
+
|
24
|
+
> The open source public ledger for everyone
|
25
|
+
>
|
26
|
+
> -- <cite> https://hedera.com
|
27
|
+
|
28
|
+
---
|
29
|
+
|
30
|
+
This package managed by the Hedera community and is intended to be a standard for ecosystem
|
31
|
+
wallets and dApp providers utilizing [WalletConnect](https://walletconnect.com) as a their
|
32
|
+
communications protocol. It utilizes the
|
33
|
+
[`@hashgraph/sdk`](https://www.npmjs.com/package/@hashgraph/sdk) and provides functions to
|
34
|
+
facilitate implementing the
|
35
|
+
[WalletConnect <> Hedera JSON-RPC spec](https://specs.walletconnect.com/2.0/blockchain-rpc/hedera-rpc)
|
36
|
+
which has been defined through the collaborative HIP process in
|
37
|
+
[HIP-820](https://hips.hedera.com/hip/hip-820).
|
38
|
+
|
39
|
+
This library facilitates the implementation of the **WalletConnect <> Hedera Spec** which allows
|
40
|
+
wallets and dApps to natively integrate with Hedera. It provides additional, out of network
|
41
|
+
functionality with the `hedera_signMessage` function.
|
42
|
+
|
43
|
+
In short, it uses the Hedera javascript SDK to build transactions, serialize them, send to
|
44
|
+
wallets for processing and return responses back to dApps.
|
45
|
+
|
46
|
+
_Please note, this is distinct from the
|
47
|
+
[Implementation of Ethereum JSON-RPC APIs for Hedera](https://github.com/hashgraph/hedera-json-rpc-relay).
|
48
|
+
At the time of this writing, "the Hedera JSON-RPC relay implementation is in beta, offers
|
49
|
+
limited functionality today, and is only available to developers."_
|
50
|
+
|
51
|
+
_The relay and this library have different intentions and serve different purposes - namely
|
52
|
+
native Hedera integration vs. Ethereum compatability layers to ease developer onboarding for
|
53
|
+
those more familiar with the Ethereum ecosystem._
|
54
|
+
|
55
|
+
## Set up
|
98
56
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
this.
|
57
|
+
To start using WalletConnect, sign up for an account at <https://cloud.walletconnect.com>. You
|
58
|
+
will use your project id when initializing client libraries.
|
59
|
+
|
60
|
+
It is important to understand core WalletConnect concepts when integrating this library. Please
|
61
|
+
reference the [WalletConnect documentation](https://docs.walletconnect.com/2.0/).
|
62
|
+
|
63
|
+
## Usage
|
64
|
+
|
65
|
+
Upon successfully configuring your dApp and/or wallet to manage WalletConnect sessions, you can
|
66
|
+
use this library’s functions to easily create and handle requests for the Hedera network.
|
67
|
+
|
68
|
+
### Wallet
|
69
|
+
|
70
|
+
This library provides a Wallet class that extends the
|
71
|
+
[ Web3Wallet ](https://github.com/WalletConnect/walletconnect-monorepo/tree/v2.0/packages/web3wallet)
|
72
|
+
class provided by WalletConnect class
|
73
|
+
|
74
|
+
#### Event Listeners
|
75
|
+
|
76
|
+
WalletConnect emits various events during a session. Listen to these events to synchronize the
|
77
|
+
state of your application:
|
78
|
+
|
79
|
+
```javascript
|
80
|
+
// Handle pairing proposals
|
81
|
+
signClient.on('session_proposal', (event) => {
|
82
|
+
// Display session proposal to the user and decide to approve or reject
|
83
|
+
})
|
84
|
+
|
85
|
+
// Handle session requests, like signing transactions or messages
|
86
|
+
signClient.on('session_request', (event) => {
|
87
|
+
// Process the session request
|
88
|
+
})
|
89
|
+
|
90
|
+
// Handle session deletions
|
91
|
+
signClient.on('session_delete', (event) => {
|
92
|
+
// React to session termination
|
93
|
+
})
|
103
94
|
```
|
104
|
-
|
105
|
-
|
106
|
-
|
95
|
+
|
96
|
+
#### Pairing with dApps
|
97
|
+
|
98
|
+
Pairing establishes a connection between the wallet and a dApp. Once paired, the dApp can send
|
99
|
+
session requests to the wallet.
|
100
|
+
|
101
|
+
##### a. Pairing via URI
|
102
|
+
|
103
|
+
If a dApp shares a URI for pairing:
|
104
|
+
|
105
|
+
```javascript
|
106
|
+
await signClient.core.pairing.pair({ uri: 'RECEIVED_URI' })
|
107
107
|
```
|
108
108
|
|
109
|
+
Upon successful pairing, the `session_proposal` event will be triggered.
|
110
|
+
|
111
|
+
##### b. Pairing via QR Codes
|
109
112
|
|
110
|
-
|
113
|
+
For a better user experience, dApps often share QR codes that wallets can scan to establish a
|
114
|
+
pairing. Use a QR code scanning library to scan and obtain the URI, then proceed with pairing:
|
111
115
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
getLedgerIdByChainId: (chainId: string) => string;
|
116
|
+
```javascript
|
117
|
+
const scannedUri = '...' // URI obtained from scanning the QR code
|
118
|
+
await signClient.core.pairing.pair({ uri: scannedUri })
|
116
119
|
```
|
117
120
|
|
118
|
-
|
119
|
-
|
121
|
+
#### Handling Session Proposals
|
122
|
+
|
123
|
+
Upon receiving a `session_proposal` event, display the proposal details to the user. Allow them
|
124
|
+
to approve or reject the session:
|
125
|
+
|
126
|
+
##### Handling Session Requests
|
127
|
+
|
128
|
+
Upon receiving a `session_request` event, process the request. For instance, if the dApp
|
129
|
+
requests a transaction to be signed:
|
130
|
+
|
131
|
+
## Demo & docs
|
132
|
+
|
133
|
+
This repository includes a vanilla html/css/javascript implementation with a dApp and wallet
|
134
|
+
example useful for testing and development while integrating WalletConnect and Hedera.
|
135
|
+
|
136
|
+
The docs site utilizes [Typedoc](https://typedoc.org) to generate a library documentation site
|
137
|
+
at <https://wc.hgraph.app/docs/>
|
138
|
+
|
139
|
+
The demo source code lives in `./src/examples/typescript` and is available at
|
140
|
+
<https://wc.hgraph.app>
|
141
|
+
|
142
|
+
## Passing tests
|
143
|
+
|
144
|
+
- `git commit -Ss "the commit message"`
|