@manahippo/aptos-wallet-adapter 0.4.4 → 0.4.5
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/dist/WalletAdapters/NightlyWallet.d.ts +52 -0
- package/dist/WalletAdapters/NightlyWallet.d.ts.map +1 -1
- package/dist/WalletAdapters/NightlyWallet.js +270 -230
- package/dist/WalletAdapters/NightlyWallet.js.map +1 -1
- package/dist/WalletAdapters/index.d.ts +1 -0
- package/dist/WalletAdapters/index.d.ts.map +1 -1
- package/dist/WalletAdapters/index.js +1 -1
- package/dist/WalletAdapters/index.js.map +1 -1
- package/package.json +3 -2
- package/src/WalletAdapters/NightlyWallet.ts +285 -260
- package/src/WalletAdapters/index.ts +1 -1
@@ -1,2 +1,54 @@
|
|
1
1
|
export declare const NightlyWallet: () => void;
|
2
|
+
import { PendingTransaction, TransactionPayload } from 'aptos/src/generated';
|
3
|
+
import { AccountKeys, BaseWalletAdapter, WalletName, WalletReadyState } from './BaseAdapter';
|
4
|
+
export declare class AptosPublicKey {
|
5
|
+
private readonly hexString;
|
6
|
+
static default(): AptosPublicKey;
|
7
|
+
address(): string;
|
8
|
+
asUint8Array(): Uint8Array;
|
9
|
+
asString(): string;
|
10
|
+
asPureHex(): string;
|
11
|
+
constructor(hexString: string);
|
12
|
+
}
|
13
|
+
interface AptosNightly {
|
14
|
+
publicKey: AptosPublicKey;
|
15
|
+
constructor(eventMap: Map<string, (data: any) => any>): any;
|
16
|
+
connect(onDisconnect?: () => void, eagerConnect?: boolean): Promise<AptosPublicKey>;
|
17
|
+
disconnect(): Promise<void>;
|
18
|
+
signTransaction: (transaction: TransactionPayload) => Promise<Uint8Array>;
|
19
|
+
signAllTransactions: (transaction: TransactionPayload[]) => Promise<Uint8Array[]>;
|
20
|
+
signMessage(msg: string): Promise<Uint8Array>;
|
21
|
+
}
|
22
|
+
export declare const NightlyWalletName: WalletName<"Nightly">;
|
23
|
+
export interface NightlyWalletAdapterConfig {
|
24
|
+
provider?: AptosNightly;
|
25
|
+
timeout?: number;
|
26
|
+
}
|
27
|
+
export declare class NightlyWalletAdapter extends BaseWalletAdapter {
|
28
|
+
name: WalletName<"Nightly">;
|
29
|
+
url: string;
|
30
|
+
icon: string;
|
31
|
+
protected _provider: AptosNightly | undefined;
|
32
|
+
protected _timeout: number;
|
33
|
+
protected _readyState: WalletReadyState;
|
34
|
+
protected _connecting: boolean;
|
35
|
+
protected _wallet: {
|
36
|
+
publicKey?: string;
|
37
|
+
address?: string;
|
38
|
+
authKey?: string;
|
39
|
+
isConnected: boolean;
|
40
|
+
} | null;
|
41
|
+
constructor({ timeout }?: NightlyWalletAdapterConfig);
|
42
|
+
get publicAccount(): AccountKeys;
|
43
|
+
get connecting(): boolean;
|
44
|
+
get connected(): boolean;
|
45
|
+
get readyState(): WalletReadyState;
|
46
|
+
connect(): Promise<void>;
|
47
|
+
disconnect(): Promise<void>;
|
48
|
+
signTransaction(payload: TransactionPayload): Promise<Uint8Array>;
|
49
|
+
signAllTransaction(payload: TransactionPayload[]): Promise<Uint8Array[]>;
|
50
|
+
signAndSubmitTransaction(tx: TransactionPayload): Promise<PendingTransaction>;
|
51
|
+
signMessage(message: string): Promise<string>;
|
52
|
+
}
|
53
|
+
export {};
|
2
54
|
//# sourceMappingURL=NightlyWallet.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"NightlyWallet.d.ts","sourceRoot":"","sources":["../../src/WalletAdapters/NightlyWallet.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,YAAW,CAAC"}
|
1
|
+
{"version":3,"file":"NightlyWallet.d.ts","sourceRoot":"","sources":["../../src/WalletAdapters/NightlyWallet.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,YAAW,CAAC;AAEtC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAU7E,OAAO,EACL,WAAW,EACX,iBAAiB,EAEjB,UAAU,EACV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AO,EAAE;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE,OAAO,CAAC;KACtB,GAAG,IAAI,CAAC;gBAEG,EAGV,OAAe,EAChB,GAAE,0BAA+B;IAqBlC,IAAI,aAAa,IAAI,WAAW,CAM/B;IAED,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,IAAI,UAAU,IAAI,gBAAgB,CAEjC;IAEK,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAgCxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAgB3B,eAAe,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,UAAU,CAAC;IAsBjE,kBAAkB,CAAC,OAAO,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAsBxE,wBAAwB,CAAC,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAwB7E,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAiBpD"}
|
@@ -1,235 +1,275 @@
|
|
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
32
|
+
});
|
33
|
+
};
|
2
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.NightlyWallet = void 0;
|
35
|
+
exports.NightlyWalletAdapter = exports.NightlyWalletName = exports.AptosPublicKey = exports.NightlyWallet = void 0;
|
4
36
|
const NightlyWallet = () => { };
|
5
37
|
exports.NightlyWallet = NightlyWallet;
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
//
|
43
|
-
//
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
38
|
+
const SHA3 = __importStar(require("js-sha3"));
|
39
|
+
const aptosConstants_1 = require("../config/aptosConstants");
|
40
|
+
const errors_1 = require("../WalletProviders/errors");
|
41
|
+
const BaseAdapter_1 = require("./BaseAdapter");
|
42
|
+
class AptosPublicKey {
|
43
|
+
constructor(hexString) {
|
44
|
+
if (hexString.startsWith('0x')) {
|
45
|
+
this.hexString = hexString;
|
46
|
+
}
|
47
|
+
else {
|
48
|
+
this.hexString = `0x${hexString}`;
|
49
|
+
}
|
50
|
+
}
|
51
|
+
static default() {
|
52
|
+
return new AptosPublicKey('0'.repeat(64));
|
53
|
+
}
|
54
|
+
address() {
|
55
|
+
const hash = SHA3.sha3_256.create();
|
56
|
+
hash.update(Buffer.from(this.asPureHex(), 'hex'));
|
57
|
+
hash.update('\x00');
|
58
|
+
return '0x' + hash.hex();
|
59
|
+
}
|
60
|
+
asUint8Array() {
|
61
|
+
return new Uint8Array(Buffer.from(this.asPureHex(), 'hex'));
|
62
|
+
}
|
63
|
+
asString() {
|
64
|
+
return this.hexString;
|
65
|
+
}
|
66
|
+
asPureHex() {
|
67
|
+
return this.hexString.substr(2);
|
68
|
+
}
|
69
|
+
}
|
70
|
+
exports.AptosPublicKey = AptosPublicKey;
|
71
|
+
exports.NightlyWalletName = 'Nightly';
|
72
|
+
class NightlyWalletAdapter extends BaseAdapter_1.BaseWalletAdapter {
|
73
|
+
constructor({
|
74
|
+
// provider,
|
75
|
+
// network = WalletAdapterNetwork.Mainnet,
|
76
|
+
timeout = 10000 } = {}) {
|
77
|
+
var _a;
|
78
|
+
super();
|
79
|
+
this.name = exports.NightlyWalletName;
|
80
|
+
this.url = 'https://chrome.google.com/webstore/detail/nightly/fiikommddbeccaoicoejoniammnalkfa/related?hl=en&authuser=0';
|
81
|
+
this.icon = 'https://lh3.googleusercontent.com/_feXM9qulMM5w9BYMLzMpZrxW2WlBmdyg3SbETIoRsHdAD9PANnLCEPabC7lzEK0N8fOyyvFkY3746jk8l73zUErxhU=w128-h128-e365-rj-sc0x00ffffff';
|
82
|
+
this._readyState = typeof window === 'undefined' || typeof document === 'undefined'
|
83
|
+
? BaseAdapter_1.WalletReadyState.Unsupported
|
84
|
+
: BaseAdapter_1.WalletReadyState.NotDetected;
|
85
|
+
this._provider = (_a = window.nightly) === null || _a === void 0 ? void 0 : _a.aptos;
|
86
|
+
// this._network = network;
|
87
|
+
this._timeout = timeout;
|
88
|
+
this._connecting = false;
|
89
|
+
this._wallet = null;
|
90
|
+
if (this._readyState !== BaseAdapter_1.WalletReadyState.Unsupported) {
|
91
|
+
(0, BaseAdapter_1.scopePollingDetectionStrategy)(() => {
|
92
|
+
var _a;
|
93
|
+
if ((_a = window.nightly) === null || _a === void 0 ? void 0 : _a.aptos) {
|
94
|
+
this._readyState = BaseAdapter_1.WalletReadyState.Installed;
|
95
|
+
this.emit('readyStateChange', this._readyState);
|
96
|
+
return true;
|
97
|
+
}
|
98
|
+
return false;
|
99
|
+
});
|
100
|
+
}
|
101
|
+
}
|
102
|
+
get publicAccount() {
|
103
|
+
var _a, _b, _c;
|
104
|
+
return {
|
105
|
+
publicKey: ((_a = this._wallet) === null || _a === void 0 ? void 0 : _a.publicKey) || null,
|
106
|
+
address: ((_b = this._wallet) === null || _b === void 0 ? void 0 : _b.address) || null,
|
107
|
+
authKey: ((_c = this._wallet) === null || _c === void 0 ? void 0 : _c.authKey) || null
|
108
|
+
};
|
109
|
+
}
|
110
|
+
get connecting() {
|
111
|
+
return this._connecting;
|
112
|
+
}
|
113
|
+
get connected() {
|
114
|
+
var _a;
|
115
|
+
return !!((_a = this._wallet) === null || _a === void 0 ? void 0 : _a.isConnected);
|
116
|
+
}
|
117
|
+
get readyState() {
|
118
|
+
return this._readyState;
|
119
|
+
}
|
120
|
+
connect() {
|
121
|
+
var _a;
|
122
|
+
return __awaiter(this, void 0, void 0, function* () {
|
123
|
+
try {
|
124
|
+
if (this.connected || this.connecting)
|
125
|
+
return;
|
126
|
+
if (!(this._readyState === BaseAdapter_1.WalletReadyState.Loadable ||
|
127
|
+
this._readyState === BaseAdapter_1.WalletReadyState.Installed))
|
128
|
+
throw new errors_1.WalletNotReadyError();
|
129
|
+
this._connecting = true;
|
130
|
+
const provider = this._provider || ((_a = window.nightly) === null || _a === void 0 ? void 0 : _a.aptos);
|
131
|
+
const publicKey = yield (provider === null || provider === void 0 ? void 0 : provider.connect(() => {
|
132
|
+
this._wallet = null;
|
133
|
+
this.emit('disconnect');
|
134
|
+
}));
|
135
|
+
this._wallet = {
|
136
|
+
publicKey: publicKey === null || publicKey === void 0 ? void 0 : publicKey.asString(),
|
137
|
+
address: publicKey === null || publicKey === void 0 ? void 0 : publicKey.address(),
|
138
|
+
isConnected: true
|
139
|
+
};
|
140
|
+
this.emit('connect', this._wallet.publicKey || '');
|
141
|
+
}
|
142
|
+
catch (error) {
|
143
|
+
this.emit('error', error);
|
144
|
+
throw error;
|
145
|
+
}
|
146
|
+
finally {
|
147
|
+
this._connecting = false;
|
148
|
+
}
|
149
|
+
});
|
150
|
+
}
|
151
|
+
disconnect() {
|
152
|
+
var _a;
|
153
|
+
return __awaiter(this, void 0, void 0, function* () {
|
154
|
+
const wallet = this._wallet;
|
155
|
+
if (wallet) {
|
156
|
+
this._wallet = null;
|
157
|
+
try {
|
158
|
+
const provider = this._provider || ((_a = window.nightly) === null || _a === void 0 ? void 0 : _a.aptos);
|
159
|
+
yield (provider === null || provider === void 0 ? void 0 : provider.disconnect());
|
160
|
+
}
|
161
|
+
catch (error) {
|
162
|
+
this.emit('error', new errors_1.WalletDisconnectionError(error === null || error === void 0 ? void 0 : error.message, error));
|
163
|
+
}
|
164
|
+
}
|
165
|
+
this.emit('disconnect');
|
166
|
+
});
|
167
|
+
}
|
168
|
+
signTransaction(payload) {
|
169
|
+
var _a;
|
170
|
+
return __awaiter(this, void 0, void 0, function* () {
|
171
|
+
try {
|
172
|
+
const wallet = this._wallet;
|
173
|
+
if (!wallet)
|
174
|
+
throw new errors_1.WalletNotConnectedError();
|
175
|
+
try {
|
176
|
+
const provider = this._provider || ((_a = window.nightly) === null || _a === void 0 ? void 0 : _a.aptos);
|
177
|
+
const response = yield (provider === null || provider === void 0 ? void 0 : provider.signTransaction(payload));
|
178
|
+
if (response) {
|
179
|
+
return response;
|
180
|
+
}
|
181
|
+
else {
|
182
|
+
throw new Error('Transaction failed');
|
183
|
+
}
|
184
|
+
}
|
185
|
+
catch (error) {
|
186
|
+
throw new errors_1.WalletSignTransactionError(error === null || error === void 0 ? void 0 : error.message, error);
|
187
|
+
}
|
188
|
+
}
|
189
|
+
catch (error) {
|
190
|
+
this.emit('error', error);
|
191
|
+
throw error;
|
192
|
+
}
|
193
|
+
});
|
194
|
+
}
|
195
|
+
signAllTransaction(payload) {
|
196
|
+
var _a;
|
197
|
+
return __awaiter(this, void 0, void 0, function* () {
|
198
|
+
try {
|
199
|
+
const wallet = this._wallet;
|
200
|
+
if (!wallet)
|
201
|
+
throw new errors_1.WalletNotConnectedError();
|
202
|
+
try {
|
203
|
+
const provider = this._provider || ((_a = window.nightly) === null || _a === void 0 ? void 0 : _a.aptos);
|
204
|
+
const response = yield (provider === null || provider === void 0 ? void 0 : provider.signAllTransactions(payload));
|
205
|
+
if (response) {
|
206
|
+
return response;
|
207
|
+
}
|
208
|
+
else {
|
209
|
+
throw new Error('Transaction failed');
|
210
|
+
}
|
211
|
+
}
|
212
|
+
catch (error) {
|
213
|
+
throw new errors_1.WalletSignTransactionError(error === null || error === void 0 ? void 0 : error.message, error);
|
214
|
+
}
|
215
|
+
}
|
216
|
+
catch (error) {
|
217
|
+
this.emit('error', error);
|
218
|
+
throw error;
|
219
|
+
}
|
220
|
+
});
|
221
|
+
}
|
222
|
+
signAndSubmitTransaction(tx) {
|
223
|
+
var _a;
|
224
|
+
return __awaiter(this, void 0, void 0, function* () {
|
225
|
+
try {
|
226
|
+
const wallet = this._wallet;
|
227
|
+
if (!wallet)
|
228
|
+
throw new errors_1.WalletNotConnectedError();
|
229
|
+
try {
|
230
|
+
const provider = this._provider || ((_a = window.nightly) === null || _a === void 0 ? void 0 : _a.aptos);
|
231
|
+
const response = yield (provider === null || provider === void 0 ? void 0 : provider.signTransaction(tx));
|
232
|
+
const result = yield aptosConstants_1.aptosClient.submitSignedBCSTransaction(response);
|
233
|
+
if (response) {
|
234
|
+
return result;
|
235
|
+
}
|
236
|
+
else {
|
237
|
+
throw new Error('Transaction failed');
|
238
|
+
}
|
239
|
+
}
|
240
|
+
catch (error) {
|
241
|
+
const errMsg = error instanceof Error ? error.message : error.response.data.message;
|
242
|
+
throw new errors_1.WalletSignTransactionError(errMsg);
|
243
|
+
}
|
244
|
+
}
|
245
|
+
catch (error) {
|
246
|
+
this.emit('error', error);
|
247
|
+
throw error;
|
248
|
+
}
|
249
|
+
});
|
250
|
+
}
|
251
|
+
signMessage(message) {
|
252
|
+
return __awaiter(this, void 0, void 0, function* () {
|
253
|
+
try {
|
254
|
+
const wallet = this._wallet;
|
255
|
+
const provider = this._provider || window.nightly.aptos;
|
256
|
+
if (!wallet || !provider)
|
257
|
+
throw new errors_1.WalletNotConnectedError();
|
258
|
+
const response = yield (provider === null || provider === void 0 ? void 0 : provider.signMessage(message));
|
259
|
+
if (response) {
|
260
|
+
return Buffer.from(response).toString('hex');
|
261
|
+
}
|
262
|
+
else {
|
263
|
+
throw new Error('Sign Message failed');
|
264
|
+
}
|
265
|
+
}
|
266
|
+
catch (error) {
|
267
|
+
const errMsg = error.message;
|
268
|
+
this.emit('error', new errors_1.WalletSignMessageError(errMsg));
|
269
|
+
throw error;
|
270
|
+
}
|
271
|
+
});
|
272
|
+
}
|
273
|
+
}
|
274
|
+
exports.NightlyWalletAdapter = NightlyWalletAdapter;
|
235
275
|
//# sourceMappingURL=NightlyWallet.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"NightlyWallet.js","sourceRoot":"","sources":["../../src/WalletAdapters/NightlyWallet.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"NightlyWallet.js","sourceRoot":"","sources":["../../src/WalletAdapters/NightlyWallet.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAO,MAAM,aAAa,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AAAzB,QAAA,aAAa,iBAAY;AAGtC,8CAAgC;AAChC,6DAAuD;AACvD,sDAMmC;AACnC,+CAMuB;AAEvB,MAAa,cAAc;IA0BzB,YAAY,SAAiB;QAC3B,IAAI,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;YAC9B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;SAC5B;aAAM;YACL,IAAI,CAAC,SAAS,GAAG,KAAK,SAAS,EAAE,CAAC;SACnC;IACH,CAAC;IA7BD,MAAM,CAAC,OAAO;QACZ,OAAO,IAAI,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED,OAAO;QACL,MAAM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AM,IAAI,mCAA0B,CAAC,MAAM,CAAC,CAAC;iBAC9C;aACF;YAAC,OAAO,KAAU,EAAE;gBACnB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;gBAC1B,MAAM,KAAK,CAAC;aACb;;KACF;IAEK,WAAW,CAAC,OAAe;;YAC/B,IAAI;gBACF,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC;gBAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;gBACxD,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ;oBAAE,MAAM,IAAI,gCAAuB,EAAE,CAAC;gBAC9D,MAAM,QAAQ,GAAG,MAAM,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,WAAW,CAAC,OAAO,CAAC,CAAA,CAAC;gBACtD,IAAI,QAAQ,EAAE;oBACZ,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;iBAC9C;qBAAM;oBACL,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;iBACxC;aACF;YAAC,OAAO,KAAU,EAAE;gBACnB,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC;gBAC7B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,+BAAsB,CAAC,MAAM,CAAC,CAAC,CAAC;gBACvD,MAAM,KAAK,CAAC;aACb;QACH,CAAC;KAAA;CACF;AA9MD,oDA8MC"}
|
@@ -5,6 +5,7 @@ export * from './HippoWallet';
|
|
5
5
|
export * from './MartianWallet';
|
6
6
|
export * from './FewchaWallet';
|
7
7
|
export * from './PontemWallet';
|
8
|
+
export * from './NightlyWallet';
|
8
9
|
export * from './RiseWallet';
|
9
10
|
export * from './SpikaWallet';
|
10
11
|
export * from './HyperPayWallet';
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/WalletAdapters/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/WalletAdapters/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
|
@@ -21,7 +21,7 @@ __exportStar(require("./HippoWallet"), exports);
|
|
21
21
|
__exportStar(require("./MartianWallet"), exports);
|
22
22
|
__exportStar(require("./FewchaWallet"), exports);
|
23
23
|
__exportStar(require("./PontemWallet"), exports);
|
24
|
-
|
24
|
+
__exportStar(require("./NightlyWallet"), exports);
|
25
25
|
__exportStar(require("./RiseWallet"), exports);
|
26
26
|
__exportStar(require("./SpikaWallet"), exports);
|
27
27
|
__exportStar(require("./HyperPayWallet"), exports);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/WalletAdapters/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,gDAA8B;AAC9B,yDAAuC;AACvC,gDAA8B;AAC9B,kDAAgC;AAChC,iDAA+B;AAC/B,iDAA+B;AAC/B,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/WalletAdapters/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,gDAA8B;AAC9B,yDAAuC;AACvC,gDAA8B;AAC9B,kDAAgC;AAChC,iDAA+B;AAC/B,iDAA+B;AAC/B,kDAAgC;AAChC,+CAA6B;AAC7B,gDAA8B;AAC9B,mDAAiC;AACjC,iDAA+B;AAC/B,8CAA4B"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@manahippo/aptos-wallet-adapter",
|
3
|
-
"version": "0.4.
|
3
|
+
"version": "0.4.5",
|
4
4
|
"main": "dist/index.js",
|
5
5
|
"typings": "dist/index.d.ts",
|
6
6
|
"files": [
|
@@ -30,6 +30,7 @@
|
|
30
30
|
"@types/node": "^18.7.6",
|
31
31
|
"@types/react": "^18.0.17",
|
32
32
|
"aptos": "^1.3.14",
|
33
|
-
"eventemitter3": "^4.0.7"
|
33
|
+
"eventemitter3": "^4.0.7",
|
34
|
+
"js-sha3": "^0.8.0"
|
34
35
|
}
|
35
36
|
}
|
@@ -1,261 +1,286 @@
|
|
1
1
|
export const NightlyWallet = () => {};
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
//
|
110
|
-
//
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
//
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
2
|
+
|
3
|
+
import { PendingTransaction, TransactionPayload } from 'aptos/src/generated';
|
4
|
+
import * as SHA3 from 'js-sha3';
|
5
|
+
import { aptosClient } from '../config/aptosConstants';
|
6
|
+
import {
|
7
|
+
WalletDisconnectionError,
|
8
|
+
WalletNotConnectedError,
|
9
|
+
WalletNotReadyError,
|
10
|
+
WalletSignMessageError,
|
11
|
+
WalletSignTransactionError
|
12
|
+
} from '../WalletProviders/errors';
|
13
|
+
import {
|
14
|
+
AccountKeys,
|
15
|
+
BaseWalletAdapter,
|
16
|
+
scopePollingDetectionStrategy,
|
17
|
+
WalletName,
|
18
|
+
WalletReadyState
|
19
|
+
} from './BaseAdapter';
|
20
|
+
|
21
|
+
export class AptosPublicKey {
|
22
|
+
private readonly hexString: string;
|
23
|
+
|
24
|
+
static default() {
|
25
|
+
return new AptosPublicKey('0'.repeat(64));
|
26
|
+
}
|
27
|
+
|
28
|
+
address() {
|
29
|
+
const hash = SHA3.sha3_256.create();
|
30
|
+
hash.update(Buffer.from(this.asPureHex(), 'hex'));
|
31
|
+
hash.update('\x00');
|
32
|
+
return '0x' + hash.hex();
|
33
|
+
}
|
34
|
+
|
35
|
+
asUint8Array() {
|
36
|
+
return new Uint8Array(Buffer.from(this.asPureHex(), 'hex'));
|
37
|
+
}
|
38
|
+
|
39
|
+
asString() {
|
40
|
+
return this.hexString;
|
41
|
+
}
|
42
|
+
|
43
|
+
asPureHex() {
|
44
|
+
return this.hexString.substr(2);
|
45
|
+
}
|
46
|
+
|
47
|
+
constructor(hexString: string) {
|
48
|
+
if (hexString.startsWith('0x')) {
|
49
|
+
this.hexString = hexString;
|
50
|
+
} else {
|
51
|
+
this.hexString = `0x${hexString}`;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
55
|
+
interface AptosNightly {
|
56
|
+
publicKey: AptosPublicKey;
|
57
|
+
constructor(eventMap: Map<string, (data: any) => any>);
|
58
|
+
connect(onDisconnect?: () => void, eagerConnect?: boolean): Promise<AptosPublicKey>;
|
59
|
+
disconnect(): Promise<void>;
|
60
|
+
signTransaction: (transaction: TransactionPayload) => Promise<Uint8Array>;
|
61
|
+
signAllTransactions: (transaction: TransactionPayload[]) => Promise<Uint8Array[]>;
|
62
|
+
signMessage(msg: string): Promise<Uint8Array>;
|
63
|
+
}
|
64
|
+
interface NightlyWindow extends Window {
|
65
|
+
nightly?: {
|
66
|
+
aptos: AptosNightly;
|
67
|
+
};
|
68
|
+
}
|
69
|
+
|
70
|
+
declare const window: NightlyWindow;
|
71
|
+
|
72
|
+
export const NightlyWalletName = 'Nightly' as WalletName<'Nightly'>;
|
73
|
+
|
74
|
+
export interface NightlyWalletAdapterConfig {
|
75
|
+
provider?: AptosNightly;
|
76
|
+
// network?: WalletAdapterNetwork;
|
77
|
+
timeout?: number;
|
78
|
+
}
|
79
|
+
|
80
|
+
export class NightlyWalletAdapter extends BaseWalletAdapter {
|
81
|
+
name = NightlyWalletName;
|
82
|
+
|
83
|
+
url =
|
84
|
+
'https://chrome.google.com/webstore/detail/nightly/fiikommddbeccaoicoejoniammnalkfa/related?hl=en&authuser=0';
|
85
|
+
|
86
|
+
icon =
|
87
|
+
'https://lh3.googleusercontent.com/_feXM9qulMM5w9BYMLzMpZrxW2WlBmdyg3SbETIoRsHdAD9PANnLCEPabC7lzEK0N8fOyyvFkY3746jk8l73zUErxhU=w128-h128-e365-rj-sc0x00ffffff';
|
88
|
+
|
89
|
+
protected _provider: AptosNightly | undefined;
|
90
|
+
|
91
|
+
// protected _network: WalletAdapterNetwork;
|
92
|
+
protected _timeout: number;
|
93
|
+
|
94
|
+
protected _readyState: WalletReadyState =
|
95
|
+
typeof window === 'undefined' || typeof document === 'undefined'
|
96
|
+
? WalletReadyState.Unsupported
|
97
|
+
: WalletReadyState.NotDetected;
|
98
|
+
|
99
|
+
protected _connecting: boolean;
|
100
|
+
|
101
|
+
protected _wallet: {
|
102
|
+
publicKey?: string;
|
103
|
+
address?: string;
|
104
|
+
authKey?: string;
|
105
|
+
isConnected: boolean;
|
106
|
+
} | null;
|
107
|
+
|
108
|
+
constructor({
|
109
|
+
// provider,
|
110
|
+
// network = WalletAdapterNetwork.Mainnet,
|
111
|
+
timeout = 10000
|
112
|
+
}: NightlyWalletAdapterConfig = {}) {
|
113
|
+
super();
|
114
|
+
|
115
|
+
this._provider = window.nightly?.aptos;
|
116
|
+
// this._network = network;
|
117
|
+
this._timeout = timeout;
|
118
|
+
this._connecting = false;
|
119
|
+
this._wallet = null;
|
120
|
+
|
121
|
+
if (this._readyState !== WalletReadyState.Unsupported) {
|
122
|
+
scopePollingDetectionStrategy(() => {
|
123
|
+
if (window.nightly?.aptos) {
|
124
|
+
this._readyState = WalletReadyState.Installed;
|
125
|
+
this.emit('readyStateChange', this._readyState);
|
126
|
+
return true;
|
127
|
+
}
|
128
|
+
return false;
|
129
|
+
});
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
get publicAccount(): AccountKeys {
|
134
|
+
return {
|
135
|
+
publicKey: this._wallet?.publicKey || null,
|
136
|
+
address: this._wallet?.address || null,
|
137
|
+
authKey: this._wallet?.authKey || null
|
138
|
+
};
|
139
|
+
}
|
140
|
+
|
141
|
+
get connecting(): boolean {
|
142
|
+
return this._connecting;
|
143
|
+
}
|
144
|
+
|
145
|
+
get connected(): boolean {
|
146
|
+
return !!this._wallet?.isConnected;
|
147
|
+
}
|
148
|
+
|
149
|
+
get readyState(): WalletReadyState {
|
150
|
+
return this._readyState;
|
151
|
+
}
|
152
|
+
|
153
|
+
async connect(): Promise<void> {
|
154
|
+
try {
|
155
|
+
if (this.connected || this.connecting) return;
|
156
|
+
if (
|
157
|
+
!(
|
158
|
+
this._readyState === WalletReadyState.Loadable ||
|
159
|
+
this._readyState === WalletReadyState.Installed
|
160
|
+
)
|
161
|
+
)
|
162
|
+
throw new WalletNotReadyError();
|
163
|
+
this._connecting = true;
|
164
|
+
|
165
|
+
const provider = this._provider || window.nightly?.aptos;
|
166
|
+
const publicKey = await provider?.connect(() => {
|
167
|
+
this._wallet = null;
|
168
|
+
this.emit('disconnect');
|
169
|
+
});
|
170
|
+
this._wallet = {
|
171
|
+
publicKey: publicKey?.asString(),
|
172
|
+
address: publicKey?.address(),
|
173
|
+
isConnected: true
|
174
|
+
};
|
175
|
+
|
176
|
+
this.emit('connect', this._wallet.publicKey || '');
|
177
|
+
} catch (error: any) {
|
178
|
+
this.emit('error', error);
|
179
|
+
throw error;
|
180
|
+
} finally {
|
181
|
+
this._connecting = false;
|
182
|
+
}
|
183
|
+
}
|
184
|
+
|
185
|
+
async disconnect(): Promise<void> {
|
186
|
+
const wallet = this._wallet;
|
187
|
+
if (wallet) {
|
188
|
+
this._wallet = null;
|
189
|
+
|
190
|
+
try {
|
191
|
+
const provider = this._provider || window.nightly?.aptos;
|
192
|
+
await provider?.disconnect();
|
193
|
+
} catch (error: any) {
|
194
|
+
this.emit('error', new WalletDisconnectionError(error?.message, error));
|
195
|
+
}
|
196
|
+
}
|
197
|
+
|
198
|
+
this.emit('disconnect');
|
199
|
+
}
|
200
|
+
|
201
|
+
async signTransaction(payload: TransactionPayload): Promise<Uint8Array> {
|
202
|
+
try {
|
203
|
+
const wallet = this._wallet;
|
204
|
+
if (!wallet) throw new WalletNotConnectedError();
|
205
|
+
|
206
|
+
try {
|
207
|
+
const provider = this._provider || window.nightly?.aptos;
|
208
|
+
const response = await provider?.signTransaction(payload);
|
209
|
+
if (response) {
|
210
|
+
return response;
|
211
|
+
} else {
|
212
|
+
throw new Error('Transaction failed');
|
213
|
+
}
|
214
|
+
} catch (error: any) {
|
215
|
+
throw new WalletSignTransactionError(error?.message, error);
|
216
|
+
}
|
217
|
+
} catch (error: any) {
|
218
|
+
this.emit('error', error);
|
219
|
+
throw error;
|
220
|
+
}
|
221
|
+
}
|
222
|
+
|
223
|
+
async signAllTransaction(payload: TransactionPayload[]): Promise<Uint8Array[]> {
|
224
|
+
try {
|
225
|
+
const wallet = this._wallet;
|
226
|
+
if (!wallet) throw new WalletNotConnectedError();
|
227
|
+
|
228
|
+
try {
|
229
|
+
const provider = this._provider || window.nightly?.aptos;
|
230
|
+
const response = await provider?.signAllTransactions(payload);
|
231
|
+
if (response) {
|
232
|
+
return response;
|
233
|
+
} else {
|
234
|
+
throw new Error('Transaction failed');
|
235
|
+
}
|
236
|
+
} catch (error: any) {
|
237
|
+
throw new WalletSignTransactionError(error?.message, error);
|
238
|
+
}
|
239
|
+
} catch (error: any) {
|
240
|
+
this.emit('error', error);
|
241
|
+
throw error;
|
242
|
+
}
|
243
|
+
}
|
244
|
+
|
245
|
+
async signAndSubmitTransaction(tx: TransactionPayload): Promise<PendingTransaction> {
|
246
|
+
try {
|
247
|
+
const wallet = this._wallet;
|
248
|
+
if (!wallet) throw new WalletNotConnectedError();
|
249
|
+
|
250
|
+
try {
|
251
|
+
const provider = this._provider || window.nightly?.aptos;
|
252
|
+
const response = await provider?.signTransaction(tx);
|
253
|
+
const result = await aptosClient.submitSignedBCSTransaction(response);
|
254
|
+
if (response) {
|
255
|
+
return result;
|
256
|
+
} else {
|
257
|
+
throw new Error('Transaction failed');
|
258
|
+
}
|
259
|
+
} catch (error: any) {
|
260
|
+
const errMsg = error instanceof Error ? error.message : error.response.data.message;
|
261
|
+
throw new WalletSignTransactionError(errMsg);
|
262
|
+
}
|
263
|
+
} catch (error: any) {
|
264
|
+
this.emit('error', error);
|
265
|
+
throw error;
|
266
|
+
}
|
267
|
+
}
|
268
|
+
|
269
|
+
async signMessage(message: string): Promise<string> {
|
270
|
+
try {
|
271
|
+
const wallet = this._wallet;
|
272
|
+
const provider = this._provider || window.nightly.aptos;
|
273
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
274
|
+
const response = await provider?.signMessage(message);
|
275
|
+
if (response) {
|
276
|
+
return Buffer.from(response).toString('hex');
|
277
|
+
} else {
|
278
|
+
throw new Error('Sign Message failed');
|
279
|
+
}
|
280
|
+
} catch (error: any) {
|
281
|
+
const errMsg = error.message;
|
282
|
+
this.emit('error', new WalletSignMessageError(errMsg));
|
283
|
+
throw error;
|
284
|
+
}
|
285
|
+
}
|
286
|
+
}
|
@@ -5,7 +5,7 @@ export * from './HippoWallet';
|
|
5
5
|
export * from './MartianWallet';
|
6
6
|
export * from './FewchaWallet';
|
7
7
|
export * from './PontemWallet';
|
8
|
-
|
8
|
+
export * from './NightlyWallet';
|
9
9
|
export * from './RiseWallet';
|
10
10
|
export * from './SpikaWallet';
|
11
11
|
export * from './HyperPayWallet';
|