@tronweb3/tronwallet-adapter-trust 1.0.0
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 +20 -0
- package/README.md +88 -0
- package/lib/cjs/adapter.js +357 -0
- package/lib/cjs/adapter.js.map +1 -0
- package/lib/cjs/index.js +19 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/package.json +1 -0
- package/lib/cjs/utils.js +24 -0
- package/lib/cjs/utils.js.map +1 -0
- package/lib/esm/adapter.js +353 -0
- package/lib/esm/adapter.js.map +1 -0
- package/lib/esm/index.js +3 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/utils.js +18 -0
- package/lib/esm/utils.js.map +1 -0
- package/lib/types/adapter.d.ts +64 -0
- package/lib/types/adapter.d.ts.map +1 -0
- package/lib/types/index.d.ts +3 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/utils.d.ts +4 -0
- package/lib/types/utils.d.ts.map +1 -0
- package/lib/umd/index.js +1739 -0
- package/lib/umd/index.min.js +1 -0
- package/package.json +54 -0
- package/src/adapter.ts +385 -0
- package/src/index.ts +2 -0
- package/src/utils.ts +20 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
Copyright (c) 2022-Present, tronweb3
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# `@tronweb3/tronwallet-adapter-trust`
|
|
2
|
+
|
|
3
|
+
This package provides an adapter to enable TRON DApps to connect to the [Trust extension](https://chrome.google.com/webstore/detail/trust-wallet/egjidjbpglichdcondbcbdnbeeppgdph).
|
|
4
|
+
|
|
5
|
+
## Demo
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { TrustAdapter } from '@tronweb3/tronwallet-adapter-trust';
|
|
9
|
+
|
|
10
|
+
const adapter = new TrustAdapter();
|
|
11
|
+
|
|
12
|
+
// connect to Trust
|
|
13
|
+
await adapter.connect();
|
|
14
|
+
|
|
15
|
+
// then you can get address
|
|
16
|
+
console.log(adapter.address);
|
|
17
|
+
|
|
18
|
+
// create a send TRX transaction
|
|
19
|
+
const unSignedTransaction = await window.trustwallet.tronLink.tronWeb.transactionBuilder.sendTrx(
|
|
20
|
+
targetAddress,
|
|
21
|
+
100,
|
|
22
|
+
adapter.address
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
// using adapter to sign the transaction
|
|
26
|
+
const signedTransaction = await adapter.signTransaction(unSignedTransaction);
|
|
27
|
+
|
|
28
|
+
// broadcast the transaction
|
|
29
|
+
await window.trustwallet.tronLink.tronWeb.trx.sendRawTransaction(signedTransaction);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Documentation
|
|
33
|
+
|
|
34
|
+
### API
|
|
35
|
+
|
|
36
|
+
- `constructor(config: TrustAdapterConfig)`
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
interface TrustAdapterConfig {
|
|
40
|
+
/**
|
|
41
|
+
* Set if open Wallet's website when wallet is not installed.
|
|
42
|
+
* Default is true.
|
|
43
|
+
*/
|
|
44
|
+
openUrlWhenWalletNotFound?: boolean;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Timeout in millisecond for checking if Trust is supported.
|
|
48
|
+
* Default is 2 * 1000ms
|
|
49
|
+
*/
|
|
50
|
+
checkTimeout?: number;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Set if open Trust app using DeepLink on mobile devices.
|
|
54
|
+
* Default is true.
|
|
55
|
+
*/
|
|
56
|
+
openAppWithDeeplink?: boolean;
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
- `network()` method is supported to get current network information. The type of returned value is `Network` as follows:
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
export enum NetworkType {
|
|
64
|
+
Mainnet = 'Mainnet',
|
|
65
|
+
Shasta = 'Shasta',
|
|
66
|
+
Nile = 'Nile',
|
|
67
|
+
/**
|
|
68
|
+
* When use custom node
|
|
69
|
+
*/
|
|
70
|
+
Unknown = 'Unknown',
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export type Network = {
|
|
74
|
+
networkType: NetworkType;
|
|
75
|
+
chainId: string;
|
|
76
|
+
fullNode: string;
|
|
77
|
+
solidityNode: string;
|
|
78
|
+
eventServer: string;
|
|
79
|
+
};
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Caveats
|
|
83
|
+
|
|
84
|
+
- Only wallet that imported by mnemonic can be used on TRON network.
|
|
85
|
+
- Trust Extension doesn't implement `multiSign()` and `switchChain()`.
|
|
86
|
+
- Trust Extension only support: `accountsChanged`,`connect`,`disconnect` events.
|
|
87
|
+
|
|
88
|
+
For more information about tronwallet adapters, please refer to [`@tronweb3/tronwallet-adapters`](https://github.com/tronweb3/tronwallet-adapter/tree/main/packages/adapters/adapters)
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TrustAdapter = exports.TrustAdapterName = void 0;
|
|
13
|
+
const tronwallet_abstract_adapter_1 = require("@tronweb3/tronwallet-abstract-adapter");
|
|
14
|
+
const tronwallet_adapter_tronlink_1 = require("@tronweb3/tronwallet-adapter-tronlink");
|
|
15
|
+
const utils_js_1 = require("./utils.js");
|
|
16
|
+
exports.TrustAdapterName = 'Trust';
|
|
17
|
+
class TrustAdapter extends tronwallet_abstract_adapter_1.Adapter {
|
|
18
|
+
constructor(config = {}) {
|
|
19
|
+
super();
|
|
20
|
+
this.name = exports.TrustAdapterName;
|
|
21
|
+
this.url = 'https://trustwallet.com';
|
|
22
|
+
this.icon = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTgiIGhlaWdodD0iNjUiIHZpZXdCb3g9IjAgMCA1OCA2NSIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTAgOS4zODk0OUwyOC44OTA3IDBWNjUuMDA0MkM4LjI1NDUgNTYuMzM2OSAwIDM5LjcyNDggMCAzMC4zMzUzVjkuMzg5NDlaIiBmaWxsPSIjMDUwMEZGIi8+CjxwYXRoIGQ9Ik01Ny43ODIyIDkuMzg5NDlMMjguODkxNSAwVjY1LjAwNDJDNDkuNTI3NyA1Ni4zMzY5IDU3Ljc4MjIgMzkuNzI0OCA1Ny43ODIyIDMwLjMzNTNWOS4zODk0OVoiIGZpbGw9InVybCgjcGFpbnQwX2xpbmVhcl8yMjAxXzY5NDIpIi8+CjxkZWZzPgo8bGluZWFyR3JhZGllbnQgaWQ9InBhaW50MF9saW5lYXJfMjIwMV82OTQyIiB4MT0iNTEuMzYxNSIgeTE9Ii00LjE1MjkzIiB4Mj0iMjkuNTM4NCIgeTI9IjY0LjUxNDciIGdyYWRpZW50VW5pdHM9InVzZXJTcGFjZU9uVXNlIj4KPHN0b3Agb2Zmc2V0PSIwLjAyMTEyIiBzdG9wLWNvbG9yPSIjMDAwMEZGIi8+CjxzdG9wIG9mZnNldD0iMC4wNzYyNDIzIiBzdG9wLWNvbG9yPSIjMDA5NEZGIi8+CjxzdG9wIG9mZnNldD0iMC4xNjMwODkiIHN0b3AtY29sb3I9IiM0OEZGOTEiLz4KPHN0b3Agb2Zmc2V0PSIwLjQyMDA0OSIgc3RvcC1jb2xvcj0iIzAwOTRGRiIvPgo8c3RvcCBvZmZzZXQ9IjAuNjgyODg2IiBzdG9wLWNvbG9yPSIjMDAzOEZGIi8+CjxzdG9wIG9mZnNldD0iMC45MDI0NjUiIHN0b3AtY29sb3I9IiMwNTAwRkYiLz4KPC9saW5lYXJHcmFkaWVudD4KPC9kZWZzPgo8L3N2Zz4K';
|
|
23
|
+
this._readyState = (0, tronwallet_abstract_adapter_1.isInBrowser)() ? tronwallet_abstract_adapter_1.WalletReadyState.Loading : tronwallet_abstract_adapter_1.WalletReadyState.NotFound;
|
|
24
|
+
this._state = tronwallet_abstract_adapter_1.AdapterState.Loading;
|
|
25
|
+
this.messageHandler = (e) => {
|
|
26
|
+
var _a, _b, _c;
|
|
27
|
+
const message = (_a = e.data) === null || _a === void 0 ? void 0 : _a.message;
|
|
28
|
+
if (!message) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (message.action === 'accountsChanged') {
|
|
32
|
+
setTimeout(() => {
|
|
33
|
+
var _a;
|
|
34
|
+
const preAddr = this.address || '';
|
|
35
|
+
if ((_a = this._wallet) === null || _a === void 0 ? void 0 : _a.ready) {
|
|
36
|
+
const address = message.data.address;
|
|
37
|
+
this.setAddress(address);
|
|
38
|
+
this.setState(tronwallet_abstract_adapter_1.AdapterState.Connected);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
this.setAddress(null);
|
|
42
|
+
this.setState(tronwallet_abstract_adapter_1.AdapterState.Disconnect);
|
|
43
|
+
}
|
|
44
|
+
const address = this.address || '';
|
|
45
|
+
if (address !== preAddr) {
|
|
46
|
+
this.emit('accountsChanged', this.address || '', preAddr);
|
|
47
|
+
}
|
|
48
|
+
if (!preAddr && this.address) {
|
|
49
|
+
this.emit('connect', this.address);
|
|
50
|
+
}
|
|
51
|
+
else if (preAddr && !this.address) {
|
|
52
|
+
this.emit('disconnect');
|
|
53
|
+
}
|
|
54
|
+
}, 200);
|
|
55
|
+
}
|
|
56
|
+
else if (message.action === 'connect') {
|
|
57
|
+
const isCurConnected = this.connected;
|
|
58
|
+
const preAddress = this.address || '';
|
|
59
|
+
const address = ((_c = (_b = this._wallet.tronWeb) === null || _b === void 0 ? void 0 : _b.defaultAddress) === null || _c === void 0 ? void 0 : _c.base58) || '';
|
|
60
|
+
this.setAddress(address);
|
|
61
|
+
this.setState(tronwallet_abstract_adapter_1.AdapterState.Connected);
|
|
62
|
+
if (!isCurConnected) {
|
|
63
|
+
this.emit('connect', address);
|
|
64
|
+
}
|
|
65
|
+
else if (address !== preAddress) {
|
|
66
|
+
this.emit('accountsChanged', this.address || '', preAddress);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else if (message.action === 'disconnect') {
|
|
70
|
+
this.setAddress(null);
|
|
71
|
+
this.setState(tronwallet_abstract_adapter_1.AdapterState.Disconnect);
|
|
72
|
+
this.emit('disconnect');
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
this._checkPromise = null;
|
|
76
|
+
this._updateWallet = () => {
|
|
77
|
+
var _a, _b;
|
|
78
|
+
let state = this.state;
|
|
79
|
+
let address = this.address;
|
|
80
|
+
if ((0, utils_js_1.supportTrust)()) {
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
82
|
+
this._wallet = window.trustwallet.tronLink;
|
|
83
|
+
this._listenEvent();
|
|
84
|
+
address = ((_b = (_a = this._wallet.tronWeb) === null || _a === void 0 ? void 0 : _a.defaultAddress) === null || _b === void 0 ? void 0 : _b.base58) || null;
|
|
85
|
+
state = this._wallet.ready ? tronwallet_abstract_adapter_1.AdapterState.Connected : tronwallet_abstract_adapter_1.AdapterState.Disconnect;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
this._wallet = null;
|
|
89
|
+
address = null;
|
|
90
|
+
state = tronwallet_abstract_adapter_1.AdapterState.NotFound;
|
|
91
|
+
}
|
|
92
|
+
this.setAddress(address);
|
|
93
|
+
this.setState(state);
|
|
94
|
+
};
|
|
95
|
+
const { checkTimeout = 2 * 1000, openUrlWhenWalletNotFound = true, openAppWithDeeplink = true } = config;
|
|
96
|
+
if (typeof checkTimeout !== 'number') {
|
|
97
|
+
throw new Error('[TrustAdapter] config.checkTimeout should be a number');
|
|
98
|
+
}
|
|
99
|
+
this.config = {
|
|
100
|
+
checkTimeout,
|
|
101
|
+
openAppWithDeeplink,
|
|
102
|
+
openUrlWhenWalletNotFound,
|
|
103
|
+
};
|
|
104
|
+
this._connecting = false;
|
|
105
|
+
this._wallet = null;
|
|
106
|
+
this._address = null;
|
|
107
|
+
if (!(0, tronwallet_abstract_adapter_1.isInBrowser)()) {
|
|
108
|
+
this._readyState = tronwallet_abstract_adapter_1.WalletReadyState.NotFound;
|
|
109
|
+
this.setState(tronwallet_abstract_adapter_1.AdapterState.NotFound);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if ((0, utils_js_1.supportTrust)()) {
|
|
113
|
+
this._readyState = tronwallet_abstract_adapter_1.WalletReadyState.Found;
|
|
114
|
+
this._updateWallet();
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
this._checkWallet().then(() => {
|
|
118
|
+
if (this.connected) {
|
|
119
|
+
this.emit('connect', this.address || '');
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
get address() {
|
|
125
|
+
return this._address;
|
|
126
|
+
}
|
|
127
|
+
get state() {
|
|
128
|
+
return this._state;
|
|
129
|
+
}
|
|
130
|
+
get readyState() {
|
|
131
|
+
return this._readyState;
|
|
132
|
+
}
|
|
133
|
+
get connecting() {
|
|
134
|
+
return this._connecting;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get network information used by Trust.
|
|
138
|
+
* @returns {Network} Current network information.
|
|
139
|
+
*/
|
|
140
|
+
network() {
|
|
141
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
try {
|
|
143
|
+
yield this._checkWallet();
|
|
144
|
+
if (this.state !== tronwallet_abstract_adapter_1.AdapterState.Connected)
|
|
145
|
+
throw new tronwallet_abstract_adapter_1.WalletDisconnectedError();
|
|
146
|
+
const wallet = this._wallet;
|
|
147
|
+
if (!wallet || !wallet.tronWeb)
|
|
148
|
+
throw new tronwallet_abstract_adapter_1.WalletDisconnectedError();
|
|
149
|
+
try {
|
|
150
|
+
return yield (0, tronwallet_adapter_tronlink_1.getNetworkInfoByTronWeb)(wallet.tronWeb);
|
|
151
|
+
}
|
|
152
|
+
catch (e) {
|
|
153
|
+
throw new tronwallet_abstract_adapter_1.WalletGetNetworkError(e === null || e === void 0 ? void 0 : e.message, e);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
catch (e) {
|
|
157
|
+
this.emit('error', e);
|
|
158
|
+
throw e;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
connect() {
|
|
163
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
+
var _a;
|
|
165
|
+
try {
|
|
166
|
+
this.checkIfopenTrustWallet();
|
|
167
|
+
if (this.connected || this.connecting)
|
|
168
|
+
return;
|
|
169
|
+
yield this._checkWallet();
|
|
170
|
+
if (this.state === tronwallet_abstract_adapter_1.AdapterState.NotFound) {
|
|
171
|
+
if (this.config.openUrlWhenWalletNotFound !== false && (0, tronwallet_abstract_adapter_1.isInBrowser)()) {
|
|
172
|
+
window.open(this.url, '_blank');
|
|
173
|
+
}
|
|
174
|
+
throw new tronwallet_abstract_adapter_1.WalletNotFoundError();
|
|
175
|
+
}
|
|
176
|
+
if (!this._wallet)
|
|
177
|
+
return;
|
|
178
|
+
this._connecting = true;
|
|
179
|
+
const wallet = this._wallet;
|
|
180
|
+
try {
|
|
181
|
+
const res = yield wallet.request({ method: 'tron_requestAccounts' });
|
|
182
|
+
if (!res) {
|
|
183
|
+
throw new tronwallet_abstract_adapter_1.WalletConnectionError('Request connect error.');
|
|
184
|
+
}
|
|
185
|
+
if (res.code === 4000) {
|
|
186
|
+
throw new tronwallet_abstract_adapter_1.WalletConnectionError('The same DApp has already initiated a request to connect to trustwallet, and the pop-up window has not been closed.');
|
|
187
|
+
}
|
|
188
|
+
if (res.code === 4001) {
|
|
189
|
+
throw new tronwallet_abstract_adapter_1.WalletConnectionError('The user rejected connection.');
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
throw new tronwallet_abstract_adapter_1.WalletConnectionError(error === null || error === void 0 ? void 0 : error.message, error);
|
|
194
|
+
}
|
|
195
|
+
const address = ((_a = wallet.tronWeb.defaultAddress) === null || _a === void 0 ? void 0 : _a.base58) || '';
|
|
196
|
+
this.setAddress(address);
|
|
197
|
+
this.setState(tronwallet_abstract_adapter_1.AdapterState.Connected);
|
|
198
|
+
this._listenEvent();
|
|
199
|
+
this.connected && this.emit('connect', this.address || '');
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
this.emit('error', error);
|
|
203
|
+
throw error;
|
|
204
|
+
}
|
|
205
|
+
finally {
|
|
206
|
+
this._connecting = false;
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
disconnect() {
|
|
211
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
212
|
+
this._stopListenEvent();
|
|
213
|
+
if (this.state !== tronwallet_abstract_adapter_1.AdapterState.Connected) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
this.setAddress(null);
|
|
217
|
+
this.setState(tronwallet_abstract_adapter_1.AdapterState.Disconnect);
|
|
218
|
+
this.emit('disconnect');
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
signTransaction(transaction, privateKey) {
|
|
222
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
223
|
+
try {
|
|
224
|
+
const wallet = yield this.checkAndGetWallet();
|
|
225
|
+
try {
|
|
226
|
+
return yield wallet.tronWeb.trx.sign(transaction, privateKey);
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
if (error instanceof Error) {
|
|
230
|
+
throw new tronwallet_abstract_adapter_1.WalletSignTransactionError(error.message, error);
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
throw new tronwallet_abstract_adapter_1.WalletSignTransactionError(error, new Error(error));
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
this.emit('error', error);
|
|
239
|
+
throw error;
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
multiSign(transaction, privateKey, permissionId) {
|
|
244
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
245
|
+
try {
|
|
246
|
+
const wallet = yield this.checkAndGetWallet();
|
|
247
|
+
try {
|
|
248
|
+
return yield wallet.tronWeb.trx.multiSign(transaction, privateKey, permissionId);
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
if (error instanceof Error) {
|
|
252
|
+
throw new tronwallet_abstract_adapter_1.WalletSignTransactionError(error.message, error);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
throw new tronwallet_abstract_adapter_1.WalletSignTransactionError(error, new Error(error));
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
catch (error) {
|
|
260
|
+
this.emit('error', error);
|
|
261
|
+
throw error;
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
signMessage(message, privateKey) {
|
|
266
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
267
|
+
try {
|
|
268
|
+
const wallet = yield this.checkAndGetWallet();
|
|
269
|
+
try {
|
|
270
|
+
return yield wallet.tronWeb.trx.signMessageV2(message, privateKey);
|
|
271
|
+
}
|
|
272
|
+
catch (error) {
|
|
273
|
+
if (error instanceof Error) {
|
|
274
|
+
throw new tronwallet_abstract_adapter_1.WalletSignMessageError(error.message, error);
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
throw new tronwallet_abstract_adapter_1.WalletSignMessageError(error, new Error(error));
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
catch (error) {
|
|
282
|
+
this.emit('error', error);
|
|
283
|
+
throw error;
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
checkAndGetWallet() {
|
|
288
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
289
|
+
this.checkIfopenTrustWallet();
|
|
290
|
+
yield this._checkWallet();
|
|
291
|
+
if (this.state !== tronwallet_abstract_adapter_1.AdapterState.Connected)
|
|
292
|
+
throw new tronwallet_abstract_adapter_1.WalletDisconnectedError();
|
|
293
|
+
const wallet = this._wallet;
|
|
294
|
+
if (!wallet || !wallet.tronWeb)
|
|
295
|
+
throw new tronwallet_abstract_adapter_1.WalletDisconnectedError();
|
|
296
|
+
return wallet;
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
_listenEvent() {
|
|
300
|
+
this._stopListenEvent();
|
|
301
|
+
window.addEventListener('message', this.messageHandler);
|
|
302
|
+
}
|
|
303
|
+
_stopListenEvent() {
|
|
304
|
+
window.removeEventListener('message', this.messageHandler);
|
|
305
|
+
}
|
|
306
|
+
checkIfopenTrustWallet() {
|
|
307
|
+
if (this.config.openAppWithDeeplink === false) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
if ((0, utils_js_1.openTrustWallet)()) {
|
|
311
|
+
throw new tronwallet_abstract_adapter_1.WalletNotFoundError();
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* check if wallet exists by interval, the promise only resolve when wallet detected or timeout
|
|
316
|
+
* @returns if trustwallet exists
|
|
317
|
+
*/
|
|
318
|
+
_checkWallet() {
|
|
319
|
+
if (this.readyState === tronwallet_abstract_adapter_1.WalletReadyState.Found) {
|
|
320
|
+
return Promise.resolve(true);
|
|
321
|
+
}
|
|
322
|
+
if (this._checkPromise) {
|
|
323
|
+
return this._checkPromise;
|
|
324
|
+
}
|
|
325
|
+
const interval = 100;
|
|
326
|
+
const maxTimes = Math.floor(this.config.checkTimeout / interval);
|
|
327
|
+
let times = 0, timer;
|
|
328
|
+
this._checkPromise = new Promise((resolve) => {
|
|
329
|
+
const check = () => {
|
|
330
|
+
times++;
|
|
331
|
+
const isSupport = (0, utils_js_1.supportTrust)();
|
|
332
|
+
if (isSupport || times > maxTimes) {
|
|
333
|
+
timer && clearInterval(timer);
|
|
334
|
+
this._readyState = isSupport ? tronwallet_abstract_adapter_1.WalletReadyState.Found : tronwallet_abstract_adapter_1.WalletReadyState.NotFound;
|
|
335
|
+
this._updateWallet();
|
|
336
|
+
this.emit('readyStateChanged', this.readyState);
|
|
337
|
+
resolve(isSupport);
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
timer = setInterval(check, interval);
|
|
341
|
+
check();
|
|
342
|
+
});
|
|
343
|
+
return this._checkPromise;
|
|
344
|
+
}
|
|
345
|
+
setAddress(address) {
|
|
346
|
+
this._address = address;
|
|
347
|
+
}
|
|
348
|
+
setState(state) {
|
|
349
|
+
const preState = this.state;
|
|
350
|
+
if (state !== preState) {
|
|
351
|
+
this._state = state;
|
|
352
|
+
this.emit('stateChanged', state);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
exports.TrustAdapter = TrustAdapter;
|
|
357
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../src/adapter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uFAW+C;AAa/C,uFAAgF;AAChF,yCAA2D;AAwB9C,QAAA,gBAAgB,GAAG,OAA+B,CAAC;AAEhE,MAAa,YAAa,SAAQ,qCAAO;IAcrC,YAAY,SAA6B,EAAE;QACvC,KAAK,EAAE,CAAC;QAdZ,SAAI,GAAG,wBAAgB,CAAC;QACxB,QAAG,GAAG,yBAAyB,CAAC;QAChC,SAAI,GACA,wjCAAwjC,CAAC;QAIrjC,gBAAW,GAAqB,IAAA,yCAAW,GAAE,CAAC,CAAC,CAAC,8CAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,8CAAgB,CAAC,QAAQ,CAAC;QACrG,WAAM,GAAiB,0CAAY,CAAC,OAAO,CAAC;QAgN5C,mBAAc,GAAG,CAAC,CAAuB,EAAE,EAAE;;YACjD,MAAM,OAAO,GAAG,MAAA,CAAC,CAAC,IAAI,0CAAE,OAAO,CAAC;YAChC,IAAI,CAAC,OAAO,EAAE,CAAC;gBACX,OAAO;YACX,CAAC;YACD,IAAI,O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,CAAC,CAAC;YACrC,KAAK,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,aAAa,CAAC;IAC9B,CAAC;IAoBO,UAAU,CAAC,OAAsB;QACrC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC5B,CAAC;IAEO,QAAQ,CAAC,KAAmB;QAChC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC;QAC5B,IAAI,KAAK,KAAK,QAAQ,EAAE,CAAC;YACrB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;YACpB,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;QACrC,CAAC;IACL,CAAC;CACJ;AA7UD,oCA6UC"}
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./adapter.js"), exports);
|
|
18
|
+
__exportStar(require("./utils.js"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,6CAA2B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "commonjs" }
|
package/lib/cjs/utils.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isTrustApp = void 0;
|
|
4
|
+
exports.supportTrust = supportTrust;
|
|
5
|
+
exports.openTrustWallet = openTrustWallet;
|
|
6
|
+
const tronwallet_abstract_adapter_1 = require("@tronweb3/tronwallet-abstract-adapter");
|
|
7
|
+
function supportTrust() {
|
|
8
|
+
return typeof window !== 'undefined' && !!(window.trustwallet && window.trustwallet.tronLink);
|
|
9
|
+
}
|
|
10
|
+
const isTrustApp = function () {
|
|
11
|
+
if (typeof window !== 'undefined' && typeof window.navigator !== 'undefined') {
|
|
12
|
+
return /Trust/i.test(window.navigator.userAgent);
|
|
13
|
+
}
|
|
14
|
+
return false;
|
|
15
|
+
};
|
|
16
|
+
exports.isTrustApp = isTrustApp;
|
|
17
|
+
function openTrustWallet() {
|
|
18
|
+
if (!(0, exports.isTrustApp)() && (0, tronwallet_abstract_adapter_1.isInMobileBrowser)()) {
|
|
19
|
+
window.location.href = 'https://link.trustwallet.com?source=' + encodeURIComponent(window.location.href);
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAEA,oCAEC;AAQD,0CAOC;AAnBD,uFAA0E;AAE1E,SAAgB,YAAY;IACxB,OAAO,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,IAAI,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;AAClG,CAAC;AAEM,MAAM,UAAU,GAAG;IACtB,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,SAAS,KAAK,WAAW,EAAE,CAAC;QAC3E,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IACrD,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AALW,QAAA,UAAU,cAKrB;AACF,SAAgB,eAAe;IAC3B,IAAI,CAAC,IAAA,kBAAU,GAAE,IAAI,IAAA,+CAAiB,GAAE,EAAE,CAAC;QACvC,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,sCAAsC,GAAG,kBAAkB,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACzG,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC"}
|