@manahippo/aptos-wallet-adapter 0.4.13 → 1.0.1

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.
@@ -0,0 +1,244 @@
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.ONTOWalletAdapter = exports.ONTOWalletName = void 0;
13
+ const errors_1 = require("../WalletProviders/errors");
14
+ const BaseAdapter_1 = require("./BaseAdapter");
15
+ exports.ONTOWalletName = 'ONTO';
16
+ class ONTOWalletAdapter extends BaseAdapter_1.BaseWalletAdapter {
17
+ constructor({
18
+ // provider,
19
+ // network = WalletAdapterNetwork.Testnet,
20
+ timeout = 10000 } = {}) {
21
+ var _a;
22
+ super();
23
+ this.name = exports.ONTOWalletName;
24
+ this.url = 'https://onto.app';
25
+ this.icon = 'https://app.ont.io/onto/ONTO_logo.png';
26
+ this._readyState = typeof window === 'undefined' || typeof document === 'undefined'
27
+ ? BaseAdapter_1.WalletReadyState.Unsupported
28
+ : BaseAdapter_1.WalletReadyState.NotDetected;
29
+ this._provider = typeof window !== 'undefined' ? (_a = window.onto) === null || _a === void 0 ? void 0 : _a.aptos : undefined;
30
+ this._network = undefined;
31
+ this._timeout = timeout;
32
+ this._connecting = false;
33
+ this._wallet = null;
34
+ if (typeof window !== 'undefined' && this._readyState !== BaseAdapter_1.WalletReadyState.Unsupported) {
35
+ (0, BaseAdapter_1.scopePollingDetectionStrategy)(() => {
36
+ var _a;
37
+ if ((_a = window.onto) === null || _a === void 0 ? void 0 : _a.aptos) {
38
+ this._readyState = BaseAdapter_1.WalletReadyState.Installed;
39
+ this.emit('readyStateChange', this._readyState);
40
+ return true;
41
+ }
42
+ return false;
43
+ });
44
+ }
45
+ }
46
+ get publicAccount() {
47
+ var _a, _b, _c;
48
+ return {
49
+ publicKey: ((_a = this._wallet) === null || _a === void 0 ? void 0 : _a.publicKey) || null,
50
+ address: ((_b = this._wallet) === null || _b === void 0 ? void 0 : _b.address) || null,
51
+ authKey: ((_c = this._wallet) === null || _c === void 0 ? void 0 : _c.authKey) || null
52
+ };
53
+ }
54
+ get network() {
55
+ return {
56
+ name: this._network,
57
+ api: this._api,
58
+ chainId: this._chainId
59
+ };
60
+ }
61
+ get connecting() {
62
+ return this._connecting;
63
+ }
64
+ get connected() {
65
+ var _a;
66
+ return !!((_a = this._wallet) === null || _a === void 0 ? void 0 : _a.isConnected);
67
+ }
68
+ get readyState() {
69
+ return this._readyState;
70
+ }
71
+ connect() {
72
+ var _a;
73
+ return __awaiter(this, void 0, void 0, function* () {
74
+ try {
75
+ if (this.connected || this.connecting)
76
+ return;
77
+ if (!(this._readyState === BaseAdapter_1.WalletReadyState.Loadable ||
78
+ this._readyState === BaseAdapter_1.WalletReadyState.Installed))
79
+ throw new errors_1.WalletNotReadyError();
80
+ this._connecting = true;
81
+ const provider = this._provider || ((_a = window.onto) === null || _a === void 0 ? void 0 : _a.aptos);
82
+ const response = yield (provider === null || provider === void 0 ? void 0 : provider.connect());
83
+ this._wallet = {
84
+ address: response === null || response === void 0 ? void 0 : response.address,
85
+ publicKey: response === null || response === void 0 ? void 0 : response.publicKey,
86
+ isConnected: true
87
+ };
88
+ try {
89
+ const name = yield (provider === null || provider === void 0 ? void 0 : provider.network());
90
+ const chainId = null;
91
+ const api = null;
92
+ this._network = name;
93
+ this._chainId = chainId;
94
+ this._api = api;
95
+ }
96
+ catch (error) {
97
+ const errMsg = error.message;
98
+ this.emit('error', new errors_1.WalletGetNetworkError(errMsg));
99
+ throw error;
100
+ }
101
+ this.emit('connect', this._wallet.publicKey);
102
+ }
103
+ catch (error) {
104
+ this.emit('error', error);
105
+ throw error;
106
+ }
107
+ finally {
108
+ this._connecting = false;
109
+ }
110
+ });
111
+ }
112
+ disconnect() {
113
+ var _a;
114
+ return __awaiter(this, void 0, void 0, function* () {
115
+ const wallet = this._wallet;
116
+ const provider = this._provider || ((_a = window.onto) === null || _a === void 0 ? void 0 : _a.aptos);
117
+ if (wallet) {
118
+ this._wallet = null;
119
+ try {
120
+ yield (provider === null || provider === void 0 ? void 0 : provider.disconnect());
121
+ }
122
+ catch (error) {
123
+ this.emit('error', new errors_1.WalletDisconnectionError(error === null || error === void 0 ? void 0 : error.message, error));
124
+ }
125
+ }
126
+ this.emit('disconnect');
127
+ });
128
+ }
129
+ signTransaction(transaction, options) {
130
+ var _a;
131
+ return __awaiter(this, void 0, void 0, function* () {
132
+ try {
133
+ const wallet = this._wallet;
134
+ const provider = this._provider || ((_a = window.onto) === null || _a === void 0 ? void 0 : _a.aptos);
135
+ if (!wallet || !provider)
136
+ throw new errors_1.WalletNotConnectedError();
137
+ const response = yield provider.signTransaction(transaction, options);
138
+ if (response.code) {
139
+ throw new Error(response.message);
140
+ }
141
+ return response;
142
+ }
143
+ catch (error) {
144
+ const errMsg = error.message;
145
+ this.emit('error', new errors_1.WalletSignTransactionError(errMsg));
146
+ throw error;
147
+ }
148
+ });
149
+ }
150
+ signAndSubmitTransaction(transaction, options) {
151
+ var _a;
152
+ return __awaiter(this, void 0, void 0, function* () {
153
+ try {
154
+ const wallet = this._wallet;
155
+ const provider = this._provider || ((_a = window.onto) === null || _a === void 0 ? void 0 : _a.aptos);
156
+ if (!wallet || !provider)
157
+ throw new errors_1.WalletNotConnectedError();
158
+ const response = yield provider.signAndSubmitTransaction(transaction, options);
159
+ if (response.code) {
160
+ throw new Error(response.message);
161
+ }
162
+ return response;
163
+ }
164
+ catch (error) {
165
+ const errMsg = error.message;
166
+ this.emit('error', new errors_1.WalletSignAndSubmitMessageError(errMsg));
167
+ throw error;
168
+ }
169
+ });
170
+ }
171
+ signMessage(msgPayload) {
172
+ var _a;
173
+ return __awaiter(this, void 0, void 0, function* () {
174
+ try {
175
+ const wallet = this._wallet;
176
+ const provider = this._provider || ((_a = window.onto) === null || _a === void 0 ? void 0 : _a.aptos);
177
+ if (!wallet || !provider)
178
+ throw new errors_1.WalletNotConnectedError();
179
+ if (typeof msgPayload !== 'object' || !msgPayload.nonce) {
180
+ throw new errors_1.WalletSignMessageError('Invalid signMessage Payload');
181
+ }
182
+ const response = yield (provider === null || provider === void 0 ? void 0 : provider.signMessage(msgPayload));
183
+ if (response) {
184
+ return response;
185
+ }
186
+ else {
187
+ throw new Error('Sign Message failed');
188
+ }
189
+ }
190
+ catch (error) {
191
+ const errMsg = error.message;
192
+ this.emit('error', new errors_1.WalletSignMessageError(errMsg));
193
+ throw error;
194
+ }
195
+ });
196
+ }
197
+ onAccountChange() {
198
+ var _a;
199
+ return __awaiter(this, void 0, void 0, function* () {
200
+ try {
201
+ const wallet = this._wallet;
202
+ const provider = this._provider || ((_a = window.onto) === null || _a === void 0 ? void 0 : _a.aptos);
203
+ if (!wallet || !provider)
204
+ throw new errors_1.WalletNotConnectedError();
205
+ const handleAccountChange = (newAccount) => __awaiter(this, void 0, void 0, function* () {
206
+ var _b, _c, _d;
207
+ console.log('account Changed >>>', newAccount);
208
+ this._wallet = Object.assign(Object.assign({}, this._wallet), { publicKey: newAccount.publicKey || ((_b = this._wallet) === null || _b === void 0 ? void 0 : _b.publicKey), authKey: newAccount.authKey || ((_c = this._wallet) === null || _c === void 0 ? void 0 : _c.authKey), address: newAccount.address || ((_d = this._wallet) === null || _d === void 0 ? void 0 : _d.address) });
209
+ this.emit('accountChange', newAccount.publicKey);
210
+ });
211
+ yield (provider === null || provider === void 0 ? void 0 : provider.onAccountChange(handleAccountChange));
212
+ }
213
+ catch (error) {
214
+ const errMsg = error.message;
215
+ this.emit('error', new errors_1.WalletAccountChangeError(errMsg));
216
+ throw error;
217
+ }
218
+ });
219
+ }
220
+ onNetworkChange() {
221
+ var _a;
222
+ return __awaiter(this, void 0, void 0, function* () {
223
+ try {
224
+ const wallet = this._wallet;
225
+ const provider = this._provider || ((_a = window.onto) === null || _a === void 0 ? void 0 : _a.aptos);
226
+ if (!wallet || !provider)
227
+ throw new errors_1.WalletNotConnectedError();
228
+ const handleNetworkChange = (newNetwork) => __awaiter(this, void 0, void 0, function* () {
229
+ console.log('network Changed >>>', newNetwork);
230
+ this._network = newNetwork.networkName;
231
+ this.emit('networkChange', this._network);
232
+ });
233
+ yield (provider === null || provider === void 0 ? void 0 : provider.onNetworkChange(handleNetworkChange));
234
+ }
235
+ catch (error) {
236
+ const errMsg = error.message;
237
+ this.emit('error', new errors_1.WalletNetworkChangeError(errMsg));
238
+ throw error;
239
+ }
240
+ });
241
+ }
242
+ }
243
+ exports.ONTOWalletAdapter = ONTOWalletAdapter;
244
+ //# sourceMappingURL=ONTOWallet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ONTOWallet.js","sourceRoot":"","sources":["../../src/WalletAdapters/ONTOWallet.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,sDAUmC;AACnC,+CAUuB;AAmCV,QAAA,cAAc,GAAG,MAA4B,CAAC;AAQ3D,MAAa,iBAAkB,SAAQ,+BAAiB;IA4BtD,YAAY;IACV,YAAY;IACZ,0CAA0C;IAC1C,OAAO,GAAG,KAAK,KACY,EAAE;;QAC7B,KAAK,EAAE,CAAC;QAhCV,SAAI,GAAG,sBAAc,CAAC;QAEtB,QAAG,GACD,kBAAkB,CAAC;QAErB,SAAI,GACF,uCAAuC,CAAC;QAYhC,gBAAW,GACnB,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,QAAQ,KAAK,WAAW;YAC9D,CAAC,CAAC,8BAAgB,CAAC,WAAW;YAC9B,CAAC,CAAC,8BAAgB,CAAC,WA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AAC,CAAA,CAAC;gBACF,MAAM,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,eAAe,CAAC,mBAAmB,CAAC,CAAA,CAAC;aACtD;YAAC,OAAO,KAAU,EAAE;gBACnB,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC;gBAC7B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,iCAAwB,CAAC,MAAM,CAAC,CAAC,CAAC;gBACzD,MAAM,KAAK,CAAC;aACb;;KACF;CACF;AAhPD,8CAgPC"}
@@ -13,4 +13,6 @@ export * from './FletchWallet';
13
13
  export * from './AptosSnap';
14
14
  export * from './BitkeepWallet';
15
15
  export * from './TokenPocketWallet';
16
+ export * from './ONTOWallet';
17
+ export * from './BloctoWallet';
16
18
  //# sourceMappingURL=index.d.ts.map
@@ -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;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;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,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;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC"}
@@ -29,4 +29,6 @@ __exportStar(require("./FletchWallet"), exports);
29
29
  __exportStar(require("./AptosSnap"), exports);
30
30
  __exportStar(require("./BitkeepWallet"), exports);
31
31
  __exportStar(require("./TokenPocketWallet"), exports);
32
+ __exportStar(require("./ONTOWallet"), exports);
33
+ __exportStar(require("./BloctoWallet"), exports);
32
34
  //# sourceMappingURL=index.js.map
@@ -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,kDAAgC;AAChC,+CAA6B;AAC7B,gDAA8B;AAC9B,mDAAiC;AACjC,iDAA+B;AAC/B,8CAA4B;AAC5B,kDAAgC;AAChC,sDAAoC"}
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;AAC5B,kDAAgC;AAChC,sDAAoC;AACpC,+CAA6B;AAC7B,iDAA+B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manahippo/aptos-wallet-adapter",
3
- "version": "0.4.13",
3
+ "version": "1.0.1",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "files": [
@@ -28,6 +28,7 @@
28
28
  "typescript": "^4.7.4"
29
29
  },
30
30
  "dependencies": {
31
+ "@blocto/sdk": "^0.3.0-beta.9",
31
32
  "@fewcha/web3": "0.1.32",
32
33
  "@keystonehq/aptossnap-adapter": "^0.2.8",
33
34
  "eventemitter3": "^4.0.7",
@@ -14,9 +14,10 @@ export type Address = MaybeHexString;
14
14
  export type AuthKey = MaybeHexString;
15
15
 
16
16
  export interface AccountKeys {
17
- publicKey: PublicKey | null;
17
+ publicKey: PublicKey | PublicKey[] | null;
18
18
  address: Address | null;
19
19
  authKey: AuthKey | null;
20
+ minKeysRequired?: number;
20
21
  }
21
22
 
22
23
  export interface WalletAdapterEvents {
@@ -0,0 +1,264 @@
1
+ import { Types } from 'aptos';
2
+ import BloctoSDK, { AptosProviderInterface as IBloctoAptos } from '@blocto/sdk';
3
+ import {
4
+ WalletAccountChangeError,
5
+ WalletDisconnectionError,
6
+ WalletNetworkChangeError,
7
+ WalletNotConnectedError,
8
+ WalletNotReadyError,
9
+ WalletSignAndSubmitMessageError,
10
+ WalletSignMessageError,
11
+ WalletSignTransactionError
12
+ } from '../WalletProviders/errors';
13
+ import {
14
+ AccountKeys,
15
+ BaseWalletAdapter,
16
+ scopePollingDetectionStrategy,
17
+ WalletName,
18
+ WalletReadyState,
19
+ SignMessagePayload,
20
+ SignMessageResponse,
21
+ NetworkInfo,
22
+ WalletAdapterNetwork
23
+ } from './BaseAdapter';
24
+
25
+ export const BloctoWalletName = 'Blocto' as WalletName<'Blocto'>;
26
+
27
+ export interface BloctoWalletAdapterConfig {
28
+ provider?: IBloctoAptos;
29
+ network: Exclude<WalletAdapterNetwork, WalletAdapterNetwork.Devnet>;
30
+ timeout?: number;
31
+ bloctoAppId?: string;
32
+ }
33
+
34
+ export const APTOS_NETWORK_CHAIN_ID_MAPPING = {
35
+ // MAINNET
36
+ [WalletAdapterNetwork.Mainnet]: 1,
37
+ // TESTNET
38
+ [WalletAdapterNetwork.Testnet]: 2
39
+ };
40
+
41
+ export class BloctoWalletAdapter extends BaseWalletAdapter {
42
+ name = BloctoWalletName;
43
+
44
+ url = 'https://portto.com/download';
45
+
46
+ icon = 'https://raw.githubusercontent.com/hippospace/aptos-wallet-adapter/main/logos/blocto.svg';
47
+
48
+ protected _provider: IBloctoAptos | undefined;
49
+
50
+ protected _network: Exclude<WalletAdapterNetwork, WalletAdapterNetwork.Devnet>;
51
+
52
+ protected _chainId: string;
53
+
54
+ protected _api: string;
55
+
56
+ protected _timeout: number;
57
+
58
+ protected _readyState: WalletReadyState =
59
+ typeof window === 'undefined' || typeof document === 'undefined'
60
+ ? WalletReadyState.Unsupported
61
+ : WalletReadyState.NotDetected;
62
+
63
+ protected _connecting: boolean;
64
+
65
+ protected _wallet: any | null;
66
+
67
+ constructor(
68
+ { network, timeout = 10000, bloctoAppId = '' }: BloctoWalletAdapterConfig = {
69
+ network: WalletAdapterNetwork.Testnet
70
+ }
71
+ ) {
72
+ super();
73
+
74
+ const sdk = new BloctoSDK({
75
+ aptos: {
76
+ chainId: APTOS_NETWORK_CHAIN_ID_MAPPING[network]
77
+ },
78
+ appId: bloctoAppId
79
+ });
80
+
81
+ this._provider = sdk.aptos;
82
+ this._network = network;
83
+ this._timeout = timeout;
84
+ this._connecting = false;
85
+ this._wallet = null;
86
+
87
+ if (typeof window !== 'undefined' && this._readyState !== WalletReadyState.Unsupported) {
88
+ scopePollingDetectionStrategy(() => {
89
+ if (window) {
90
+ this._readyState = WalletReadyState.Installed;
91
+ return true;
92
+ }
93
+ return false;
94
+ });
95
+ }
96
+ }
97
+
98
+ get publicAccount(): AccountKeys {
99
+ return {
100
+ publicKey: this._wallet?.publicKey || null,
101
+ address: this._wallet?.address || null,
102
+ authKey: this._wallet?.authKey || null,
103
+ minKeysRequired: this._wallet?.minKeysRequired
104
+ };
105
+ }
106
+
107
+ get network(): NetworkInfo {
108
+ return {
109
+ name: this._network,
110
+ api: this._api,
111
+ chainId: this._chainId
112
+ };
113
+ }
114
+
115
+ get connecting(): boolean {
116
+ return this._connecting;
117
+ }
118
+
119
+ get connected(): boolean {
120
+ return !!this._wallet?.isConnected;
121
+ }
122
+
123
+ get readyState(): WalletReadyState {
124
+ return this._readyState;
125
+ }
126
+
127
+ async connect(): Promise<void> {
128
+ try {
129
+ if (this.connected || this.connecting) return;
130
+ if (
131
+ !(
132
+ this._readyState === WalletReadyState.Loadable ||
133
+ this._readyState === WalletReadyState.Installed
134
+ )
135
+ )
136
+ throw new WalletNotReadyError();
137
+
138
+ this._connecting = true;
139
+ const provider = this._provider;
140
+ const isConnected = await provider?.isConnected();
141
+ if (isConnected) {
142
+ await provider?.disconnect();
143
+ }
144
+
145
+ const { publicKey, ...rest } = await provider?.connect();
146
+ this._wallet = {
147
+ ...rest,
148
+ publicKey,
149
+ isConnected: true
150
+ };
151
+
152
+ const { api, chainId } = await provider.network();
153
+ this._api = api;
154
+ this._chainId = chainId;
155
+
156
+ this.emit('connect', this._wallet);
157
+ } catch (error: any) {
158
+ this.emit('error', error);
159
+ throw error;
160
+ } finally {
161
+ this._connecting = false;
162
+ }
163
+ }
164
+
165
+ async disconnect(): Promise<void> {
166
+ const wallet = this._wallet;
167
+ const provider = this._provider;
168
+ if (wallet) {
169
+ this._wallet = null;
170
+ try {
171
+ await provider?.disconnect();
172
+ } catch (error: any) {
173
+ this.emit('error', new WalletDisconnectionError(error?.message, error));
174
+ }
175
+ }
176
+
177
+ this.emit('disconnect');
178
+ }
179
+
180
+ async signTransaction(transaction: Types.TransactionPayload): Promise<Uint8Array> {
181
+ try {
182
+ try {
183
+ const provider = this._provider;
184
+ const response = await provider?.signTransaction(transaction as Types.EntryFunctionPayload);
185
+ if (response) {
186
+ return new Uint8Array([]);
187
+ } else {
188
+ throw new Error('Transaction failed');
189
+ }
190
+ } catch (error: any) {
191
+ throw new WalletSignTransactionError(error?.message, error);
192
+ }
193
+ } catch (error: any) {
194
+ this.emit('error', error);
195
+ throw error;
196
+ }
197
+ }
198
+
199
+ async signAndSubmitTransaction(
200
+ transaction: Types.TransactionPayload
201
+ ): Promise<{ hash: Types.HexEncodedBytes }> {
202
+ try {
203
+ try {
204
+ const provider = this._provider;
205
+ const response = await provider?.signAndSubmitTransaction(
206
+ transaction as Types.EntryFunctionPayload
207
+ );
208
+ if (response) {
209
+ return { hash: response.hash };
210
+ } else {
211
+ throw new Error('Transaction failed');
212
+ }
213
+ } catch (error: any) {
214
+ throw new WalletSignAndSubmitMessageError(error.message || error);
215
+ }
216
+ } catch (error: any) {
217
+ this.emit('error', error);
218
+ throw error;
219
+ }
220
+ }
221
+
222
+ async signMessage(message: SignMessagePayload): Promise<SignMessageResponse> {
223
+ try {
224
+ const provider = this._provider;
225
+ const response = await provider?.signMessage(message);
226
+
227
+ if (response) {
228
+ return response;
229
+ } else {
230
+ throw new Error('Sign Message failed');
231
+ }
232
+ } catch (error: any) {
233
+ const errMsg = error.message;
234
+ this.emit('error', new WalletSignMessageError(errMsg));
235
+ throw error;
236
+ }
237
+ }
238
+
239
+ async onAccountChange(): Promise<void> {
240
+ try {
241
+ const wallet = this._wallet;
242
+ const provider = this._provider;
243
+ if (!wallet || !provider) throw new WalletNotConnectedError();
244
+ //To be implemented
245
+ } catch (error: any) {
246
+ const errMsg = error.message;
247
+ this.emit('error', new WalletAccountChangeError(errMsg));
248
+ throw error;
249
+ }
250
+ }
251
+
252
+ async onNetworkChange(): Promise<void> {
253
+ try {
254
+ const wallet = this._wallet;
255
+ const provider = this._provider;
256
+ if (!wallet || !provider) throw new WalletNotConnectedError();
257
+ //To be implemented
258
+ } catch (error: any) {
259
+ const errMsg = error.message;
260
+ this.emit('error', new WalletNetworkChangeError(errMsg));
261
+ throw error;
262
+ }
263
+ }
264
+ }
@@ -282,13 +282,16 @@ export class MartianWalletAdapter extends BaseWalletAdapter {
282
282
  const wallet = this._wallet;
283
283
  const provider = this._provider || window.martian;
284
284
  if (!wallet || !provider) throw new WalletNotConnectedError();
285
- await provider?.onAccountChange((newAccount: string) => {
285
+ const handleChangeAccount = async (newAccount: string) => {
286
+ const { publicKey } = await provider?.account();
286
287
  this._wallet = {
287
288
  ...this._wallet,
288
- address: newAccount
289
+ address: newAccount,
290
+ publicKey
289
291
  };
290
292
  this.emit('accountChange', newAccount);
291
- });
293
+ };
294
+ await provider?.onAccountChange(handleChangeAccount);
292
295
  } catch (error: any) {
293
296
  const errMsg = error.message;
294
297
  this.emit('error', new WalletAccountChangeError(errMsg));