@hashgraph/hedera-wallet-connect 1.0.6 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -65,6 +65,65 @@ reference the [WalletConnect documentation](https://docs.walletconnect.com/2.0/)
65
65
  Upon successfully configuring your dApp and/or wallet to manage WalletConnect sessions, you can
66
66
  use this library’s functions to easily create and handle requests for the Hedera network.
67
67
 
68
+ ### DApps
69
+
70
+ #### Signer
71
+
72
+ This library provides a `DAppSigner` class that implements the `@hashgraph/sdk`'s `Signer`
73
+ interface. You may use the `DAppSigner` class to sign and execute transactions on the Hedera
74
+ network.
75
+
76
+ ##### Get Signer
77
+
78
+ After you have paired your wallet with your dApp, you can get the signer from the
79
+ `DAppConnector` instance:
80
+
81
+ ```javascript
82
+ const signer = dAppConnector.signers[0] // DAppSigner
83
+ ```
84
+
85
+ Or, if multiple signers are available, you can find the signer by account ID:
86
+
87
+ ```javascript
88
+ const signer = dAppConnector.signers.find(
89
+ (signer_) => signer_.getAccountId().toString() === '0.0.100',
90
+ ) // DAppSigner
91
+ ```
92
+
93
+ ##### Sign Transactions
94
+
95
+ ```javascript
96
+ const transaction = new TransferTransaction()
97
+ .addHbarTransfer('0.0.100', new Hbar(-1))
98
+ .addHbarTransfer('0.0.101', new Hbar(1))
99
+
100
+ await transaction.freezeWithSigner(signer)
101
+ const signedTransaction = await signer.signTransaction(transaction)
102
+ ```
103
+
104
+ ##### Sign and Execute Transactions
105
+
106
+ ```javascript
107
+ const transaction = new TransferTransaction()
108
+ .addHbarTransfer('0.0.100', new Hbar(-1))
109
+ .addHbarTransfer('0.0.101', new Hbar(1))
110
+
111
+ await transaction.freezeWithSigner(signer)
112
+ const transactionResponse = await transaction.executeWithSigner(signer)
113
+ ```
114
+
115
+ ##### Sign and verify messages
116
+
117
+ ```javascript
118
+ const text = 'Example message to sign'
119
+ const base64String = btoa(text)
120
+
121
+ const sigMaps = await signer.sign([base64StringToUint8Array(base64String)]) // import { base64StringToUint8Array } from '@hashgraph/hedera-wallet-connect'
122
+
123
+ // sigMaps[0].publicKey also contains the public key of the signer, but you should obtain a PublicKey you can trust from a mirror node.
124
+ const verifiedResult = verifySignerSignature(base64String, sigMaps[0], publicKey) // import { verifySignerSignature } from '@hashgraph/hedera-wallet-connect'
125
+ ```
126
+
68
127
  ### Wallet
69
128
 
70
129
  This library provides a Wallet class that extends the