@txnlab/use-wallet 0.1.0 → 0.1.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/LICENSE.md +20 -0
- package/README.md +150 -64
- package/dist/cjs/clients/algosigner.d.ts +1 -1
- package/dist/cjs/clients/index.d.ts +107 -1
- package/dist/cjs/clients/kmd.d.ts +32 -0
- package/dist/cjs/clients/walletconnect.d.ts +52 -0
- package/dist/cjs/constants/constants.d.ts +9 -1
- package/dist/cjs/hooks/useConnectWallet.d.ts +10 -2
- package/dist/cjs/hooks/useWallet.d.ts +2 -0
- package/dist/cjs/index.js +9174 -340
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/providers/index.d.ts +2 -0
- package/dist/cjs/providers/kmd.d.ts +2 -0
- package/dist/cjs/providers/walletconnect.d.ts +2 -0
- package/dist/cjs/types/node.d.ts +1 -1
- package/dist/esm/clients/algosigner.d.ts +1 -1
- package/dist/esm/clients/index.d.ts +107 -1
- package/dist/esm/clients/kmd.d.ts +32 -0
- package/dist/esm/clients/walletconnect.d.ts +52 -0
- package/dist/esm/constants/constants.d.ts +9 -1
- package/dist/esm/hooks/useConnectWallet.d.ts +10 -2
- package/dist/esm/hooks/useWallet.d.ts +2 -0
- package/dist/esm/index.js +9152 -331
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/providers/index.d.ts +2 -0
- package/dist/esm/providers/kmd.d.ts +2 -0
- package/dist/esm/providers/walletconnect.d.ts +2 -0
- package/dist/esm/types/node.d.ts +1 -1
- package/dist/index.d.ts +136 -11
- package/package.json +2 -1
package/LICENSE.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2022 TxnLab Inc.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,48 +1,58 @@
|
|
|
1
|
-
|
|
1
|
+
# @TxnLab/use-wallet
|
|
2
2
|
|
|
3
3
|
React hooks for using Algorand compatible wallets with web applications.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Supported Providers
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- [Pera](https://perawallet.app/)
|
|
8
|
+
- [MyAlgo](https://wallet.myalgo.com/home)
|
|
9
|
+
- [Defly](https://defly.app)
|
|
10
|
+
- [AlgoSigner](https://www.purestake.com/technology/algosigner)
|
|
11
|
+
- [Exodus](https://www.exodus.com)
|
|
12
|
+
- [WalletConnect](https://walletconnect.com)
|
|
13
|
+
- [KMD](https://developer.algorand.org/docs/rest-apis/kmd)
|
|
8
14
|
|
|
9
|
-
If you're using Webpack 5 (most newer React projects), you need to install polyfills. Follow [these directions.](#webpack-5-issues)
|
|
10
15
|
|
|
11
|
-
|
|
16
|
+
## Demo
|
|
17
|
+
|
|
18
|
+
Preview a basic implementation in [Storybook](https://txnlab.github.io/use-wallet) or check out [this example](https://github.com/gabrielkuettel/use-wallet-example).
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
⚠️ If you're using Webpack 5 (most newer React projects), you will need to install polyfills. Follow [these directions](#webpack-5).
|
|
23
|
+
|
|
24
|
+
### Yarn
|
|
12
25
|
|
|
13
26
|
```bash
|
|
14
27
|
yarn add @txnlab/use-wallet
|
|
15
28
|
```
|
|
16
29
|
|
|
17
|
-
Install
|
|
30
|
+
Install peer dependencies (if needed)
|
|
18
31
|
|
|
19
32
|
```bash
|
|
20
|
-
|
|
33
|
+
yarn add algosdk @blockshake/defly-connect @perawallet/connect @randlabs/myalgo-connect @walletconnect/client algorand-walletconnect-qrcode-modal
|
|
21
34
|
```
|
|
22
35
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
With Yarn.
|
|
36
|
+
### NPM
|
|
26
37
|
|
|
27
38
|
```bash
|
|
28
|
-
|
|
39
|
+
npm install @txnlab/use-wallet
|
|
29
40
|
```
|
|
30
41
|
|
|
31
|
-
|
|
42
|
+
Install peer dependencies (if needed)
|
|
32
43
|
|
|
33
44
|
```bash
|
|
34
|
-
npm install algosdk @blockshake/defly-connect @perawallet/connect @randlabs/myalgo-connect @walletconnect/client
|
|
45
|
+
npm install algosdk @blockshake/defly-connect @perawallet/connect @randlabs/myalgo-connect @walletconnect/client algorand-walletconnect-qrcode-modal
|
|
35
46
|
```
|
|
36
47
|
|
|
37
|
-
|
|
48
|
+
### Set up the wallet providers
|
|
38
49
|
|
|
39
50
|
```jsx
|
|
40
51
|
import React from "react";
|
|
41
52
|
import { useConnectWallet } from "@txnlab/use-wallet";
|
|
42
53
|
|
|
43
54
|
function App() {
|
|
44
|
-
const { providers, reconnectProviders, accounts, activeAccount } =
|
|
45
|
-
useConnectWallet();
|
|
55
|
+
const { providers, reconnectProviders, accounts, activeAccount } = useConnectWallet();
|
|
46
56
|
|
|
47
57
|
// Reconnect the session when the user returns to the dApp
|
|
48
58
|
React.useEffect(() => {
|
|
@@ -56,7 +66,9 @@ function App() {
|
|
|
56
66
|
console.log("active account", activeAccount);
|
|
57
67
|
});
|
|
58
68
|
|
|
59
|
-
// Map through the providers,
|
|
69
|
+
// Map through the providers,
|
|
70
|
+
// render account information and "connect", "set active", and "disconnect" buttons.
|
|
71
|
+
// Finally, map through the `accounts` property to render a dropdown for each connected account.
|
|
60
72
|
return (
|
|
61
73
|
<div>
|
|
62
74
|
{providers.map((provider) => (
|
|
@@ -75,6 +87,16 @@ function App() {
|
|
|
75
87
|
<button onClick={provider.setActive} disabled={!provider.isConnected || provider.isActive}>
|
|
76
88
|
Set Active
|
|
77
89
|
</button>
|
|
90
|
+
{provider.isActive && provider.accounts.length && (
|
|
91
|
+
<select
|
|
92
|
+
value={provider.activeAccount?.address}
|
|
93
|
+
onChange={(e) => provider.selectAccount(e.target.value)}
|
|
94
|
+
>
|
|
95
|
+
{provider.accounts.map((account) => (
|
|
96
|
+
<option value={account.address}>{account.address}</option>
|
|
97
|
+
))}
|
|
98
|
+
</select>
|
|
99
|
+
)}
|
|
78
100
|
</div>
|
|
79
101
|
</div>
|
|
80
102
|
))}
|
|
@@ -89,9 +111,28 @@ Each provider has two connection states: `isConnected` and `isActive`.
|
|
|
89
111
|
|
|
90
112
|
`isActive` indicates that the provider is currently active and will be used to sign and send transactions when using the `useWallet` hook.
|
|
91
113
|
|
|
92
|
-
|
|
114
|
+
By default, all of the supported providers except for `KMD` are returned by `useConnectWallet`. A configuration object can be passed to determine which providers your dApp suports, as shown below.
|
|
115
|
+
|
|
116
|
+
```jsx
|
|
117
|
+
import { useConnectWallet, PROVIDER_ID } from "@txnlab/use-wallet";
|
|
118
|
+
|
|
119
|
+
...
|
|
120
|
+
|
|
121
|
+
const { providers } = useConnectWallet({
|
|
122
|
+
providers: [
|
|
123
|
+
PROVIDER_ID.MYALGO_WALLET,
|
|
124
|
+
PROVIDER_ID.PERA_WALLET,
|
|
125
|
+
PROVIDER_ID.KMD_WALLET,
|
|
126
|
+
],
|
|
127
|
+
});
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Sign and send transactions
|
|
93
131
|
|
|
94
132
|
```jsx
|
|
133
|
+
import React from "react";
|
|
134
|
+
import { useWallet } from "@txnlab/use-wallet";
|
|
135
|
+
|
|
95
136
|
function Wallet() {
|
|
96
137
|
const { activeAccount, signTransactions, sendTransactions } = useWallet();
|
|
97
138
|
|
|
@@ -151,66 +192,111 @@ function Wallet() {
|
|
|
151
192
|
};
|
|
152
193
|
```
|
|
153
194
|
|
|
154
|
-
|
|
195
|
+
## Environment Variables
|
|
155
196
|
|
|
156
|
-
|
|
197
|
+
By default, wallets will connect to Algorand [MainNet](https://developer.algorand.org/docs/get-details/algorand-networks/mainnet). You can change this behavior by setting the following environment variables:
|
|
157
198
|
|
|
158
|
-
|
|
159
|
-
|
|
199
|
+
* `NODE_NETWORK` (defaults to `mainnet`, and can be set to `testnet`, `betanet`, or the name of a local network running in dev mode)
|
|
200
|
+
|
|
201
|
+
* `NODE_SERVER`
|
|
202
|
+
|
|
203
|
+
* `NODE_TOKEN`
|
|
204
|
+
|
|
205
|
+
* `NODE_PORT`
|
|
206
|
+
|
|
207
|
+
Example `.env` file:
|
|
208
|
+
|
|
209
|
+
```
|
|
210
|
+
NODE_NETWORK=devmodenet
|
|
211
|
+
NODE_SERVER=http://algod
|
|
212
|
+
NODE_TOKEN=xxxxxxxxx
|
|
213
|
+
NODE_PORT=8080
|
|
160
214
|
```
|
|
161
215
|
|
|
162
|
-
|
|
216
|
+
### Create React App and Next.js
|
|
163
217
|
|
|
164
|
-
|
|
165
|
-
|
|
218
|
+
In Create React App and Next.js projects, you'll need to add a prefix to these environment variables to expose them to the browser.
|
|
219
|
+
|
|
220
|
+
* `REACT_APP_` in [Create React App](https://create-react-app.dev/docs/adding-custom-environment-variables/)
|
|
166
221
|
|
|
222
|
+
* `NEXT_PUBLIC_` in [Next.js](https://nextjs.org/docs/basic-features/environment-variables#exposing-environment-variables-to-the-browser)
|
|
223
|
+
|
|
224
|
+
Example `.env` file in Create React App:
|
|
225
|
+
|
|
226
|
+
```
|
|
227
|
+
REACT_APP_NODE_NETWORK=devmodenet
|
|
228
|
+
REACT_APP_NODE_SERVER=http://algod
|
|
229
|
+
REACT_APP_NODE_TOKEN=xxxxxxxxx
|
|
230
|
+
REACT_APP_NODE_PORT=8080
|
|
167
231
|
```
|
|
168
|
-
|
|
232
|
+
|
|
233
|
+
## Webpack 5
|
|
234
|
+
|
|
235
|
+
1. Install `react-app-rewired` and the missing polyfills.
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
yarn add --dev react-app-rewired crypto-browserify stream-browserify assert stream-http https-browserify os-browserify url buffer process
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
2. Create `config-overrides.js` in the root of your project and add the following:
|
|
242
|
+
|
|
243
|
+
```js
|
|
244
|
+
const webpack = require("webpack");
|
|
245
|
+
|
|
246
|
+
module.exports = function override(config) {
|
|
247
|
+
const fallback = config.resolve.fallback || {};
|
|
248
|
+
Object.assign(fallback, {
|
|
249
|
+
crypto: require.resolve("crypto-browserify"),
|
|
250
|
+
stream: require.resolve("stream-browserify"),
|
|
251
|
+
assert: require.resolve("assert"),
|
|
252
|
+
http: require.resolve("stream-http"),
|
|
253
|
+
https: require.resolve("https-browserify"),
|
|
254
|
+
os: require.resolve("os-browserify"),
|
|
255
|
+
url: require.resolve("url"),
|
|
256
|
+
});
|
|
257
|
+
config.resolve.fallback = fallback;
|
|
258
|
+
config.plugins = (config.plugins || []).concat([
|
|
259
|
+
new webpack.ProvidePlugin({
|
|
260
|
+
process: "process/browser",
|
|
261
|
+
Buffer: ["buffer", "Buffer"],
|
|
262
|
+
}),
|
|
263
|
+
]);
|
|
264
|
+
return config;
|
|
265
|
+
};
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
3. Change your scripts in `package.json` to the following:
|
|
269
|
+
|
|
270
|
+
```js
|
|
271
|
+
"scripts": {
|
|
272
|
+
"start": "react-app-rewired start",
|
|
273
|
+
"build": "react-app-rewired build",
|
|
274
|
+
"test": "react-app-rewired test",
|
|
275
|
+
"eject": "react-scripts eject"
|
|
276
|
+
},
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
## Local Development
|
|
280
|
+
|
|
281
|
+
### Install dependencies
|
|
169
282
|
|
|
170
283
|
```bash
|
|
171
|
-
yarn
|
|
284
|
+
yarn install
|
|
172
285
|
```
|
|
173
|
-
### Webpack 5 issues
|
|
174
286
|
|
|
175
|
-
|
|
287
|
+
### Demo in Storybook
|
|
176
288
|
|
|
177
289
|
```bash
|
|
178
|
-
yarn
|
|
179
|
-
```
|
|
290
|
+
yarn storybook
|
|
180
291
|
|
|
181
|
-
Create `config-overrides.js` in the root of your project and add the following:
|
|
182
|
-
|
|
183
|
-
```js
|
|
184
|
-
const webpack = require("webpack");
|
|
185
|
-
|
|
186
|
-
module.exports = function override(config) {
|
|
187
|
-
const fallback = config.resolve.fallback || {};
|
|
188
|
-
Object.assign(fallback, {
|
|
189
|
-
crypto: require.resolve("crypto-browserify"),
|
|
190
|
-
stream: require.resolve("stream-browserify"),
|
|
191
|
-
assert: require.resolve("assert"),
|
|
192
|
-
http: require.resolve("stream-http"),
|
|
193
|
-
https: require.resolve("https-browserify"),
|
|
194
|
-
os: require.resolve("os-browserify"),
|
|
195
|
-
url: require.resolve("url"),
|
|
196
|
-
});
|
|
197
|
-
config.resolve.fallback = fallback;
|
|
198
|
-
config.plugins = (config.plugins || []).concat([
|
|
199
|
-
new webpack.ProvidePlugin({
|
|
200
|
-
process: "process/browser",
|
|
201
|
-
Buffer: ["buffer", "Buffer"],
|
|
202
|
-
}),
|
|
203
|
-
]);
|
|
204
|
-
return config;
|
|
205
|
-
};
|
|
206
292
|
```
|
|
207
293
|
|
|
208
|
-
|
|
294
|
+
### Build the library
|
|
295
|
+
|
|
296
|
+
```bash
|
|
297
|
+
yarn build
|
|
209
298
|
```
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
"eject": "react-scripts eject"
|
|
215
|
-
},
|
|
216
|
-
```
|
|
299
|
+
|
|
300
|
+
## License
|
|
301
|
+
|
|
302
|
+
See the [LICENSE](https://github.com/TxnLab/use-wallet/blob/main/LICENSE.md) file for license rights and limitations (MIT)
|
|
@@ -13,7 +13,7 @@ declare type AlgoSignerTransaction = {
|
|
|
13
13
|
signers?: [];
|
|
14
14
|
multisig?: string;
|
|
15
15
|
};
|
|
16
|
-
declare type SupportedLedgers = "MainNet" | "TestNet" | "BetaNet" |
|
|
16
|
+
declare type SupportedLedgers = "MainNet" | "TestNet" | "BetaNet" | string;
|
|
17
17
|
declare type AlgoSigner = {
|
|
18
18
|
connect: () => Promise<Record<string, never>>;
|
|
19
19
|
accounts: (ledger: {
|
|
@@ -1,5 +1,53 @@
|
|
|
1
1
|
import { PROVIDER_ID } from "../constants";
|
|
2
2
|
export declare const clients: {
|
|
3
|
+
"KMD Wallet": Promise<void | {
|
|
4
|
+
"__#6@#client": import("algosdk").Kmd;
|
|
5
|
+
walletId: string;
|
|
6
|
+
id: PROVIDER_ID;
|
|
7
|
+
provider: import("..").WalletProvider;
|
|
8
|
+
connect(): Promise<import("..").Wallet>;
|
|
9
|
+
disconnect(): Promise<void>;
|
|
10
|
+
reconnect(): Promise<import("..").Wallet | null>;
|
|
11
|
+
requestPassword(): Promise<string>;
|
|
12
|
+
getWalletToken(walletId: string, password: string): Promise<string>;
|
|
13
|
+
releaseToken(token: string): Promise<void>;
|
|
14
|
+
listWallets(): Promise<Record<string, string>>;
|
|
15
|
+
listAccounts(wallet: string, password: string): Promise<import("..").Account[]>;
|
|
16
|
+
signTransactions(activeAddress: string, transactions: Uint8Array[]): Promise<Uint8Array[]>;
|
|
17
|
+
signEncodedTransactions(transactions: import("..").TransactionsArray): Promise<Uint8Array[]>;
|
|
18
|
+
algodClient: import("algosdk").Algodv2;
|
|
19
|
+
algosdk: typeof import("algosdk/dist/types/src/main");
|
|
20
|
+
keepWCAlive: HTMLAudioElement;
|
|
21
|
+
healthCheck(): Promise<{}>;
|
|
22
|
+
getAccountInfo(address: string): Promise<import("..").AccountInfo>;
|
|
23
|
+
getAssets(address: string): Promise<import("..").Asset[]>;
|
|
24
|
+
waitForConfirmation(txId: string, timeout?: number): Promise<{
|
|
25
|
+
"confirmed-round": number;
|
|
26
|
+
"global-state-delta": Record<string, unknown>[];
|
|
27
|
+
"pool-error": string;
|
|
28
|
+
txn: {
|
|
29
|
+
sig: Uint8Array;
|
|
30
|
+
txn: import("..").Txn;
|
|
31
|
+
};
|
|
32
|
+
txId: string;
|
|
33
|
+
}>;
|
|
34
|
+
decodeTransaction: (txn: string, isSigned: boolean) => import("algosdk").Transaction;
|
|
35
|
+
logEncodedTransaction(txn: string, isSigned: boolean): void;
|
|
36
|
+
groupTransactionsBySender(transactions: import("..").TransactionsArray): Record<string, any>;
|
|
37
|
+
sendRawTransactions(transactions: Uint8Array[]): Promise<{
|
|
38
|
+
"confirmed-round": number;
|
|
39
|
+
"global-state-delta": Record<string, unknown>[];
|
|
40
|
+
"pool-error": string;
|
|
41
|
+
txn: {
|
|
42
|
+
sig: Uint8Array;
|
|
43
|
+
txn: import("..").Txn;
|
|
44
|
+
};
|
|
45
|
+
txId: string;
|
|
46
|
+
id: any;
|
|
47
|
+
}>;
|
|
48
|
+
keepWCAliveStart(): void;
|
|
49
|
+
keepWCAliveStop(): void;
|
|
50
|
+
}>;
|
|
3
51
|
"Pera Wallet": Promise<void | {
|
|
4
52
|
"__#1@#client": import("@perawallet/connect/dist/PeraWalletConnect").default;
|
|
5
53
|
id: PROVIDER_ID;
|
|
@@ -109,7 +157,7 @@ export declare const clients: {
|
|
|
109
157
|
"__#3@#client": {
|
|
110
158
|
connect: () => Promise<Record<string, never>>;
|
|
111
159
|
accounts: (ledger: {
|
|
112
|
-
ledger:
|
|
160
|
+
ledger: string;
|
|
113
161
|
}) => Promise<{
|
|
114
162
|
address: string;
|
|
115
163
|
}[]>;
|
|
@@ -297,4 +345,62 @@ export declare const clients: {
|
|
|
297
345
|
keepWCAliveStart(): void;
|
|
298
346
|
keepWCAliveStop(): void;
|
|
299
347
|
}>;
|
|
348
|
+
"Wallet Connect": Promise<void | {
|
|
349
|
+
"__#7@#client": import("@walletconnect/client").default;
|
|
350
|
+
id: PROVIDER_ID;
|
|
351
|
+
provider: import("..").WalletProvider;
|
|
352
|
+
connect(): Promise<import("..").Wallet>;
|
|
353
|
+
reconnect(): Promise<{
|
|
354
|
+
accounts: {
|
|
355
|
+
name: string;
|
|
356
|
+
address: string;
|
|
357
|
+
providerId: PROVIDER_ID;
|
|
358
|
+
}[];
|
|
359
|
+
id: PROVIDER_ID;
|
|
360
|
+
name: string;
|
|
361
|
+
icon: string;
|
|
362
|
+
isWalletConnect: boolean;
|
|
363
|
+
} | null>;
|
|
364
|
+
check(): boolean;
|
|
365
|
+
disconnect(): Promise<void>;
|
|
366
|
+
formatTransactionsArray(transactions: import("..").TransactionsArray): {
|
|
367
|
+
txn: string;
|
|
368
|
+
message?: string | undefined;
|
|
369
|
+
signers?: [] | string[] | undefined;
|
|
370
|
+
}[];
|
|
371
|
+
signTransactions(activeAdress: string, transactions: Uint8Array[]): Promise<Uint8Array[]>;
|
|
372
|
+
signEncodedTransactions(transactions: import("..").TransactionsArray): Promise<Uint8Array[]>;
|
|
373
|
+
algodClient: import("algosdk").Algodv2;
|
|
374
|
+
algosdk: typeof import("algosdk/dist/types/src/main");
|
|
375
|
+
keepWCAlive: HTMLAudioElement;
|
|
376
|
+
healthCheck(): Promise<{}>;
|
|
377
|
+
getAccountInfo(address: string): Promise<import("..").AccountInfo>;
|
|
378
|
+
getAssets(address: string): Promise<import("..").Asset[]>;
|
|
379
|
+
waitForConfirmation(txId: string, timeout?: number): Promise<{
|
|
380
|
+
"confirmed-round": number;
|
|
381
|
+
"global-state-delta": Record<string, unknown>[];
|
|
382
|
+
"pool-error": string;
|
|
383
|
+
txn: {
|
|
384
|
+
sig: Uint8Array;
|
|
385
|
+
txn: import("..").Txn;
|
|
386
|
+
};
|
|
387
|
+
txId: string;
|
|
388
|
+
}>;
|
|
389
|
+
decodeTransaction: (txn: string, isSigned: boolean) => import("algosdk").Transaction;
|
|
390
|
+
logEncodedTransaction(txn: string, isSigned: boolean): void;
|
|
391
|
+
groupTransactionsBySender(transactions: import("..").TransactionsArray): Record<string, any>;
|
|
392
|
+
sendRawTransactions(transactions: Uint8Array[]): Promise<{
|
|
393
|
+
"confirmed-round": number;
|
|
394
|
+
"global-state-delta": Record<string, unknown>[];
|
|
395
|
+
"pool-error": string;
|
|
396
|
+
txn: {
|
|
397
|
+
sig: Uint8Array;
|
|
398
|
+
txn: import("..").Txn;
|
|
399
|
+
};
|
|
400
|
+
txId: string;
|
|
401
|
+
id: any;
|
|
402
|
+
}>;
|
|
403
|
+
keepWCAliveStart(): void;
|
|
404
|
+
keepWCAliveStop(): void;
|
|
405
|
+
}>;
|
|
300
406
|
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Kmd } from "algosdk";
|
|
2
|
+
import BaseWallet from "./base";
|
|
3
|
+
import type { InitAlgodClient } from "./base";
|
|
4
|
+
import { PROVIDER_ID } from "../constants";
|
|
5
|
+
import { providers } from "../providers";
|
|
6
|
+
import type { Account, Wallet, WalletProvider } from "../types";
|
|
7
|
+
import { TransactionsArray } from "../types";
|
|
8
|
+
declare type InitWallet = {
|
|
9
|
+
client: Kmd;
|
|
10
|
+
id: PROVIDER_ID;
|
|
11
|
+
providers: typeof providers;
|
|
12
|
+
};
|
|
13
|
+
declare class KMDWallet extends BaseWallet {
|
|
14
|
+
#private;
|
|
15
|
+
walletId: string;
|
|
16
|
+
id: PROVIDER_ID;
|
|
17
|
+
provider: WalletProvider;
|
|
18
|
+
constructor(initAlgodClient: InitAlgodClient, initWallet: InitWallet);
|
|
19
|
+
static init(): Promise<KMDWallet>;
|
|
20
|
+
connect(): Promise<Wallet>;
|
|
21
|
+
disconnect(): Promise<void>;
|
|
22
|
+
reconnect(): Promise<Wallet | null>;
|
|
23
|
+
requestPassword(): Promise<string>;
|
|
24
|
+
getWalletToken(walletId: string, password: string): Promise<string>;
|
|
25
|
+
releaseToken(token: string): Promise<void>;
|
|
26
|
+
listWallets(): Promise<Record<string, string>>;
|
|
27
|
+
listAccounts(wallet: string, password: string): Promise<Array<Account>>;
|
|
28
|
+
signTransactions(activeAddress: string, transactions: Uint8Array[]): Promise<Uint8Array[]>;
|
|
29
|
+
signEncodedTransactions(transactions: TransactionsArray): Promise<Uint8Array[]>;
|
|
30
|
+
}
|
|
31
|
+
declare const _default: Promise<void | KMDWallet>;
|
|
32
|
+
export default _default;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpful resources:
|
|
3
|
+
* https://developer.algorand.org/docs/get-details/walletconnect/
|
|
4
|
+
*/
|
|
5
|
+
import type WalletConnect from "@walletconnect/client";
|
|
6
|
+
import type { IWalletConnectOptions } from "@walletconnect/types";
|
|
7
|
+
import type QRCodeModal from "algorand-walletconnect-qrcode-modal";
|
|
8
|
+
import { providers } from "../providers";
|
|
9
|
+
import type { WalletProvider, Wallet } from "../types/wallet";
|
|
10
|
+
import { PROVIDER_ID } from "../constants";
|
|
11
|
+
import BaseWallet from "./base";
|
|
12
|
+
import type { InitAlgodClient } from "./base";
|
|
13
|
+
import { TransactionsArray } from "../types/api";
|
|
14
|
+
declare type WalletConnectTransaction = {
|
|
15
|
+
txn: string;
|
|
16
|
+
message?: string;
|
|
17
|
+
signers?: string[] | [];
|
|
18
|
+
};
|
|
19
|
+
declare type InitWallet = {
|
|
20
|
+
id: PROVIDER_ID;
|
|
21
|
+
walletConnect: typeof WalletConnect;
|
|
22
|
+
bridge: string;
|
|
23
|
+
qrcodeModal: typeof QRCodeModal;
|
|
24
|
+
WalletConnectOptions?: IWalletConnectOptions;
|
|
25
|
+
providers: typeof providers;
|
|
26
|
+
};
|
|
27
|
+
declare class WalletConnectClient extends BaseWallet {
|
|
28
|
+
#private;
|
|
29
|
+
id: PROVIDER_ID;
|
|
30
|
+
provider: WalletProvider;
|
|
31
|
+
constructor(initAlgodClient: InitAlgodClient, initWallet: InitWallet);
|
|
32
|
+
static init(): Promise<WalletConnectClient>;
|
|
33
|
+
connect(): Promise<Wallet>;
|
|
34
|
+
reconnect(): Promise<{
|
|
35
|
+
accounts: {
|
|
36
|
+
name: string;
|
|
37
|
+
address: string;
|
|
38
|
+
providerId: PROVIDER_ID;
|
|
39
|
+
}[];
|
|
40
|
+
id: PROVIDER_ID;
|
|
41
|
+
name: string;
|
|
42
|
+
icon: string;
|
|
43
|
+
isWalletConnect: boolean;
|
|
44
|
+
} | null>;
|
|
45
|
+
check(): boolean;
|
|
46
|
+
disconnect(): Promise<void>;
|
|
47
|
+
formatTransactionsArray(transactions: TransactionsArray): WalletConnectTransaction[];
|
|
48
|
+
signTransactions(activeAdress: string, transactions: Uint8Array[]): Promise<Uint8Array[]>;
|
|
49
|
+
signEncodedTransactions(transactions: TransactionsArray): Promise<Uint8Array[]>;
|
|
50
|
+
}
|
|
51
|
+
declare const _default: Promise<void | WalletConnectClient>;
|
|
52
|
+
export default _default;
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
export declare enum PROVIDER_ID {
|
|
2
|
+
KMD_WALLET = "KMD Wallet",
|
|
2
3
|
PERA_WALLET = "Pera Wallet",
|
|
3
4
|
MYALGO_WALLET = "MyAlgo Wallet",
|
|
4
5
|
ALGO_SIGNER = "Algo Signer",
|
|
5
6
|
DEFLY = "Defly",
|
|
6
|
-
EXODUS = "Exodus"
|
|
7
|
+
EXODUS = "Exodus",
|
|
8
|
+
WALLET_CONNECT = "Wallet Connect"
|
|
7
9
|
}
|
|
8
10
|
export declare const NODE_SERVER: string;
|
|
9
11
|
export declare const NODE_TOKEN: string;
|
|
10
12
|
export declare const NODE_PORT: string;
|
|
13
|
+
export declare const NODE_NETWORK: string;
|
|
14
|
+
export declare const KMD_HOST: string;
|
|
15
|
+
export declare const KMD_TOKEN: string;
|
|
16
|
+
export declare const KMD_PORT: string;
|
|
17
|
+
export declare const KMD_WALLET: string;
|
|
18
|
+
export declare const KMD_PASSWORD: string;
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { PROVIDER_ID } from "../types";
|
|
2
|
+
declare type Options = Partial<{
|
|
3
|
+
providers: PROVIDER_ID[];
|
|
4
|
+
}>;
|
|
5
|
+
export default function useConnectWallet(options?: Options): {
|
|
3
6
|
providers: {
|
|
4
7
|
id: PROVIDER_ID;
|
|
5
8
|
name: string;
|
|
6
9
|
icon: string;
|
|
10
|
+
accounts: import("../types").Account[];
|
|
11
|
+
activeAccount: import("../types").Account | null;
|
|
7
12
|
isActive: boolean;
|
|
8
13
|
isConnected: boolean;
|
|
9
14
|
isWalletConnect: boolean;
|
|
@@ -11,12 +16,15 @@ export default function useConnectWallet(): {
|
|
|
11
16
|
disconnect: () => Promise<void>;
|
|
12
17
|
reconnect: () => Promise<void>;
|
|
13
18
|
setActive: () => Promise<void>;
|
|
19
|
+
selectAccount: (account: string) => Promise<void>;
|
|
14
20
|
}[];
|
|
15
21
|
activeAccount: import("../types").Account | null;
|
|
16
22
|
accounts: import("../types").Account[];
|
|
17
23
|
connect: (id: PROVIDER_ID) => Promise<void>;
|
|
18
24
|
reconnect: (id: PROVIDER_ID) => Promise<void>;
|
|
19
25
|
disconnect: (id: PROVIDER_ID) => Promise<void>;
|
|
26
|
+
selectActiveAccount: (providerId: PROVIDER_ID, address: string) => Promise<void>;
|
|
20
27
|
setActive: (id: PROVIDER_ID) => Promise<void>;
|
|
21
28
|
reconnectProviders: () => Promise<void>;
|
|
22
29
|
};
|
|
30
|
+
export {};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import algosdk from "algosdk";
|
|
1
2
|
import { PROVIDER_ID } from "../types";
|
|
2
3
|
import { TransactionsArray } from "../types";
|
|
3
4
|
export { PROVIDER_ID };
|
|
4
5
|
export default function useWallet(): {
|
|
5
6
|
accounts: import("../types").Account[];
|
|
6
7
|
activeAccount: import("../types").Account | null;
|
|
8
|
+
signer: algosdk.TransactionSigner;
|
|
7
9
|
signTransactions: (transactions: Array<Uint8Array>) => Promise<Uint8Array[]>;
|
|
8
10
|
sendTransactions: (transactions: Uint8Array[]) => Promise<import("../types").ConfirmedTxn & {
|
|
9
11
|
id: string;
|