@manahippo/aptos-wallet-adapter 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +5 -2
- package/dist/WalletAdapters/HyperPayWallet.d.ts +56 -0
- package/dist/WalletAdapters/HyperPayWallet.d.ts.map +1 -0
- package/dist/WalletAdapters/HyperPayWallet.js +180 -0
- package/dist/WalletAdapters/HyperPayWallet.js.map +1 -0
- package/dist/WalletAdapters/RiseWallet.d.ts +53 -0
- package/dist/WalletAdapters/RiseWallet.d.ts.map +1 -0
- package/dist/WalletAdapters/RiseWallet.js +187 -0
- package/dist/WalletAdapters/RiseWallet.js.map +1 -0
- package/dist/WalletAdapters/index.d.ts +2 -0
- package/dist/WalletAdapters/index.d.ts.map +1 -1
- package/dist/WalletAdapters/index.js +2 -0
- package/dist/WalletAdapters/index.js.map +1 -1
- package/package.json +1 -1
- package/src/WalletAdapters/HyperPayWallet.ts +237 -0
- package/src/WalletAdapters/RiseWallet.ts +235 -0
- package/src/WalletAdapters/index.ts +2 -0
package/README.md
CHANGED
@@ -11,6 +11,7 @@ Supports:
|
|
11
11
|
- [Hippo web wallet](https://hippo-wallet-test.web.app/)
|
12
12
|
- [Pontem Wallet](https://pontem.network/pontem-wallet)
|
13
13
|
- [Spika wallet](https://spika.app)
|
14
|
+
- [Rise Wallet](https://rise)
|
14
15
|
|
15
16
|
Working on (PR welcome):
|
16
17
|
|
@@ -52,7 +53,8 @@ import {
|
|
52
53
|
MartianWalletAdapter,
|
53
54
|
FewchaWalletAdapter,
|
54
55
|
PontemWalletAdapter,
|
55
|
-
SpikaWalletAdapter
|
56
|
+
SpikaWalletAdapter,
|
57
|
+
RiseWalletAdapter
|
56
58
|
} from '@manahippo/aptos-wallet-adapter';
|
57
59
|
|
58
60
|
const wallets = [
|
@@ -62,7 +64,8 @@ const wallets = [
|
|
62
64
|
new FewchaWalletAdapter(),
|
63
65
|
new HippoExtensionWalletAdapter(),
|
64
66
|
new PontemWalletAdapter(),
|
65
|
-
new SpikaWalletAdapter()
|
67
|
+
new SpikaWalletAdapter(),
|
68
|
+
new RiseWalletAdapter()
|
66
69
|
];
|
67
70
|
|
68
71
|
const App: React.FC = () => {
|
@@ -0,0 +1,56 @@
|
|
1
|
+
import { MaybeHexString } from 'aptos';
|
2
|
+
import { TransactionPayload, HexEncodedBytes } from 'aptos/src/generated';
|
3
|
+
import { AccountKeys, BaseWalletAdapter, WalletName, WalletReadyState } from './BaseAdapter';
|
4
|
+
interface ConnectHyperPayAccount {
|
5
|
+
address: MaybeHexString;
|
6
|
+
method: string;
|
7
|
+
publicKey: MaybeHexString;
|
8
|
+
status: number;
|
9
|
+
}
|
10
|
+
interface HyperPayAccount {
|
11
|
+
address: MaybeHexString;
|
12
|
+
publicKey: MaybeHexString;
|
13
|
+
authKey: MaybeHexString;
|
14
|
+
isConnected: boolean;
|
15
|
+
}
|
16
|
+
interface IHyperPayWallet {
|
17
|
+
connect: () => Promise<ConnectHyperPayAccount>;
|
18
|
+
account(): Promise<HyperPayAccount>;
|
19
|
+
isConnected(): Promise<boolean>;
|
20
|
+
generateTransaction(sender: MaybeHexString, payload: any, options?: any): Promise<any>;
|
21
|
+
signAndSubmitTransaction(transaction: TransactionPayload): Promise<HexEncodedBytes>;
|
22
|
+
signTransaction(transaction: TransactionPayload): Promise<Uint8Array>;
|
23
|
+
signMessage(message: string): Promise<{
|
24
|
+
signature: string;
|
25
|
+
}>;
|
26
|
+
disconnect(): Promise<void>;
|
27
|
+
}
|
28
|
+
export declare const HyperPayWalletName: WalletName<"HyperPay">;
|
29
|
+
export interface HyperPayWalletAdapterConfig {
|
30
|
+
provider?: IHyperPayWallet;
|
31
|
+
timeout?: number;
|
32
|
+
}
|
33
|
+
export declare class HyperPayWalletAdapter extends BaseWalletAdapter {
|
34
|
+
name: WalletName<"HyperPay">;
|
35
|
+
url: string;
|
36
|
+
icon: string;
|
37
|
+
protected _provider: IHyperPayWallet | undefined;
|
38
|
+
protected _timeout: number;
|
39
|
+
protected _readyState: WalletReadyState;
|
40
|
+
protected _connecting: boolean;
|
41
|
+
protected _wallet: HyperPayAccount | null;
|
42
|
+
constructor({ timeout }?: HyperPayWalletAdapterConfig);
|
43
|
+
get publicAccount(): AccountKeys;
|
44
|
+
get connecting(): boolean;
|
45
|
+
get connected(): boolean;
|
46
|
+
get readyState(): WalletReadyState;
|
47
|
+
connect(): Promise<void>;
|
48
|
+
disconnect(): Promise<void>;
|
49
|
+
signTransaction(transactionPyld: TransactionPayload, options?: any): Promise<Uint8Array>;
|
50
|
+
signAndSubmitTransaction(transactionPyld: TransactionPayload, options?: any): Promise<{
|
51
|
+
hash: HexEncodedBytes;
|
52
|
+
}>;
|
53
|
+
signMessage(message: string): Promise<string>;
|
54
|
+
}
|
55
|
+
export {};
|
56
|
+
//# sourceMappingURL=HyperPayWallet.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"HyperPayWallet.d.ts","sourceRoot":"","sources":["../../src/WalletAdapters/HyperPayWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAS1E,OAAO,EACL,WAAW,EACX,iBAAiB,EAEjB,UAAU,EACV,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAEvB,UAAU,sBAAsB;IAC9B,OAAO,EAAE,cAAc,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,cAAc,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,eAAe;IACvB,OAAO,EAAE,cAAc,CAAC;IACxB,SAAS,EAAE,cAAc,CAAC;IAC1B,OAAO,EAAE,cAAc,CAAC;IACxB,WAAW,EAAE,OAAO,CAAC;CACtB;AACD,UAAU,eAAe;IACvB,OAAO,EAAE,MAAM,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAC/C,OAAO,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC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AAI,OAAO,CAAC,IAAI,CAAC;IAgB3B,eAAe,CAAC,eAAe,EAAE,kBAAkB,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC;IAmBxF,wBAAwB,CAC5B,eAAe,EAAE,kBAAkB,EACnC,OAAO,CAAC,EAAE,GAAG,GACZ,OAAO,CAAC;QAAE,IAAI,EAAE,eAAe,CAAA;KAAE,CAAC;IAmB/B,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAiBpD"}
|
@@ -0,0 +1,180 @@
|
|
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.HyperPayWalletAdapter = exports.HyperPayWalletName = void 0;
|
13
|
+
const errors_1 = require("../WalletProviders/errors");
|
14
|
+
const BaseAdapter_1 = require("./BaseAdapter");
|
15
|
+
exports.HyperPayWalletName = 'HyperPay';
|
16
|
+
class HyperPayWalletAdapter extends BaseAdapter_1.BaseWalletAdapter {
|
17
|
+
constructor({
|
18
|
+
// provider,
|
19
|
+
// network = WalletAdapterNetwork.Mainnet,
|
20
|
+
timeout = 10000 } = {}) {
|
21
|
+
super();
|
22
|
+
this.name = exports.HyperPayWalletName;
|
23
|
+
this.url = 'https://www.hyperpay.tech/';
|
24
|
+
this.icon = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMjE1IDEyMTUiPjxwYXRoIGQ9Ik02MDcuNSAwQzk0My4wMTMgMCAxMjE1IDI3MS45ODcgMTIxNSA2MDcuNVM5NDMuMDEzIDEyMTUgNjA3LjUgMTIxNSAwIDk0My4wMTMgMCA2MDcuNSAyNzEuOTg3IDAgNjA3LjUgMHpNMzUxLjY4IDM3MS4zMTVzMy43MDgtNzIuOSA3Ny43Ni03Mi45aDIwNC4xMnMxMTkuNDM3LS4xIDIwNC4xMiA3NS4zM2MwIDAgMTExLjg0MyA5My42MTIgMTE2LjY0IDIzNS43MSAwIDAgMS45NjIgMTE5LjA0NS03Mi45IDIxMS40MSAwIDAtNzcuOTMxIDEyMS41LTI2Mi40NCAxMjEuNUg0NDEuNTlzLTg5LjkxIDExLjA0OS04OS45MS04NS4wNXYtNDg2ek0xMTkuMzQ0IDU1My42NTlzLjkwNi0xNy44MiAxOS4wMDgtMTcuODJoNDkuOXMyOS4yLS4wMjMgNDkuOSAxOC40MTRjMCAwIDI3LjMzOSAyMi44ODMgMjguNTEyIDU3LjYxOCAwIDAgLjQ4IDI5LjEtMTcuODIgNTEuNjc4IDAgMC0xOS4wNSAyOS43LTY0LjE1MiAyOS43aC00My4zN3MtMjEuOTc4IDIuNy0yMS45NzgtMjAuNzl2LTExOC44eiIgZmlsbD0iIzE1N0VGQiIgZmlsbC1ydWxlPSJldmVub2RkIi8+PC9zdmc+';
|
25
|
+
this._readyState = typeof window === 'undefined' || typeof document === 'undefined'
|
26
|
+
? BaseAdapter_1.WalletReadyState.Unsupported
|
27
|
+
: BaseAdapter_1.WalletReadyState.NotDetected;
|
28
|
+
this._provider = typeof window !== 'undefined' ? window.hyperpay : undefined;
|
29
|
+
// this._network = network;
|
30
|
+
this._timeout = timeout;
|
31
|
+
this._connecting = false;
|
32
|
+
this._wallet = null;
|
33
|
+
if (typeof window !== 'undefined' && this._readyState !== BaseAdapter_1.WalletReadyState.Unsupported) {
|
34
|
+
(0, BaseAdapter_1.scopePollingDetectionStrategy)(() => {
|
35
|
+
if (window.hyperpay) {
|
36
|
+
this._readyState = BaseAdapter_1.WalletReadyState.Installed;
|
37
|
+
this.emit('readyStateChange', this._readyState);
|
38
|
+
return true;
|
39
|
+
}
|
40
|
+
return false;
|
41
|
+
});
|
42
|
+
}
|
43
|
+
}
|
44
|
+
get publicAccount() {
|
45
|
+
var _a, _b, _c;
|
46
|
+
return {
|
47
|
+
publicKey: ((_a = this._wallet) === null || _a === void 0 ? void 0 : _a.publicKey) || null,
|
48
|
+
address: ((_b = this._wallet) === null || _b === void 0 ? void 0 : _b.address) || null,
|
49
|
+
authKey: ((_c = this._wallet) === null || _c === void 0 ? void 0 : _c.authKey) || null
|
50
|
+
};
|
51
|
+
}
|
52
|
+
get connecting() {
|
53
|
+
return this._connecting;
|
54
|
+
}
|
55
|
+
get connected() {
|
56
|
+
var _a;
|
57
|
+
return !!((_a = this._wallet) === null || _a === void 0 ? void 0 : _a.isConnected);
|
58
|
+
}
|
59
|
+
get readyState() {
|
60
|
+
return this._readyState;
|
61
|
+
}
|
62
|
+
connect() {
|
63
|
+
var _a;
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
65
|
+
try {
|
66
|
+
if (this.connected || this.connecting)
|
67
|
+
return;
|
68
|
+
if (!(this._readyState === BaseAdapter_1.WalletReadyState.Loadable ||
|
69
|
+
this._readyState === BaseAdapter_1.WalletReadyState.Installed))
|
70
|
+
throw new errors_1.WalletNotReadyError();
|
71
|
+
this._connecting = true;
|
72
|
+
const provider = this._provider || window.hyperpay;
|
73
|
+
const isConnected = yield (provider === null || provider === void 0 ? void 0 : provider.isConnected());
|
74
|
+
if (isConnected) {
|
75
|
+
yield (provider === null || provider === void 0 ? void 0 : provider.disconnect());
|
76
|
+
}
|
77
|
+
const response = yield (provider === null || provider === void 0 ? void 0 : provider.connect());
|
78
|
+
if (!response) {
|
79
|
+
throw new errors_1.WalletNotConnectedError('No connect response');
|
80
|
+
}
|
81
|
+
const walletAccount = yield (provider === null || provider === void 0 ? void 0 : provider.account());
|
82
|
+
if (walletAccount) {
|
83
|
+
this._wallet = Object.assign(Object.assign({}, walletAccount), { isConnected: true });
|
84
|
+
}
|
85
|
+
this.emit('connect', ((_a = this._wallet) === null || _a === void 0 ? void 0 : _a.address) || '');
|
86
|
+
}
|
87
|
+
catch (error) {
|
88
|
+
this.emit('error', new Error(error));
|
89
|
+
throw error;
|
90
|
+
}
|
91
|
+
finally {
|
92
|
+
this._connecting = false;
|
93
|
+
}
|
94
|
+
});
|
95
|
+
}
|
96
|
+
disconnect() {
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
98
|
+
const wallet = this._wallet;
|
99
|
+
const provider = this._provider || window.hyperpay;
|
100
|
+
if (wallet) {
|
101
|
+
this._wallet = null;
|
102
|
+
try {
|
103
|
+
yield (provider === null || provider === void 0 ? void 0 : provider.disconnect());
|
104
|
+
}
|
105
|
+
catch (error) {
|
106
|
+
this.emit('error', new errors_1.WalletDisconnectionError(error === null || error === void 0 ? void 0 : error.message, error));
|
107
|
+
}
|
108
|
+
}
|
109
|
+
this.emit('disconnect');
|
110
|
+
});
|
111
|
+
}
|
112
|
+
signTransaction(transactionPyld, options) {
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
114
|
+
try {
|
115
|
+
const wallet = this._wallet;
|
116
|
+
const provider = this._provider || window.hyperpay;
|
117
|
+
if (!wallet || !provider)
|
118
|
+
throw new errors_1.WalletNotConnectedError();
|
119
|
+
const tx = yield provider.generateTransaction(wallet.address || '', transactionPyld, options);
|
120
|
+
if (!tx)
|
121
|
+
throw new Error('Cannot generate transaction');
|
122
|
+
const response = yield (provider === null || provider === void 0 ? void 0 : provider.signTransaction(tx));
|
123
|
+
if (!response) {
|
124
|
+
throw new Error('No response');
|
125
|
+
}
|
126
|
+
return response;
|
127
|
+
}
|
128
|
+
catch (error) {
|
129
|
+
this.emit('error', new errors_1.WalletSignTransactionError(error));
|
130
|
+
throw error;
|
131
|
+
}
|
132
|
+
});
|
133
|
+
}
|
134
|
+
signAndSubmitTransaction(transactionPyld, options) {
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
136
|
+
try {
|
137
|
+
const wallet = this._wallet;
|
138
|
+
const provider = this._provider || window.hyperpay;
|
139
|
+
if (!wallet || !provider)
|
140
|
+
throw new errors_1.WalletNotConnectedError();
|
141
|
+
const tx = yield provider.generateTransaction(wallet.address || '', transactionPyld, options);
|
142
|
+
if (!tx)
|
143
|
+
throw new Error('Cannot generate transaction');
|
144
|
+
const response = yield (provider === null || provider === void 0 ? void 0 : provider.signAndSubmitTransaction(tx));
|
145
|
+
if (!response) {
|
146
|
+
throw new Error('No response');
|
147
|
+
}
|
148
|
+
return { hash: response };
|
149
|
+
}
|
150
|
+
catch (error) {
|
151
|
+
this.emit('error', new errors_1.WalletSignAndSubmitMessageError(error));
|
152
|
+
throw error;
|
153
|
+
}
|
154
|
+
});
|
155
|
+
}
|
156
|
+
signMessage(message) {
|
157
|
+
return __awaiter(this, void 0, void 0, function* () {
|
158
|
+
try {
|
159
|
+
const wallet = this._wallet;
|
160
|
+
const provider = this._provider || window.hyperpay;
|
161
|
+
if (!wallet || !provider)
|
162
|
+
throw new errors_1.WalletNotConnectedError();
|
163
|
+
const response = yield (provider === null || provider === void 0 ? void 0 : provider.signMessage(message));
|
164
|
+
if (response === null || response === void 0 ? void 0 : response.signature) {
|
165
|
+
return response === null || response === void 0 ? void 0 : response.signature;
|
166
|
+
}
|
167
|
+
else {
|
168
|
+
throw new Error('Sign Message failed');
|
169
|
+
}
|
170
|
+
}
|
171
|
+
catch (error) {
|
172
|
+
const errMsg = error.message;
|
173
|
+
this.emit('error', new errors_1.WalletSignMessageError(errMsg));
|
174
|
+
throw error;
|
175
|
+
}
|
176
|
+
});
|
177
|
+
}
|
178
|
+
}
|
179
|
+
exports.HyperPayWalletAdapter = HyperPayWalletAdapter;
|
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AAC,CAAC;gBACvD,MAAM,KAAK,CAAC;aACb;QACH,CAAC;KAAA;CACF;AApLD,sDAoLC"}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import { HexEncodedBytes, TransactionPayload } from 'aptos/src/generated';
|
2
|
+
import { AccountKeys, BaseWalletAdapter, WalletName, WalletReadyState } from './BaseAdapter';
|
3
|
+
import { MaybeHexString } from 'aptos';
|
4
|
+
interface RiseAccount {
|
5
|
+
address: MaybeHexString;
|
6
|
+
publicKey: MaybeHexString;
|
7
|
+
authKey: MaybeHexString;
|
8
|
+
isConnected: boolean;
|
9
|
+
}
|
10
|
+
interface IRiseWallet {
|
11
|
+
connect: () => Promise<{
|
12
|
+
address: string;
|
13
|
+
}>;
|
14
|
+
account(): Promise<RiseAccount>;
|
15
|
+
isConnected: () => Promise<boolean>;
|
16
|
+
signAndSubmitTransaction(transaction: any): Promise<{
|
17
|
+
hash: HexEncodedBytes;
|
18
|
+
}>;
|
19
|
+
signTransaction(transaction: any, options?: any): Promise<Uint8Array>;
|
20
|
+
signMessage(message: string): Promise<{
|
21
|
+
signature: string;
|
22
|
+
}>;
|
23
|
+
disconnect(): Promise<void>;
|
24
|
+
}
|
25
|
+
export declare const RiseWalletName: WalletName<"Rise Wallet">;
|
26
|
+
export interface RiseWalletAdapterConfig {
|
27
|
+
provider?: IRiseWallet;
|
28
|
+
timeout?: number;
|
29
|
+
}
|
30
|
+
export declare class RiseWalletAdapter extends BaseWalletAdapter {
|
31
|
+
name: WalletName<"Rise Wallet">;
|
32
|
+
url: string;
|
33
|
+
icon: string;
|
34
|
+
protected _provider: IRiseWallet | undefined;
|
35
|
+
protected _timeout: number;
|
36
|
+
protected _readyState: WalletReadyState;
|
37
|
+
protected _connecting: boolean;
|
38
|
+
protected _wallet: any | null;
|
39
|
+
constructor({ timeout }?: RiseWalletAdapterConfig);
|
40
|
+
get publicAccount(): AccountKeys;
|
41
|
+
get connecting(): boolean;
|
42
|
+
get connected(): boolean;
|
43
|
+
get readyState(): WalletReadyState;
|
44
|
+
connect(): Promise<void>;
|
45
|
+
disconnect(): Promise<void>;
|
46
|
+
signTransaction(transaction: TransactionPayload): Promise<Uint8Array>;
|
47
|
+
signAndSubmitTransaction(transaction: TransactionPayload): Promise<{
|
48
|
+
hash: HexEncodedBytes;
|
49
|
+
}>;
|
50
|
+
signMessage(message: string): Promise<string>;
|
51
|
+
}
|
52
|
+
export {};
|
53
|
+
//# sourceMappingURL=RiseWallet.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"RiseWallet.d.ts","sourceRoot":"","sources":["../../src/WalletAdapters/RiseWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAQ1E,OAAO,EACL,WAAW,EACX,iBAAiB,EAEjB,UAAU,EACV,gBAAgB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAEvC,UAAU,WAAW;IACnB,OAAO,EAAE,cAAc,CAAC;IACxB,SAAS,EAAE,cAAc,CAAC;IAC1B,OAAO,EAAE,cAAc,CAAC;IACxB,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,UAAU,WAAW;IACnB,OAAO,EAAE,MAAM,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC5C,OAAO,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;IAChC,WAAW,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACpC,wBAAwB,CAAC,WAAW,EAAE,GAAG,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,eAAe,CAAA;KAAE,CAAC,CAAC;IAC/E,eAAe,CAAC,WAAW,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACtE,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,SA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{ 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.RiseWalletAdapter = exports.RiseWalletName = void 0;
|
13
|
+
const WalletProviders_1 = require("../WalletProviders");
|
14
|
+
const BaseAdapter_1 = require("./BaseAdapter");
|
15
|
+
exports.RiseWalletName = 'Rise Wallet';
|
16
|
+
class RiseWalletAdapter extends BaseAdapter_1.BaseWalletAdapter {
|
17
|
+
constructor({
|
18
|
+
// provider,
|
19
|
+
// network = WalletAdapterNetwork.Mainnet,
|
20
|
+
timeout = 10000 } = {}) {
|
21
|
+
super();
|
22
|
+
this.name = exports.RiseWalletName;
|
23
|
+
this.url = 'https://chrome.google.com/webstore/detail/hbbgbephgojikajhfbomhlmmollphcad';
|
24
|
+
this.icon = 'https://static.risewallet.io/logo.png';
|
25
|
+
this._readyState = typeof window === 'undefined' || typeof document === 'undefined'
|
26
|
+
? BaseAdapter_1.WalletReadyState.Unsupported
|
27
|
+
: BaseAdapter_1.WalletReadyState.NotDetected;
|
28
|
+
this._provider = typeof window !== 'undefined' ? window.rise : undefined;
|
29
|
+
// this._network = network;
|
30
|
+
this._timeout = timeout;
|
31
|
+
this._connecting = false;
|
32
|
+
this._wallet = null;
|
33
|
+
if (typeof window !== 'undefined' && this._readyState !== BaseAdapter_1.WalletReadyState.Unsupported) {
|
34
|
+
(0, BaseAdapter_1.scopePollingDetectionStrategy)(() => {
|
35
|
+
if (window.rise) {
|
36
|
+
this._readyState = BaseAdapter_1.WalletReadyState.Installed;
|
37
|
+
this.emit('readyStateChange', this._readyState);
|
38
|
+
return true;
|
39
|
+
}
|
40
|
+
return false;
|
41
|
+
});
|
42
|
+
}
|
43
|
+
}
|
44
|
+
get publicAccount() {
|
45
|
+
var _a, _b, _c;
|
46
|
+
return {
|
47
|
+
publicKey: ((_a = this._wallet) === null || _a === void 0 ? void 0 : _a.publicKey) || null,
|
48
|
+
address: ((_b = this._wallet) === null || _b === void 0 ? void 0 : _b.address) || null,
|
49
|
+
authKey: ((_c = this._wallet) === null || _c === void 0 ? void 0 : _c.authKey) || null
|
50
|
+
};
|
51
|
+
}
|
52
|
+
get connecting() {
|
53
|
+
return this._connecting;
|
54
|
+
}
|
55
|
+
get connected() {
|
56
|
+
var _a;
|
57
|
+
return !!((_a = this._wallet) === null || _a === void 0 ? void 0 : _a.isConnected);
|
58
|
+
}
|
59
|
+
get readyState() {
|
60
|
+
return this._readyState;
|
61
|
+
}
|
62
|
+
connect() {
|
63
|
+
var _a;
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
65
|
+
try {
|
66
|
+
if (this.connected || this.connecting)
|
67
|
+
return;
|
68
|
+
if (!(this._readyState === BaseAdapter_1.WalletReadyState.Loadable ||
|
69
|
+
this._readyState === BaseAdapter_1.WalletReadyState.Installed))
|
70
|
+
throw new WalletProviders_1.WalletNotReadyError();
|
71
|
+
this._connecting = true;
|
72
|
+
const provider = this._provider || window.rise;
|
73
|
+
const isConnected = yield ((_a = this._provider) === null || _a === void 0 ? void 0 : _a.isConnected());
|
74
|
+
if (isConnected === true) {
|
75
|
+
yield (provider === null || provider === void 0 ? void 0 : provider.disconnect());
|
76
|
+
}
|
77
|
+
const response = yield (provider === null || provider === void 0 ? void 0 : provider.connect());
|
78
|
+
if (!response) {
|
79
|
+
throw new WalletProviders_1.WalletNotConnectedError('User has rejected the request');
|
80
|
+
}
|
81
|
+
const account = yield (provider === null || provider === void 0 ? void 0 : provider.account());
|
82
|
+
if (account) {
|
83
|
+
const { publicKey, address, authKey } = account;
|
84
|
+
this._wallet = {
|
85
|
+
publicKey,
|
86
|
+
address,
|
87
|
+
authKey,
|
88
|
+
isConnected: true
|
89
|
+
};
|
90
|
+
this.emit('connect', this._wallet.publicKey);
|
91
|
+
}
|
92
|
+
}
|
93
|
+
catch (error) {
|
94
|
+
this.emit('error', error);
|
95
|
+
throw error;
|
96
|
+
}
|
97
|
+
finally {
|
98
|
+
this._connecting = false;
|
99
|
+
}
|
100
|
+
});
|
101
|
+
}
|
102
|
+
disconnect() {
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
104
|
+
const wallet = this._wallet;
|
105
|
+
if (wallet) {
|
106
|
+
this._wallet = null;
|
107
|
+
try {
|
108
|
+
const provider = this._provider || window.rise;
|
109
|
+
yield (provider === null || provider === void 0 ? void 0 : provider.disconnect());
|
110
|
+
}
|
111
|
+
catch (error) {
|
112
|
+
this.emit('error', new WalletProviders_1.WalletDisconnectionError(error === null || error === void 0 ? void 0 : error.message, error));
|
113
|
+
}
|
114
|
+
}
|
115
|
+
this.emit('disconnect');
|
116
|
+
});
|
117
|
+
}
|
118
|
+
signTransaction(transaction) {
|
119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
120
|
+
try {
|
121
|
+
const wallet = this._wallet;
|
122
|
+
const provider = this._provider || window.rise;
|
123
|
+
if (!wallet || !provider)
|
124
|
+
throw new WalletProviders_1.WalletNotConnectedError();
|
125
|
+
const response = yield (provider === null || provider === void 0 ? void 0 : provider.signTransaction(transaction));
|
126
|
+
if (response) {
|
127
|
+
return response;
|
128
|
+
}
|
129
|
+
else {
|
130
|
+
throw new Error('Sign Transaction failed');
|
131
|
+
}
|
132
|
+
}
|
133
|
+
catch (error) {
|
134
|
+
const errMsg = error.message;
|
135
|
+
this.emit('error', new WalletProviders_1.WalletSignTransactionError(errMsg));
|
136
|
+
throw error;
|
137
|
+
}
|
138
|
+
});
|
139
|
+
}
|
140
|
+
signAndSubmitTransaction(transaction) {
|
141
|
+
return __awaiter(this, void 0, void 0, function* () {
|
142
|
+
try {
|
143
|
+
const wallet = this._wallet;
|
144
|
+
const provider = this._provider || window.rise;
|
145
|
+
if (!wallet || !provider)
|
146
|
+
throw new WalletProviders_1.WalletNotConnectedError();
|
147
|
+
const response = yield (provider === null || provider === void 0 ? void 0 : provider.signAndSubmitTransaction(transaction));
|
148
|
+
if (response) {
|
149
|
+
return response;
|
150
|
+
}
|
151
|
+
else {
|
152
|
+
throw new Error('Transaction failed');
|
153
|
+
}
|
154
|
+
}
|
155
|
+
catch (error) {
|
156
|
+
const errMsg = error.message;
|
157
|
+
this.emit('error', new WalletProviders_1.WalletSignTransactionError(errMsg));
|
158
|
+
throw error;
|
159
|
+
}
|
160
|
+
});
|
161
|
+
}
|
162
|
+
signMessage(message) {
|
163
|
+
return __awaiter(this, void 0, void 0, function* () {
|
164
|
+
try {
|
165
|
+
const wallet = this._wallet;
|
166
|
+
const provider = this._provider || window.rise;
|
167
|
+
if (!wallet || !provider)
|
168
|
+
throw new WalletProviders_1.WalletNotConnectedError();
|
169
|
+
const response = yield (provider === null || provider === void 0 ? void 0 : provider.signMessage(message));
|
170
|
+
if (response === null || response === void 0 ? void 0 : response.signature) {
|
171
|
+
return response.signature;
|
172
|
+
}
|
173
|
+
else {
|
174
|
+
throw new Error('Sign Message failed');
|
175
|
+
}
|
176
|
+
}
|
177
|
+
catch (error) {
|
178
|
+
console.log('err', error);
|
179
|
+
const errMsg = error.message;
|
180
|
+
this.emit('error', new WalletProviders_1.WalletSignMessageError(errMsg));
|
181
|
+
throw error;
|
182
|
+
}
|
183
|
+
});
|
184
|
+
}
|
185
|
+
}
|
186
|
+
exports.RiseWalletAdapter = RiseWalletAdapter;
|
187
|
+
//# sourceMappingURL=RiseWallet.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"RiseWallet.js","sourceRoot":"","sources":["../../src/WalletAdapters/RiseWallet.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,wDAM4B;AAC5B,+CAMuB;AA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KAAK,CAAC;aACb;QACH,CAAC;KAAA;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,IAAI,CAAC;gBAC/C,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ;oBAAE,MAAM,IAAI,yCAAuB,EAAE,CAAC;gBAE9D,MAAM,QAAQ,GAAG,MAAM,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,WAAW,CAAC,OAAO,CAAC,CAAA,CAAC;gBACtD,IAAI,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,SAAS,EAAE;oBACvB,OAAO,QAAQ,CAAC,SAAS,CAAC;iBAC3B;qBAAM;oBACL,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;iBACxC;aACF;YAAC,OAAO,KAAU,EAAE;gBACnB,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;gBAC1B,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC;gBAC7B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,wCAAsB,CAAC,MAAM,CAAC,CAAC,CAAC;gBACvD,MAAM,KAAK,CAAC;aACb;QACH,CAAC;KAAA;CACF;AA1LD,8CA0LC"}
|
@@ -5,5 +5,7 @@ export * from './HippoWallet';
|
|
5
5
|
export * from './MartianWallet';
|
6
6
|
export * from './FewchaWallet';
|
7
7
|
export * from './PontemWallet';
|
8
|
+
export * from './RiseWallet';
|
8
9
|
export * from './SpikaWallet';
|
10
|
+
export * from './HyperPayWallet';
|
9
11
|
//# 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;AAE/B,cAAc,eAAe,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;AAE/B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC"}
|
@@ -22,5 +22,7 @@ __exportStar(require("./MartianWallet"), exports);
|
|
22
22
|
__exportStar(require("./FewchaWallet"), exports);
|
23
23
|
__exportStar(require("./PontemWallet"), exports);
|
24
24
|
// export * from './NightlyWallet';
|
25
|
+
__exportStar(require("./RiseWallet"), exports);
|
25
26
|
__exportStar(require("./SpikaWallet"), exports);
|
27
|
+
__exportStar(require("./HyperPayWallet"), exports);
|
26
28
|
//# 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,mCAAmC;AACnC,gDAA8B"}
|
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,mCAAmC;AACnC,+CAA6B;AAC7B,gDAA8B;AAC9B,mDAAiC"}
|
package/package.json
CHANGED
@@ -0,0 +1,237 @@
|
|
1
|
+
import { MaybeHexString } from 'aptos';
|
2
|
+
import { TransactionPayload, HexEncodedBytes } from 'aptos/src/generated';
|
3
|
+
import {
|
4
|
+
WalletDisconnectionError,
|
5
|
+
WalletNotConnectedError,
|
6
|
+
WalletNotReadyError,
|
7
|
+
WalletSignAndSubmitMessageError,
|
8
|
+
WalletSignMessageError,
|
9
|
+
WalletSignTransactionError
|
10
|
+
} from '../WalletProviders/errors';
|
11
|
+
import {
|
12
|
+
AccountKeys,
|
13
|
+
BaseWalletAdapter,
|
14
|
+
scopePollingDetectionStrategy,
|
15
|
+
WalletName,
|
16
|
+
WalletReadyState
|
17
|
+
} from './BaseAdapter';
|
18
|
+
|
19
|
+
interface ConnectHyperPayAccount {
|
20
|
+
address: MaybeHexString;
|
21
|
+
method: string;
|
22
|
+
publicKey: MaybeHexString;
|
23
|
+
status: number;
|
24
|
+
}
|
25
|
+
|
26
|
+
interface HyperPayAccount {
|
27
|
+
address: MaybeHexString;
|
28
|
+
publicKey: MaybeHexString;
|
29
|
+
authKey: MaybeHexString;
|
30
|
+
isConnected: boolean;
|
31
|
+
}
|
32
|
+
interface IHyperPayWallet {
|
33
|
+
connect: () => Promise<ConnectHyperPayAccount>;
|
34
|
+
account(): Promise<HyperPayAccount>;
|
35
|
+
isConnected(): Promise<boolean>;
|
36
|
+
generateTransaction(sender: MaybeHexString, payload: any, options?: any): Promise<any>;
|
37
|
+
signAndSubmitTransaction(transaction: TransactionPayload): Promise<HexEncodedBytes>;
|
38
|
+
signTransaction(transaction: TransactionPayload): Promise<Uint8Array>;
|
39
|
+
signMessage(message: string): Promise<{ signature: string }>;
|
40
|
+
disconnect(): Promise<void>;
|
41
|
+
}
|
42
|
+
|
43
|
+
interface HyperPayWindow extends Window {
|
44
|
+
hyperpay?: IHyperPayWallet;
|
45
|
+
}
|
46
|
+
|
47
|
+
declare const window: HyperPayWindow;
|
48
|
+
|
49
|
+
export const HyperPayWalletName = 'HyperPay' as WalletName<'HyperPay'>;
|
50
|
+
|
51
|
+
export interface HyperPayWalletAdapterConfig {
|
52
|
+
provider?: IHyperPayWallet;
|
53
|
+
// network?: WalletAdapterNetwork;
|
54
|
+
timeout?: number;
|
55
|
+
}
|
56
|
+
|
57
|
+
export class HyperPayWalletAdapter extends BaseWalletAdapter {
|
58
|
+
name = HyperPayWalletName;
|
59
|
+
|
60
|
+
url = 'https://www.hyperpay.tech/';
|
61
|
+
|
62
|
+
icon =
|
63
|
+
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMjE1IDEyMTUiPjxwYXRoIGQ9Ik02MDcuNSAwQzk0My4wMTMgMCAxMjE1IDI3MS45ODcgMTIxNSA2MDcuNVM5NDMuMDEzIDEyMTUgNjA3LjUgMTIxNSAwIDk0My4wMTMgMCA2MDcuNSAyNzEuOTg3IDAgNjA3LjUgMHpNMzUxLjY4IDM3MS4zMTVzMy43MDgtNzIuOSA3Ny43Ni03Mi45aDIwNC4xMnMxMTkuNDM3LS4xIDIwNC4xMiA3NS4zM2MwIDAgMTExLjg0MyA5My42MTIgMTE2LjY0IDIzNS43MSAwIDAgMS45NjIgMTE5LjA0NS03Mi45IDIxMS40MSAwIDAtNzcuOTMxIDEyMS41LTI2Mi40NCAxMjEuNUg0NDEuNTlzLTg5LjkxIDExLjA0OS04OS45MS04NS4wNXYtNDg2ek0xMTkuMzQ0IDU1My42NTlzLjkwNi0xNy44MiAxOS4wMDgtMTcuODJoNDkuOXMyOS4yLS4wMjMgNDkuOSAxOC40MTRjMCAwIDI3LjMzOSAyMi44ODMgMjguNTEyIDU3LjYxOCAwIDAgLjQ4IDI5LjEtMTcuODIgNTEuNjc4IDAgMC0xOS4wNSAyOS43LTY0LjE1MiAyOS43aC00My4zN3MtMjEuOTc4IDIuNy0yMS45NzgtMjAuNzl2LTExOC44eiIgZmlsbD0iIzE1N0VGQiIgZmlsbC1ydWxlPSJldmVub2RkIi8+PC9zdmc+';
|
64
|
+
|
65
|
+
protected _provider: IHyperPayWallet | undefined;
|
66
|
+
|
67
|
+
// protected _network: WalletAdapterNetwork;
|
68
|
+
protected _timeout: number;
|
69
|
+
|
70
|
+
protected _readyState: WalletReadyState =
|
71
|
+
typeof window === 'undefined' || typeof document === 'undefined'
|
72
|
+
? WalletReadyState.Unsupported
|
73
|
+
: WalletReadyState.NotDetected;
|
74
|
+
|
75
|
+
protected _connecting: boolean;
|
76
|
+
|
77
|
+
protected _wallet: HyperPayAccount | null;
|
78
|
+
|
79
|
+
constructor({
|
80
|
+
// provider,
|
81
|
+
// network = WalletAdapterNetwork.Mainnet,
|
82
|
+
timeout = 10000
|
83
|
+
}: HyperPayWalletAdapterConfig = {}) {
|
84
|
+
super();
|
85
|
+
|
86
|
+
this._provider = typeof window !== 'undefined' ? window.hyperpay : undefined;
|
87
|
+
// this._network = network;
|
88
|
+
this._timeout = timeout;
|
89
|
+
this._connecting = false;
|
90
|
+
this._wallet = null;
|
91
|
+
|
92
|
+
if (typeof window !== 'undefined' && this._readyState !== WalletReadyState.Unsupported) {
|
93
|
+
scopePollingDetectionStrategy(() => {
|
94
|
+
if (window.hyperpay) {
|
95
|
+
this._readyState = WalletReadyState.Installed;
|
96
|
+
this.emit('readyStateChange', this._readyState);
|
97
|
+
return true;
|
98
|
+
}
|
99
|
+
return false;
|
100
|
+
});
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
get publicAccount(): AccountKeys {
|
105
|
+
return {
|
106
|
+
publicKey: this._wallet?.publicKey || null,
|
107
|
+
address: this._wallet?.address || null,
|
108
|
+
authKey: this._wallet?.authKey || null
|
109
|
+
};
|
110
|
+
}
|
111
|
+
|
112
|
+
get connecting(): boolean {
|
113
|
+
return this._connecting;
|
114
|
+
}
|
115
|
+
|
116
|
+
get connected(): boolean {
|
117
|
+
return !!this._wallet?.isConnected;
|
118
|
+
}
|
119
|
+
|
120
|
+
get readyState(): WalletReadyState {
|
121
|
+
return this._readyState;
|
122
|
+
}
|
123
|
+
|
124
|
+
async connect(): Promise<void> {
|
125
|
+
try {
|
126
|
+
if (this.connected || this.connecting) return;
|
127
|
+
if (
|
128
|
+
!(
|
129
|
+
this._readyState === WalletReadyState.Loadable ||
|
130
|
+
this._readyState === WalletReadyState.Installed
|
131
|
+
)
|
132
|
+
)
|
133
|
+
throw new WalletNotReadyError();
|
134
|
+
this._connecting = true;
|
135
|
+
|
136
|
+
const provider = this._provider || window.hyperpay;
|
137
|
+
const isConnected = await provider?.isConnected();
|
138
|
+
if (isConnected) {
|
139
|
+
await provider?.disconnect();
|
140
|
+
}
|
141
|
+
const response = await provider?.connect();
|
142
|
+
|
143
|
+
if (!response) {
|
144
|
+
throw new WalletNotConnectedError('No connect response');
|
145
|
+
}
|
146
|
+
|
147
|
+
const walletAccount = await provider?.account();
|
148
|
+
if (walletAccount) {
|
149
|
+
this._wallet = {
|
150
|
+
...walletAccount,
|
151
|
+
isConnected: true
|
152
|
+
};
|
153
|
+
}
|
154
|
+
this.emit('connect', this._wallet?.address || '');
|
155
|
+
} catch (error: any) {
|
156
|
+
this.emit('error', new Error(error));
|
157
|
+
throw error;
|
158
|
+
} finally {
|
159
|
+
this._connecting = false;
|
160
|
+
}
|
161
|
+
}
|
162
|
+
|
163
|
+
async disconnect(): Promise<void> {
|
164
|
+
const wallet = this._wallet;
|
165
|
+
const provider = this._provider || window.hyperpay;
|
166
|
+
if (wallet) {
|
167
|
+
this._wallet = null;
|
168
|
+
|
169
|
+
try {
|
170
|
+
await provider?.disconnect();
|
171
|
+
} catch (error: any) {
|
172
|
+
this.emit('error', new WalletDisconnectionError(error?.message, error));
|
173
|
+
}
|
174
|
+
}
|
175
|
+
|
176
|
+
this.emit('disconnect');
|
177
|
+
}
|
178
|
+
|
179
|
+
async signTransaction(transactionPyld: TransactionPayload, options?: any): Promise<Uint8Array> {
|
180
|
+
try {
|
181
|
+
const wallet = this._wallet;
|
182
|
+
const provider = this._provider || window.hyperpay;
|
183
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
184
|
+
const tx = await provider.generateTransaction(wallet.address || '', transactionPyld, options);
|
185
|
+
if (!tx) throw new Error('Cannot generate transaction');
|
186
|
+
const response = await provider?.signTransaction(tx);
|
187
|
+
|
188
|
+
if (!response) {
|
189
|
+
throw new Error('No response');
|
190
|
+
}
|
191
|
+
return response;
|
192
|
+
} catch (error: any) {
|
193
|
+
this.emit('error', new WalletSignTransactionError(error));
|
194
|
+
throw error;
|
195
|
+
}
|
196
|
+
}
|
197
|
+
|
198
|
+
async signAndSubmitTransaction(
|
199
|
+
transactionPyld: TransactionPayload,
|
200
|
+
options?: any
|
201
|
+
): Promise<{ hash: HexEncodedBytes }> {
|
202
|
+
try {
|
203
|
+
const wallet = this._wallet;
|
204
|
+
const provider = this._provider || window.hyperpay;
|
205
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
206
|
+
const tx = await provider.generateTransaction(wallet.address || '', transactionPyld, options);
|
207
|
+
if (!tx) throw new Error('Cannot generate transaction');
|
208
|
+
const response = await provider?.signAndSubmitTransaction(tx);
|
209
|
+
|
210
|
+
if (!response) {
|
211
|
+
throw new Error('No response');
|
212
|
+
}
|
213
|
+
return { hash: response };
|
214
|
+
} catch (error: any) {
|
215
|
+
this.emit('error', new WalletSignAndSubmitMessageError(error));
|
216
|
+
throw error;
|
217
|
+
}
|
218
|
+
}
|
219
|
+
|
220
|
+
async signMessage(message: string): Promise<string> {
|
221
|
+
try {
|
222
|
+
const wallet = this._wallet;
|
223
|
+
const provider = this._provider || window.hyperpay;
|
224
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
225
|
+
const response = await provider?.signMessage(message);
|
226
|
+
if (response?.signature) {
|
227
|
+
return response?.signature;
|
228
|
+
} else {
|
229
|
+
throw new Error('Sign Message failed');
|
230
|
+
}
|
231
|
+
} catch (error: any) {
|
232
|
+
const errMsg = error.message;
|
233
|
+
this.emit('error', new WalletSignMessageError(errMsg));
|
234
|
+
throw error;
|
235
|
+
}
|
236
|
+
}
|
237
|
+
}
|
@@ -0,0 +1,235 @@
|
|
1
|
+
import { HexEncodedBytes, TransactionPayload } from 'aptos/src/generated';
|
2
|
+
import {
|
3
|
+
WalletDisconnectionError,
|
4
|
+
WalletNotConnectedError,
|
5
|
+
WalletNotReadyError,
|
6
|
+
WalletSignMessageError,
|
7
|
+
WalletSignTransactionError
|
8
|
+
} from '../WalletProviders';
|
9
|
+
import {
|
10
|
+
AccountKeys,
|
11
|
+
BaseWalletAdapter,
|
12
|
+
scopePollingDetectionStrategy,
|
13
|
+
WalletName,
|
14
|
+
WalletReadyState
|
15
|
+
} from './BaseAdapter';
|
16
|
+
import { MaybeHexString } from 'aptos';
|
17
|
+
|
18
|
+
interface RiseAccount {
|
19
|
+
address: MaybeHexString;
|
20
|
+
publicKey: MaybeHexString;
|
21
|
+
authKey: MaybeHexString;
|
22
|
+
isConnected: boolean;
|
23
|
+
}
|
24
|
+
|
25
|
+
interface IRiseWallet {
|
26
|
+
connect: () => Promise<{ address: string }>;
|
27
|
+
account(): Promise<RiseAccount>;
|
28
|
+
isConnected: () => Promise<boolean>;
|
29
|
+
signAndSubmitTransaction(transaction: any): Promise<{ hash: HexEncodedBytes }>;
|
30
|
+
signTransaction(transaction: any, options?: any): Promise<Uint8Array>;
|
31
|
+
signMessage(message: string): Promise<{ signature: string }>;
|
32
|
+
disconnect(): Promise<void>;
|
33
|
+
}
|
34
|
+
|
35
|
+
interface RiseWindow extends Window {
|
36
|
+
rise?: IRiseWallet;
|
37
|
+
}
|
38
|
+
|
39
|
+
declare const window: RiseWindow;
|
40
|
+
|
41
|
+
export const RiseWalletName = 'Rise Wallet' as WalletName<'Rise Wallet'>;
|
42
|
+
|
43
|
+
export interface RiseWalletAdapterConfig {
|
44
|
+
provider?: IRiseWallet;
|
45
|
+
// network?: WalletAdapterNetwork;
|
46
|
+
timeout?: number;
|
47
|
+
}
|
48
|
+
|
49
|
+
export class RiseWalletAdapter extends BaseWalletAdapter {
|
50
|
+
name = RiseWalletName;
|
51
|
+
|
52
|
+
url = 'https://chrome.google.com/webstore/detail/hbbgbephgojikajhfbomhlmmollphcad';
|
53
|
+
|
54
|
+
icon = 'https://static.risewallet.io/logo.png';
|
55
|
+
|
56
|
+
protected _provider: IRiseWallet | undefined;
|
57
|
+
|
58
|
+
// protected _network: WalletAdapterNetwork;
|
59
|
+
protected _timeout: number;
|
60
|
+
|
61
|
+
protected _readyState: WalletReadyState =
|
62
|
+
typeof window === 'undefined' || typeof document === 'undefined'
|
63
|
+
? WalletReadyState.Unsupported
|
64
|
+
: WalletReadyState.NotDetected;
|
65
|
+
|
66
|
+
protected _connecting: boolean;
|
67
|
+
|
68
|
+
protected _wallet: any | null;
|
69
|
+
|
70
|
+
constructor({
|
71
|
+
// provider,
|
72
|
+
// network = WalletAdapterNetwork.Mainnet,
|
73
|
+
timeout = 10000
|
74
|
+
}: RiseWalletAdapterConfig = {}) {
|
75
|
+
super();
|
76
|
+
|
77
|
+
this._provider = typeof window !== 'undefined' ? window.rise : undefined;
|
78
|
+
// this._network = network;
|
79
|
+
this._timeout = timeout;
|
80
|
+
this._connecting = false;
|
81
|
+
this._wallet = null;
|
82
|
+
|
83
|
+
if (typeof window !== 'undefined' && this._readyState !== WalletReadyState.Unsupported) {
|
84
|
+
scopePollingDetectionStrategy(() => {
|
85
|
+
if (window.rise) {
|
86
|
+
this._readyState = WalletReadyState.Installed;
|
87
|
+
this.emit('readyStateChange', this._readyState);
|
88
|
+
return true;
|
89
|
+
}
|
90
|
+
return false;
|
91
|
+
});
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
get publicAccount(): AccountKeys {
|
96
|
+
return {
|
97
|
+
publicKey: this._wallet?.publicKey || null,
|
98
|
+
address: this._wallet?.address || null,
|
99
|
+
authKey: this._wallet?.authKey || null
|
100
|
+
};
|
101
|
+
}
|
102
|
+
|
103
|
+
get connecting(): boolean {
|
104
|
+
return this._connecting;
|
105
|
+
}
|
106
|
+
|
107
|
+
get connected(): boolean {
|
108
|
+
return !!this._wallet?.isConnected;
|
109
|
+
}
|
110
|
+
|
111
|
+
get readyState(): WalletReadyState {
|
112
|
+
return this._readyState;
|
113
|
+
}
|
114
|
+
|
115
|
+
async connect(): Promise<void> {
|
116
|
+
try {
|
117
|
+
if (this.connected || this.connecting) return;
|
118
|
+
if (
|
119
|
+
!(
|
120
|
+
this._readyState === WalletReadyState.Loadable ||
|
121
|
+
this._readyState === WalletReadyState.Installed
|
122
|
+
)
|
123
|
+
)
|
124
|
+
throw new WalletNotReadyError();
|
125
|
+
this._connecting = true;
|
126
|
+
|
127
|
+
const provider = this._provider || window.rise;
|
128
|
+
const isConnected = await this._provider?.isConnected();
|
129
|
+
if (isConnected === true) {
|
130
|
+
await provider?.disconnect();
|
131
|
+
}
|
132
|
+
|
133
|
+
const response = await provider?.connect();
|
134
|
+
|
135
|
+
if (!response) {
|
136
|
+
throw new WalletNotConnectedError('User has rejected the request');
|
137
|
+
}
|
138
|
+
|
139
|
+
const account = await provider?.account();
|
140
|
+
if (account) {
|
141
|
+
const { publicKey, address, authKey } = account;
|
142
|
+
|
143
|
+
this._wallet = {
|
144
|
+
publicKey,
|
145
|
+
address,
|
146
|
+
authKey,
|
147
|
+
isConnected: true
|
148
|
+
};
|
149
|
+
|
150
|
+
this.emit('connect', this._wallet.publicKey);
|
151
|
+
}
|
152
|
+
} catch (error: any) {
|
153
|
+
this.emit('error', error);
|
154
|
+
throw error;
|
155
|
+
} finally {
|
156
|
+
this._connecting = false;
|
157
|
+
}
|
158
|
+
}
|
159
|
+
|
160
|
+
async disconnect(): Promise<void> {
|
161
|
+
const wallet = this._wallet;
|
162
|
+
if (wallet) {
|
163
|
+
this._wallet = null;
|
164
|
+
|
165
|
+
try {
|
166
|
+
const provider = this._provider || window.rise;
|
167
|
+
await provider?.disconnect();
|
168
|
+
} catch (error: any) {
|
169
|
+
this.emit('error', new WalletDisconnectionError(error?.message, error));
|
170
|
+
}
|
171
|
+
}
|
172
|
+
|
173
|
+
this.emit('disconnect');
|
174
|
+
}
|
175
|
+
|
176
|
+
async signTransaction(transaction: TransactionPayload): Promise<Uint8Array> {
|
177
|
+
try {
|
178
|
+
const wallet = this._wallet;
|
179
|
+
const provider = this._provider || window.rise;
|
180
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
181
|
+
|
182
|
+
const response = await provider?.signTransaction(transaction);
|
183
|
+
if (response) {
|
184
|
+
return response;
|
185
|
+
} else {
|
186
|
+
throw new Error('Sign Transaction failed');
|
187
|
+
}
|
188
|
+
} catch (error: any) {
|
189
|
+
const errMsg = error.message;
|
190
|
+
this.emit('error', new WalletSignTransactionError(errMsg));
|
191
|
+
throw error;
|
192
|
+
}
|
193
|
+
}
|
194
|
+
|
195
|
+
async signAndSubmitTransaction(
|
196
|
+
transaction: TransactionPayload
|
197
|
+
): Promise<{ hash: HexEncodedBytes }> {
|
198
|
+
try {
|
199
|
+
const wallet = this._wallet;
|
200
|
+
const provider = this._provider || window.rise;
|
201
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
202
|
+
|
203
|
+
const response = await provider?.signAndSubmitTransaction(transaction);
|
204
|
+
if (response) {
|
205
|
+
return response;
|
206
|
+
} else {
|
207
|
+
throw new Error('Transaction failed');
|
208
|
+
}
|
209
|
+
} catch (error: any) {
|
210
|
+
const errMsg = error.message;
|
211
|
+
this.emit('error', new WalletSignTransactionError(errMsg));
|
212
|
+
throw error;
|
213
|
+
}
|
214
|
+
}
|
215
|
+
|
216
|
+
async signMessage(message: string): Promise<string> {
|
217
|
+
try {
|
218
|
+
const wallet = this._wallet;
|
219
|
+
const provider = this._provider || window.rise;
|
220
|
+
if (!wallet || !provider) throw new WalletNotConnectedError();
|
221
|
+
|
222
|
+
const response = await provider?.signMessage(message);
|
223
|
+
if (response?.signature) {
|
224
|
+
return response.signature;
|
225
|
+
} else {
|
226
|
+
throw new Error('Sign Message failed');
|
227
|
+
}
|
228
|
+
} catch (error: any) {
|
229
|
+
console.log('err', error);
|
230
|
+
const errMsg = error.message;
|
231
|
+
this.emit('error', new WalletSignMessageError(errMsg));
|
232
|
+
throw error;
|
233
|
+
}
|
234
|
+
}
|
235
|
+
}
|