@onekeyfe/onekey-neo-provider 2.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +51 -0
- package/README.md +1 -0
- package/dist/OneKeyNeoProvider.d.ts +93 -0
- package/dist/OneKeyNeoProvider.js +346 -0
- package/dist/ProviderNeoBase.d.ts +8 -0
- package/dist/ProviderNeoBase.js +12 -0
- package/dist/cjs/OneKeyNeoProvider.js +351 -0
- package/dist/cjs/ProviderNeoBase.js +15 -0
- package/dist/cjs/index.js +19 -0
- package/dist/cjs/type-utils.js +2 -0
- package/dist/cjs/types.js +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/type-utils.d.ts +4 -0
- package/dist/type-utils.js +1 -0
- package/dist/types.d.ts +246 -0
- package/dist/types.js +1 -0
- package/package.json +37 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# ONEKEY STANDARD SOURCE LICENSE (O-SSL)
|
|
2
|
+
|
|
3
|
+
This license governs use of the accompanying software. If you use the software,
|
|
4
|
+
you accept this license. If you do not accept the license, do not use the
|
|
5
|
+
software.
|
|
6
|
+
|
|
7
|
+
## 1. Definitions
|
|
8
|
+
|
|
9
|
+
The terms "reproduce," "reproduction" and "distribution" have the same meaning
|
|
10
|
+
here as under Hong Kong copyright law.
|
|
11
|
+
|
|
12
|
+
"You" means the licensee of the software.
|
|
13
|
+
|
|
14
|
+
"Your company" means the company you worked for when you downloaded the
|
|
15
|
+
software.
|
|
16
|
+
|
|
17
|
+
"Reference use" means use of the software within your company as a reference,
|
|
18
|
+
in read only form, for the sole purposes of debugging your products,
|
|
19
|
+
maintaining your products, or enhancing the interoperability of your products
|
|
20
|
+
with the software, and specifically excludes the right to distribute the
|
|
21
|
+
software outside of your company.
|
|
22
|
+
|
|
23
|
+
"Licensed patents" means any Licensor patent claims which read directly on the
|
|
24
|
+
software as distributed by the Licensor under this license.
|
|
25
|
+
|
|
26
|
+
## 2. Grant of Rights
|
|
27
|
+
|
|
28
|
+
(A) Copyright Grant - Subject to the terms of this license, the Licensor grants
|
|
29
|
+
you a non-transferable, non-exclusive, worldwide, royalty-free copyright
|
|
30
|
+
license to reproduce the software for reference use.
|
|
31
|
+
|
|
32
|
+
(B) Patent Grant - Subject to the terms of this license, the Licensor grants
|
|
33
|
+
you a non-transferable, non-exclusive, worldwide, royalty-free patent license
|
|
34
|
+
under licensed patents for reference use.
|
|
35
|
+
|
|
36
|
+
## 3. Limitations
|
|
37
|
+
|
|
38
|
+
(A) No Trademark License - This license does not grant you any rights to use
|
|
39
|
+
the Licensor's name, logo, or trademarks.
|
|
40
|
+
|
|
41
|
+
(B) If you begin patent litigation against the Licensor over patents that you
|
|
42
|
+
think may apply to the software (including a cross-claim or counterclaim in
|
|
43
|
+
a lawsuit), your license to the software ends automatically.
|
|
44
|
+
|
|
45
|
+
(C) The software is licensed "as-is." You bear the risk of using it. The
|
|
46
|
+
Licensor gives no express warranties, guarantees or conditions. You may have
|
|
47
|
+
additional consumer rights under your local laws which this license cannot
|
|
48
|
+
change. To the extent permitted under your local laws, the Licensor excludes
|
|
49
|
+
the implied warranties of merchantability, fitness for a particular purpose and
|
|
50
|
+
non-infringement.This license agreement is governed by the laws of Hong Kong,
|
|
51
|
+
and any disputes related to this license agreement shall be resolved in accordance with Hong Kong law.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# OneKey Neo Provider
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { IInpageProviderConfig } from '@onekeyfe/cross-inpage-provider-core';
|
|
2
|
+
import { ProviderNeoBase } from './ProviderNeoBase';
|
|
3
|
+
import { INeoProviderMethods, INeoGetProviderResponse, NeoProviderEventsMap, INeoNetworkResponse, IGetAccountResponse, IGetPublicKeyResponse, IGetBalanceParams, IGetBalanceResponse, IGetStorageParams, IGetStorageResponse, IGetBlockParams, IGetTransactionParams, IGetApplicationLogParams, IPickAddressResponse, IAddressToScriptHashParams, IAddressToScriptHashResponse, IScriptHashToAddressParams, IScriptHashToAddressResponse, IRpcResponse, IVerifyMessageParams, IVerifyMessageResponse, IVerifyMessageV2Params, IVerifyMessageV2Response, ISignMessageV2Params, ISignMessageV2Response, ISignMessageWithoutSaltV2Params, ISignMessageWithoutSaltV2Response, ISignTransactionParams, ISignTransactionResponse, ISwitchWalletNetworkParams, ISwitchWalletNetworkResponse, IInvokeMultipleParams, IInvokeParams, IInvokeResponse, ISendParams, ISendResponse, IInvokeReadParams, IInvokeReadResponse, IInvokeReadMultiParams } from './types';
|
|
4
|
+
declare const PROVIDER_EVENTS: {
|
|
5
|
+
readonly connect: "connect";
|
|
6
|
+
readonly disconnect: "disconnect";
|
|
7
|
+
readonly accountChanged: "accountChanged";
|
|
8
|
+
readonly message_low_level: "message_low_level";
|
|
9
|
+
};
|
|
10
|
+
export type PROVIDER_EVENTS_STRINGS = keyof typeof PROVIDER_EVENTS;
|
|
11
|
+
/**
|
|
12
|
+
* send NEOLine.N3.EVENT.READY event to notify the page that Neo Provider is ready
|
|
13
|
+
*/
|
|
14
|
+
declare function emitNeoReadyEvent(): void;
|
|
15
|
+
/**
|
|
16
|
+
* NEOLineN3 is a class to provide compatibility with Neo dAPI
|
|
17
|
+
*/
|
|
18
|
+
declare class NEOLineN3 {
|
|
19
|
+
static instance: ProviderNeo | null;
|
|
20
|
+
static Init: {
|
|
21
|
+
new (): {
|
|
22
|
+
provider: ProviderNeo;
|
|
23
|
+
getProvider(): Promise<INeoGetProviderResponse>;
|
|
24
|
+
getNetworks(): Promise<INeoNetworkResponse>;
|
|
25
|
+
getAccount(): Promise<IGetAccountResponse>;
|
|
26
|
+
getPublicKey(): Promise<IGetPublicKeyResponse>;
|
|
27
|
+
pickAddress(): Promise<IPickAddressResponse>;
|
|
28
|
+
AddressToScriptHash(params: IAddressToScriptHashParams): Promise<IAddressToScriptHashResponse>;
|
|
29
|
+
ScriptHashToAddress(params: IScriptHashToAddressParams): Promise<IScriptHashToAddressResponse>;
|
|
30
|
+
getBalance(params?: IGetBalanceParams): Promise<IGetBalanceResponse>;
|
|
31
|
+
getStorage(params?: IGetStorageParams): Promise<IGetStorageResponse>;
|
|
32
|
+
getBlock(params: IGetBlockParams): Promise<IRpcResponse>;
|
|
33
|
+
getTransaction(params: IGetTransactionParams): Promise<IRpcResponse>;
|
|
34
|
+
getApplicationLog(params: IGetApplicationLogParams): Promise<IRpcResponse>;
|
|
35
|
+
invokeRead(params: IInvokeReadParams): Promise<IInvokeReadResponse>;
|
|
36
|
+
invokeReadMulti(params: IInvokeReadMultiParams): Promise<IInvokeReadResponse>;
|
|
37
|
+
verifyMessage(params: IVerifyMessageParams): Promise<IVerifyMessageResponse>;
|
|
38
|
+
verifyMessageV2(params: IVerifyMessageV2Params): Promise<IVerifyMessageV2Response>;
|
|
39
|
+
send(params: ISendParams): Promise<ISendResponse>;
|
|
40
|
+
invoke(params: IInvokeParams): Promise<IInvokeResponse>;
|
|
41
|
+
invokeMultiple(params: IInvokeMultipleParams): Promise<IInvokeResponse>;
|
|
42
|
+
signMessage(params: ISignMessageV2Params): Promise<ISignMessageV2Response>;
|
|
43
|
+
signMessageV2(params: ISignMessageV2Params): Promise<ISignMessageV2Response>;
|
|
44
|
+
signMessageWithoutSalt(params: ISignMessageWithoutSaltV2Params): Promise<ISignMessageWithoutSaltV2Response>;
|
|
45
|
+
signMessageWithoutSaltV2(params: ISignMessageWithoutSaltV2Params): Promise<ISignMessageWithoutSaltV2Response>;
|
|
46
|
+
signTransaction(params: ISignTransactionParams): Promise<ISignTransactionResponse>;
|
|
47
|
+
switchWalletNetwork(params: ISwitchWalletNetworkParams): Promise<ISwitchWalletNetworkResponse>;
|
|
48
|
+
switchWalletAccount(): Promise<IGetAccountResponse>;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* ProviderNeo is the core implementation that communicates with OneKey Wallet
|
|
54
|
+
*/
|
|
55
|
+
declare class ProviderNeo extends ProviderNeoBase implements INeoProviderMethods {
|
|
56
|
+
constructor(props: IInpageProviderConfig & {
|
|
57
|
+
timeout?: number;
|
|
58
|
+
});
|
|
59
|
+
private _registerEvents;
|
|
60
|
+
private _handleDisconnected;
|
|
61
|
+
private _handleAccountChange;
|
|
62
|
+
on<E extends keyof NeoProviderEventsMap>(event: E, listener: NeoProviderEventsMap[E]): this;
|
|
63
|
+
off<E extends keyof NeoProviderEventsMap>(event: E, listener: NeoProviderEventsMap[E]): this;
|
|
64
|
+
emit<E extends keyof NeoProviderEventsMap>(event: E, ...args: Parameters<NeoProviderEventsMap[E]>): boolean;
|
|
65
|
+
private _callBridge;
|
|
66
|
+
getProvider(): Promise<INeoGetProviderResponse>;
|
|
67
|
+
getNetworks(): Promise<INeoNetworkResponse>;
|
|
68
|
+
getAccount(): Promise<IGetAccountResponse>;
|
|
69
|
+
getPublicKey(): Promise<IGetPublicKeyResponse>;
|
|
70
|
+
getBalance(params?: IGetBalanceParams): Promise<IGetBalanceResponse>;
|
|
71
|
+
getStorage(params?: IGetStorageParams): Promise<IGetStorageResponse>;
|
|
72
|
+
getBlock(params: IGetBlockParams): Promise<IRpcResponse>;
|
|
73
|
+
getTransaction(params: IGetTransactionParams): Promise<IRpcResponse>;
|
|
74
|
+
getApplicationLog(params: IGetApplicationLogParams): Promise<IRpcResponse>;
|
|
75
|
+
invokeRead(params: IInvokeReadParams): Promise<IInvokeReadResponse>;
|
|
76
|
+
invokeReadMulti(params: IInvokeReadMultiParams): Promise<IInvokeReadResponse>;
|
|
77
|
+
verifyMessage(params: IVerifyMessageParams): Promise<IVerifyMessageResponse>;
|
|
78
|
+
verifyMessageV2(params: IVerifyMessageV2Params): Promise<IVerifyMessageV2Response>;
|
|
79
|
+
pickAddress(): Promise<IPickAddressResponse>;
|
|
80
|
+
AddressToScriptHash(params: IAddressToScriptHashParams): Promise<IAddressToScriptHashResponse>;
|
|
81
|
+
ScriptHashToAddress(params: IScriptHashToAddressParams): Promise<IScriptHashToAddressResponse>;
|
|
82
|
+
send(params: ISendParams): Promise<ISendResponse>;
|
|
83
|
+
invoke(params: IInvokeParams): Promise<IInvokeResponse>;
|
|
84
|
+
invokeMultiple(params: IInvokeMultipleParams): Promise<IInvokeResponse>;
|
|
85
|
+
signMessage(params: ISignMessageV2Params): Promise<ISignMessageV2Response>;
|
|
86
|
+
signMessageV2(params: ISignMessageV2Params): Promise<ISignMessageV2Response>;
|
|
87
|
+
signMessageWithoutSalt(params: ISignMessageWithoutSaltV2Params): Promise<ISignMessageWithoutSaltV2Response>;
|
|
88
|
+
signMessageWithoutSaltV2(params: ISignMessageWithoutSaltV2Params): Promise<ISignMessageWithoutSaltV2Response>;
|
|
89
|
+
signTransaction(params: ISignTransactionParams): Promise<ISignTransactionResponse>;
|
|
90
|
+
switchWalletNetwork(params: ISwitchWalletNetworkParams): Promise<ISwitchWalletNetworkResponse>;
|
|
91
|
+
switchWalletAccount(): Promise<IGetAccountResponse>;
|
|
92
|
+
}
|
|
93
|
+
export { NEOLineN3, ProviderNeo, emitNeoReadyEvent };
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { getOrCreateExtInjectedJsBridge } from '@onekeyfe/extension-bridge-injected';
|
|
11
|
+
import { ProviderNeoBase } from './ProviderNeoBase';
|
|
12
|
+
const PROVIDER_EVENTS = {
|
|
13
|
+
'connect': 'connect',
|
|
14
|
+
'disconnect': 'disconnect',
|
|
15
|
+
'accountChanged': 'accountChanged',
|
|
16
|
+
'message_low_level': 'message_low_level',
|
|
17
|
+
};
|
|
18
|
+
function isWalletEventMethodMatch(method, name) {
|
|
19
|
+
return method === `metamask_${name}` || method === `wallet_events_${name}`;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* send NEOLine.N3.EVENT.READY event to notify the page that Neo Provider is ready
|
|
23
|
+
*/
|
|
24
|
+
function emitNeoReadyEvent() {
|
|
25
|
+
if (typeof window === 'undefined') {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const readyEvent = new Event('NEOLine.N3.EVENT.READY');
|
|
29
|
+
window.dispatchEvent(readyEvent);
|
|
30
|
+
const neoReadyEvent = new Event('NEOLine.NEO.EVENT.READY');
|
|
31
|
+
window.dispatchEvent(neoReadyEvent);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* NEOLineN3 is a class to provide compatibility with Neo dAPI
|
|
35
|
+
*/
|
|
36
|
+
class NEOLineN3 {
|
|
37
|
+
}
|
|
38
|
+
NEOLineN3.instance = null;
|
|
39
|
+
NEOLineN3.Init = class Init {
|
|
40
|
+
constructor() {
|
|
41
|
+
if (!NEOLineN3.instance) {
|
|
42
|
+
throw new Error('NEOLineN3 instance not available');
|
|
43
|
+
}
|
|
44
|
+
this.provider = NEOLineN3.instance;
|
|
45
|
+
}
|
|
46
|
+
getProvider() {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
return this.provider.getProvider();
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
getNetworks() {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
return this.provider.getNetworks();
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
getAccount() {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
return this.provider.getAccount();
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
getPublicKey() {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
return this.provider.getPublicKey();
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
pickAddress() {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
return this.provider.pickAddress();
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
AddressToScriptHash(params) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
return this.provider.AddressToScriptHash(params);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
ScriptHashToAddress(params) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
return this.provider.ScriptHashToAddress(params);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
getBalance(params) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
return this.provider.getBalance(params);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
getStorage(params) {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
return this.provider.getStorage(params);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
getBlock(params) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
return this.provider.getBlock(params);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
getTransaction(params) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
return this.provider.getTransaction(params);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
getApplicationLog(params) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
return this.provider.getApplicationLog(params);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
invokeRead(params) {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
return this.provider.invokeRead(params);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
invokeReadMulti(params) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
return this.provider.invokeReadMulti(params);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
verifyMessage(params) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
return this.provider.verifyMessage(params);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
verifyMessageV2(params) {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
return this.provider.verifyMessageV2(params);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
send(params) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
return this.provider.send(params);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
invoke(params) {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
return this.provider.invoke(params);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
invokeMultiple(params) {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
return this.provider.invokeMultiple(params);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
signMessage(params) {
|
|
142
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
return this.provider.signMessage(params);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
signMessageV2(params) {
|
|
147
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
148
|
+
return this.provider.signMessageV2(params);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
signMessageWithoutSalt(params) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
return this.provider.signMessageWithoutSalt(params);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
signMessageWithoutSaltV2(params) {
|
|
157
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
+
return this.provider.signMessageWithoutSaltV2(params);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
signTransaction(params) {
|
|
162
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
163
|
+
return this.provider.signTransaction(params);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
switchWalletNetwork(params) {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
return this.provider.switchWalletNetwork(params);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
switchWalletAccount() {
|
|
172
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
173
|
+
return this.provider.switchWalletAccount();
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* ProviderNeo is the core implementation that communicates with OneKey Wallet
|
|
179
|
+
*/
|
|
180
|
+
class ProviderNeo extends ProviderNeoBase {
|
|
181
|
+
constructor(props) {
|
|
182
|
+
super(Object.assign(Object.assign({}, props), { bridge: props.bridge || getOrCreateExtInjectedJsBridge({ timeout: props.timeout }) }));
|
|
183
|
+
this._registerEvents();
|
|
184
|
+
}
|
|
185
|
+
_registerEvents() {
|
|
186
|
+
window.addEventListener('onekey_bridge_disconnect', () => {
|
|
187
|
+
this._handleDisconnected();
|
|
188
|
+
});
|
|
189
|
+
this.on(PROVIDER_EVENTS.message_low_level, (payload) => {
|
|
190
|
+
const { method } = payload;
|
|
191
|
+
if (isWalletEventMethodMatch(method, PROVIDER_EVENTS.accountChanged)) {
|
|
192
|
+
this._handleAccountChange();
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
_handleDisconnected(options = { emit: true }) {
|
|
197
|
+
if (options.emit && this.isConnectionStatusChanged('disconnected')) {
|
|
198
|
+
this.emit('disconnect');
|
|
199
|
+
this.emit('accountChanged');
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
_handleAccountChange() {
|
|
203
|
+
this.emit('accountChanged');
|
|
204
|
+
}
|
|
205
|
+
on(event, listener) {
|
|
206
|
+
return super.on(event, listener);
|
|
207
|
+
}
|
|
208
|
+
off(event, listener) {
|
|
209
|
+
return super.off(event, listener);
|
|
210
|
+
}
|
|
211
|
+
emit(event, ...args) {
|
|
212
|
+
return super.emit(event, ...args);
|
|
213
|
+
}
|
|
214
|
+
_callBridge(params) {
|
|
215
|
+
return this.bridgeRequest(params);
|
|
216
|
+
}
|
|
217
|
+
getProvider() {
|
|
218
|
+
return this._callBridge({ method: 'getProvider' });
|
|
219
|
+
}
|
|
220
|
+
getNetworks() {
|
|
221
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
222
|
+
return this._callBridge({ method: 'getNetworks' });
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
getAccount() {
|
|
226
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
227
|
+
return this._callBridge({ method: 'getAccount' });
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
getPublicKey() {
|
|
231
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
+
return this._callBridge({ method: 'getPublicKey' });
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
getBalance(params) {
|
|
236
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
237
|
+
return this._callBridge({ method: 'getBalance', params });
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
getStorage(params) {
|
|
241
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
242
|
+
return this._callBridge({ method: 'getStorage', params });
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
getBlock(params) {
|
|
246
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
247
|
+
return this._callBridge({ method: 'getBlock', params });
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
getTransaction(params) {
|
|
251
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
252
|
+
return this._callBridge({ method: 'getTransaction', params });
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
getApplicationLog(params) {
|
|
256
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
257
|
+
return this._callBridge({ method: 'getApplicationLog', params });
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
invokeRead(params) {
|
|
261
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
262
|
+
return this._callBridge({ method: 'invokeRead', params });
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
invokeReadMulti(params) {
|
|
266
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
267
|
+
return this._callBridge({ method: 'invokeReadMulti', params });
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
verifyMessage(params) {
|
|
271
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
272
|
+
return this._callBridge({ method: 'verifyMessage', params });
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
verifyMessageV2(params) {
|
|
276
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
277
|
+
return this._callBridge({ method: 'verifyMessageV2', params });
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
pickAddress() {
|
|
281
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
282
|
+
return this._callBridge({ method: 'pickAddress' });
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
AddressToScriptHash(params) {
|
|
286
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
287
|
+
return this._callBridge({ method: 'AddressToScriptHash', params });
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
ScriptHashToAddress(params) {
|
|
291
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
292
|
+
return this._callBridge({ method: 'ScriptHashToAddress', params });
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
send(params) {
|
|
296
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
297
|
+
return this._callBridge({ method: 'send', params });
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
invoke(params) {
|
|
301
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
302
|
+
return this._callBridge({ method: 'invoke', params });
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
invokeMultiple(params) {
|
|
306
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
307
|
+
return this._callBridge({ method: 'invokeMultiple', params });
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
signMessage(params) {
|
|
311
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
312
|
+
return this._callBridge({ method: 'signMessage', params });
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
signMessageV2(params) {
|
|
316
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
317
|
+
return this._callBridge({ method: 'signMessageV2', params });
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
signMessageWithoutSalt(params) {
|
|
321
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
322
|
+
return this._callBridge({ method: 'signMessageWithoutSalt', params });
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
signMessageWithoutSaltV2(params) {
|
|
326
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
327
|
+
return this._callBridge({ method: 'signMessageWithoutSaltV2', params });
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
signTransaction(params) {
|
|
331
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
332
|
+
return this._callBridge({ method: 'signTransaction', params });
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
switchWalletNetwork(params) {
|
|
336
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
337
|
+
return this._callBridge({ method: 'switchWalletNetwork', params });
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
switchWalletAccount() {
|
|
341
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
342
|
+
return this._callBridge({ method: 'switchWalletAccount' });
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
export { NEOLineN3, ProviderNeo, emitNeoReadyEvent };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IInjectedProviderNames } from '@onekeyfe/cross-inpage-provider-types';
|
|
2
|
+
import { ProviderBase, IInpageProviderConfig } from '@onekeyfe/cross-inpage-provider-core';
|
|
3
|
+
declare class ProviderNeoBase extends ProviderBase {
|
|
4
|
+
constructor(props: IInpageProviderConfig);
|
|
5
|
+
protected providerName: IInjectedProviderNames;
|
|
6
|
+
request(data: unknown): Promise<unknown>;
|
|
7
|
+
}
|
|
8
|
+
export { ProviderNeoBase };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IInjectedProviderNames } from '@onekeyfe/cross-inpage-provider-types';
|
|
2
|
+
import { ProviderBase } from '@onekeyfe/cross-inpage-provider-core';
|
|
3
|
+
class ProviderNeoBase extends ProviderBase {
|
|
4
|
+
constructor(props) {
|
|
5
|
+
super(props);
|
|
6
|
+
this.providerName = IInjectedProviderNames.neo;
|
|
7
|
+
}
|
|
8
|
+
request(data) {
|
|
9
|
+
return this.bridgeRequest(data);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export { ProviderNeoBase };
|
|
@@ -0,0 +1,351 @@
|
|
|
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.ProviderNeo = exports.NEOLineN3 = void 0;
|
|
13
|
+
exports.emitNeoReadyEvent = emitNeoReadyEvent;
|
|
14
|
+
const extension_bridge_injected_1 = require("@onekeyfe/extension-bridge-injected");
|
|
15
|
+
const ProviderNeoBase_1 = require("./ProviderNeoBase");
|
|
16
|
+
const PROVIDER_EVENTS = {
|
|
17
|
+
'connect': 'connect',
|
|
18
|
+
'disconnect': 'disconnect',
|
|
19
|
+
'accountChanged': 'accountChanged',
|
|
20
|
+
'message_low_level': 'message_low_level',
|
|
21
|
+
};
|
|
22
|
+
function isWalletEventMethodMatch(method, name) {
|
|
23
|
+
return method === `metamask_${name}` || method === `wallet_events_${name}`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* send NEOLine.N3.EVENT.READY event to notify the page that Neo Provider is ready
|
|
27
|
+
*/
|
|
28
|
+
function emitNeoReadyEvent() {
|
|
29
|
+
if (typeof window === 'undefined') {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const readyEvent = new Event('NEOLine.N3.EVENT.READY');
|
|
33
|
+
window.dispatchEvent(readyEvent);
|
|
34
|
+
const neoReadyEvent = new Event('NEOLine.NEO.EVENT.READY');
|
|
35
|
+
window.dispatchEvent(neoReadyEvent);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* NEOLineN3 is a class to provide compatibility with Neo dAPI
|
|
39
|
+
*/
|
|
40
|
+
class NEOLineN3 {
|
|
41
|
+
}
|
|
42
|
+
exports.NEOLineN3 = NEOLineN3;
|
|
43
|
+
NEOLineN3.instance = null;
|
|
44
|
+
NEOLineN3.Init = class Init {
|
|
45
|
+
constructor() {
|
|
46
|
+
if (!NEOLineN3.instance) {
|
|
47
|
+
throw new Error('NEOLineN3 instance not available');
|
|
48
|
+
}
|
|
49
|
+
this.provider = NEOLineN3.instance;
|
|
50
|
+
}
|
|
51
|
+
getProvider() {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
return this.provider.getProvider();
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
getNetworks() {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
return this.provider.getNetworks();
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
getAccount() {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
return this.provider.getAccount();
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
getPublicKey() {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
return this.provider.getPublicKey();
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
pickAddress() {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
return this.provider.pickAddress();
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
AddressToScriptHash(params) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
return this.provider.AddressToScriptHash(params);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
ScriptHashToAddress(params) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
return this.provider.ScriptHashToAddress(params);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
getBalance(params) {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
return this.provider.getBalance(params);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
getStorage(params) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
return this.provider.getStorage(params);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
getBlock(params) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
return this.provider.getBlock(params);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
getTransaction(params) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
return this.provider.getTransaction(params);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
getApplicationLog(params) {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
return this.provider.getApplicationLog(params);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
invokeRead(params) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
return this.provider.invokeRead(params);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
invokeReadMulti(params) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
return this.provider.invokeReadMulti(params);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
verifyMessage(params) {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
return this.provider.verifyMessage(params);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
verifyMessageV2(params) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
return this.provider.verifyMessageV2(params);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
send(params) {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
return this.provider.send(params);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
invoke(params) {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
return this.provider.invoke(params);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
invokeMultiple(params) {
|
|
142
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
return this.provider.invokeMultiple(params);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
signMessage(params) {
|
|
147
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
148
|
+
return this.provider.signMessage(params);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
signMessageV2(params) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
return this.provider.signMessageV2(params);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
signMessageWithoutSalt(params) {
|
|
157
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
+
return this.provider.signMessageWithoutSalt(params);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
signMessageWithoutSaltV2(params) {
|
|
162
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
163
|
+
return this.provider.signMessageWithoutSaltV2(params);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
signTransaction(params) {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
return this.provider.signTransaction(params);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
switchWalletNetwork(params) {
|
|
172
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
173
|
+
return this.provider.switchWalletNetwork(params);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
switchWalletAccount() {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
return this.provider.switchWalletAccount();
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* ProviderNeo is the core implementation that communicates with OneKey Wallet
|
|
184
|
+
*/
|
|
185
|
+
class ProviderNeo extends ProviderNeoBase_1.ProviderNeoBase {
|
|
186
|
+
constructor(props) {
|
|
187
|
+
super(Object.assign(Object.assign({}, props), { bridge: props.bridge || (0, extension_bridge_injected_1.getOrCreateExtInjectedJsBridge)({ timeout: props.timeout }) }));
|
|
188
|
+
this._registerEvents();
|
|
189
|
+
}
|
|
190
|
+
_registerEvents() {
|
|
191
|
+
window.addEventListener('onekey_bridge_disconnect', () => {
|
|
192
|
+
this._handleDisconnected();
|
|
193
|
+
});
|
|
194
|
+
this.on(PROVIDER_EVENTS.message_low_level, (payload) => {
|
|
195
|
+
const { method } = payload;
|
|
196
|
+
if (isWalletEventMethodMatch(method, PROVIDER_EVENTS.accountChanged)) {
|
|
197
|
+
this._handleAccountChange();
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
_handleDisconnected(options = { emit: true }) {
|
|
202
|
+
if (options.emit && this.isConnectionStatusChanged('disconnected')) {
|
|
203
|
+
this.emit('disconnect');
|
|
204
|
+
this.emit('accountChanged');
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
_handleAccountChange() {
|
|
208
|
+
this.emit('accountChanged');
|
|
209
|
+
}
|
|
210
|
+
on(event, listener) {
|
|
211
|
+
return super.on(event, listener);
|
|
212
|
+
}
|
|
213
|
+
off(event, listener) {
|
|
214
|
+
return super.off(event, listener);
|
|
215
|
+
}
|
|
216
|
+
emit(event, ...args) {
|
|
217
|
+
return super.emit(event, ...args);
|
|
218
|
+
}
|
|
219
|
+
_callBridge(params) {
|
|
220
|
+
return this.bridgeRequest(params);
|
|
221
|
+
}
|
|
222
|
+
getProvider() {
|
|
223
|
+
return this._callBridge({ method: 'getProvider' });
|
|
224
|
+
}
|
|
225
|
+
getNetworks() {
|
|
226
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
227
|
+
return this._callBridge({ method: 'getNetworks' });
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
getAccount() {
|
|
231
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
+
return this._callBridge({ method: 'getAccount' });
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
getPublicKey() {
|
|
236
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
237
|
+
return this._callBridge({ method: 'getPublicKey' });
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
getBalance(params) {
|
|
241
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
242
|
+
return this._callBridge({ method: 'getBalance', params });
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
getStorage(params) {
|
|
246
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
247
|
+
return this._callBridge({ method: 'getStorage', params });
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
getBlock(params) {
|
|
251
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
252
|
+
return this._callBridge({ method: 'getBlock', params });
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
getTransaction(params) {
|
|
256
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
257
|
+
return this._callBridge({ method: 'getTransaction', params });
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
getApplicationLog(params) {
|
|
261
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
262
|
+
return this._callBridge({ method: 'getApplicationLog', params });
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
invokeRead(params) {
|
|
266
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
267
|
+
return this._callBridge({ method: 'invokeRead', params });
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
invokeReadMulti(params) {
|
|
271
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
272
|
+
return this._callBridge({ method: 'invokeReadMulti', params });
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
verifyMessage(params) {
|
|
276
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
277
|
+
return this._callBridge({ method: 'verifyMessage', params });
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
verifyMessageV2(params) {
|
|
281
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
282
|
+
return this._callBridge({ method: 'verifyMessageV2', params });
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
pickAddress() {
|
|
286
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
287
|
+
return this._callBridge({ method: 'pickAddress' });
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
AddressToScriptHash(params) {
|
|
291
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
292
|
+
return this._callBridge({ method: 'AddressToScriptHash', params });
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
ScriptHashToAddress(params) {
|
|
296
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
297
|
+
return this._callBridge({ method: 'ScriptHashToAddress', params });
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
send(params) {
|
|
301
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
302
|
+
return this._callBridge({ method: 'send', params });
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
invoke(params) {
|
|
306
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
307
|
+
return this._callBridge({ method: 'invoke', params });
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
invokeMultiple(params) {
|
|
311
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
312
|
+
return this._callBridge({ method: 'invokeMultiple', params });
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
signMessage(params) {
|
|
316
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
317
|
+
return this._callBridge({ method: 'signMessage', params });
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
signMessageV2(params) {
|
|
321
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
322
|
+
return this._callBridge({ method: 'signMessageV2', params });
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
signMessageWithoutSalt(params) {
|
|
326
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
327
|
+
return this._callBridge({ method: 'signMessageWithoutSalt', params });
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
signMessageWithoutSaltV2(params) {
|
|
331
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
332
|
+
return this._callBridge({ method: 'signMessageWithoutSaltV2', params });
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
signTransaction(params) {
|
|
336
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
337
|
+
return this._callBridge({ method: 'signTransaction', params });
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
switchWalletNetwork(params) {
|
|
341
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
342
|
+
return this._callBridge({ method: 'switchWalletNetwork', params });
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
switchWalletAccount() {
|
|
346
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
347
|
+
return this._callBridge({ method: 'switchWalletAccount' });
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
exports.ProviderNeo = ProviderNeo;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProviderNeoBase = void 0;
|
|
4
|
+
const cross_inpage_provider_types_1 = require("@onekeyfe/cross-inpage-provider-types");
|
|
5
|
+
const cross_inpage_provider_core_1 = require("@onekeyfe/cross-inpage-provider-core");
|
|
6
|
+
class ProviderNeoBase extends cross_inpage_provider_core_1.ProviderBase {
|
|
7
|
+
constructor(props) {
|
|
8
|
+
super(props);
|
|
9
|
+
this.providerName = cross_inpage_provider_types_1.IInjectedProviderNames.neo;
|
|
10
|
+
}
|
|
11
|
+
request(data) {
|
|
12
|
+
return this.bridgeRequest(data);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.ProviderNeoBase = ProviderNeoBase;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./OneKeyNeoProvider"), exports);
|
|
19
|
+
__exportStar(require("./ProviderNeoBase"), exports);
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import type * as TypeUtils from './type-utils';
|
|
2
|
+
export interface IAccount {
|
|
3
|
+
address: string;
|
|
4
|
+
}
|
|
5
|
+
export interface INeoGetProviderResponse {
|
|
6
|
+
name: string;
|
|
7
|
+
website: string;
|
|
8
|
+
version: string;
|
|
9
|
+
compatibility: string[];
|
|
10
|
+
}
|
|
11
|
+
export interface INeoNetworkResponse {
|
|
12
|
+
networks: string[];
|
|
13
|
+
chainId: number;
|
|
14
|
+
defaultNetwork: string;
|
|
15
|
+
}
|
|
16
|
+
export interface IGetAccountResponse {
|
|
17
|
+
address: string;
|
|
18
|
+
label?: string;
|
|
19
|
+
isLedger: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface IGetPublicKeyResponse {
|
|
22
|
+
address: string;
|
|
23
|
+
publicKey: string;
|
|
24
|
+
}
|
|
25
|
+
export interface IBalanceRequest {
|
|
26
|
+
address: string;
|
|
27
|
+
contracts: string[];
|
|
28
|
+
}
|
|
29
|
+
export interface IBalanceResponse {
|
|
30
|
+
contract: string;
|
|
31
|
+
symbol: string;
|
|
32
|
+
amount: string;
|
|
33
|
+
}
|
|
34
|
+
export interface IGetBalanceParams {
|
|
35
|
+
params: IBalanceRequest[];
|
|
36
|
+
}
|
|
37
|
+
export interface IGetBalanceResponse {
|
|
38
|
+
[address: string]: IBalanceResponse[];
|
|
39
|
+
}
|
|
40
|
+
export interface IGetStorageParams {
|
|
41
|
+
scriptHash: string;
|
|
42
|
+
key: string;
|
|
43
|
+
}
|
|
44
|
+
export interface IGetStorageResponse {
|
|
45
|
+
result: string;
|
|
46
|
+
}
|
|
47
|
+
export interface IVerifyMessageV2Params {
|
|
48
|
+
message: string;
|
|
49
|
+
data: string;
|
|
50
|
+
publicKey: string;
|
|
51
|
+
}
|
|
52
|
+
export interface IVerifyMessageV2Response {
|
|
53
|
+
result: boolean;
|
|
54
|
+
}
|
|
55
|
+
export interface ISignMessageV2Params {
|
|
56
|
+
message: string;
|
|
57
|
+
isJsonObject?: boolean;
|
|
58
|
+
}
|
|
59
|
+
export interface ISignMessageV2Response {
|
|
60
|
+
publicKey: string;
|
|
61
|
+
data: string;
|
|
62
|
+
salt: string;
|
|
63
|
+
message: string;
|
|
64
|
+
}
|
|
65
|
+
export interface ISignMessageWithoutSaltV2Params {
|
|
66
|
+
message: string;
|
|
67
|
+
isJsonObject?: boolean;
|
|
68
|
+
}
|
|
69
|
+
export interface ISignMessageWithoutSaltV2Response {
|
|
70
|
+
publicKey: string;
|
|
71
|
+
data: string;
|
|
72
|
+
message: string;
|
|
73
|
+
}
|
|
74
|
+
export interface TransactionLike {
|
|
75
|
+
[key: string]: any;
|
|
76
|
+
}
|
|
77
|
+
export interface ISignTransactionParams {
|
|
78
|
+
transaction: TransactionLike;
|
|
79
|
+
magicNumber?: number;
|
|
80
|
+
}
|
|
81
|
+
export interface ISignTransactionResponse {
|
|
82
|
+
transaction: TransactionLike;
|
|
83
|
+
}
|
|
84
|
+
export interface ISwitchWalletNetworkParams {
|
|
85
|
+
chainId: number;
|
|
86
|
+
}
|
|
87
|
+
export interface ISwitchWalletNetworkResponse {
|
|
88
|
+
result: boolean;
|
|
89
|
+
}
|
|
90
|
+
export interface IArgument {
|
|
91
|
+
type: 'String' | 'Boolean' | 'Hash160' | 'Hash256' | 'Integer' | 'ByteArray' | 'Array' | 'Address';
|
|
92
|
+
value: any;
|
|
93
|
+
}
|
|
94
|
+
export interface IInvokeArguments {
|
|
95
|
+
scriptHash: string;
|
|
96
|
+
operation: string;
|
|
97
|
+
args: IArgument[];
|
|
98
|
+
}
|
|
99
|
+
export interface ISigners {
|
|
100
|
+
account: string;
|
|
101
|
+
scopes: string;
|
|
102
|
+
allowedContracts?: string[];
|
|
103
|
+
allowedGroups?: string[];
|
|
104
|
+
rules?: IWitnessRule[];
|
|
105
|
+
}
|
|
106
|
+
export interface IWitnessRule {
|
|
107
|
+
action: string;
|
|
108
|
+
condition: any;
|
|
109
|
+
}
|
|
110
|
+
export interface IInvokeMultipleParams {
|
|
111
|
+
fee?: string;
|
|
112
|
+
extraSystemFee?: string;
|
|
113
|
+
overrideSystemFee?: string;
|
|
114
|
+
invokeArgs?: IInvokeArguments[];
|
|
115
|
+
broadcastOverride?: boolean;
|
|
116
|
+
signers: ISigners[];
|
|
117
|
+
}
|
|
118
|
+
export interface IInvokeParams {
|
|
119
|
+
scriptHash: string;
|
|
120
|
+
operation: string;
|
|
121
|
+
args: IArgument[];
|
|
122
|
+
fee?: string;
|
|
123
|
+
extraSystemFee?: string;
|
|
124
|
+
overrideSystemFee?: string;
|
|
125
|
+
broadcastOverride?: boolean;
|
|
126
|
+
signers: ISigners[];
|
|
127
|
+
}
|
|
128
|
+
export interface IInvokeResponse {
|
|
129
|
+
txid?: string;
|
|
130
|
+
nodeURL?: string;
|
|
131
|
+
signedTx?: string;
|
|
132
|
+
}
|
|
133
|
+
export interface ISendParams {
|
|
134
|
+
fromAddress: string;
|
|
135
|
+
toAddress: string;
|
|
136
|
+
asset: string;
|
|
137
|
+
amount: string;
|
|
138
|
+
fee?: string;
|
|
139
|
+
broadcastOverride?: boolean;
|
|
140
|
+
}
|
|
141
|
+
export interface ISendResponse {
|
|
142
|
+
txid: string;
|
|
143
|
+
nodeURL?: string;
|
|
144
|
+
signedTx?: string;
|
|
145
|
+
}
|
|
146
|
+
export interface IInvokeReadParams {
|
|
147
|
+
scriptHash: string;
|
|
148
|
+
operation: string;
|
|
149
|
+
args: IArgument[];
|
|
150
|
+
signers: ISigners[];
|
|
151
|
+
}
|
|
152
|
+
export interface IInvokeReadResponse {
|
|
153
|
+
script: string;
|
|
154
|
+
state: string;
|
|
155
|
+
gas_consumed: string;
|
|
156
|
+
stack: IArgument[];
|
|
157
|
+
}
|
|
158
|
+
export interface IInvokeReadMultiParams {
|
|
159
|
+
invokeReadArgs: {
|
|
160
|
+
scriptHash: string;
|
|
161
|
+
operation: string;
|
|
162
|
+
args: IArgument[];
|
|
163
|
+
}[];
|
|
164
|
+
signers: ISigners[];
|
|
165
|
+
}
|
|
166
|
+
export interface IVerifyMessageParams {
|
|
167
|
+
message: string;
|
|
168
|
+
data: string;
|
|
169
|
+
publicKey: string;
|
|
170
|
+
}
|
|
171
|
+
export interface IVerifyMessageResponse {
|
|
172
|
+
result: boolean;
|
|
173
|
+
}
|
|
174
|
+
export interface IGetBlockParams {
|
|
175
|
+
blockHeight: number;
|
|
176
|
+
}
|
|
177
|
+
export interface IGetTransactionParams {
|
|
178
|
+
txid: string;
|
|
179
|
+
}
|
|
180
|
+
export interface IGetApplicationLogParams {
|
|
181
|
+
txid: string;
|
|
182
|
+
}
|
|
183
|
+
export interface IPickAddressResponse {
|
|
184
|
+
label: string;
|
|
185
|
+
address: string;
|
|
186
|
+
}
|
|
187
|
+
export interface IAddressToScriptHashParams {
|
|
188
|
+
address: string;
|
|
189
|
+
}
|
|
190
|
+
export interface IAddressToScriptHashResponse {
|
|
191
|
+
scriptHash: string;
|
|
192
|
+
}
|
|
193
|
+
export interface IScriptHashToAddressParams {
|
|
194
|
+
scriptHash: string;
|
|
195
|
+
}
|
|
196
|
+
export interface IScriptHashToAddressResponse {
|
|
197
|
+
address: string;
|
|
198
|
+
}
|
|
199
|
+
export interface IRpcResponse {
|
|
200
|
+
[key: string]: any;
|
|
201
|
+
}
|
|
202
|
+
export interface INeoProviderMethods {
|
|
203
|
+
/** Common Methods */
|
|
204
|
+
getNetworks(): Promise<INeoNetworkResponse>;
|
|
205
|
+
getAccount(): Promise<IGetAccountResponse>;
|
|
206
|
+
getPublicKey(): Promise<IGetPublicKeyResponse>;
|
|
207
|
+
/** Read Methods */
|
|
208
|
+
getProvider(): Promise<INeoGetProviderResponse>;
|
|
209
|
+
getBalance(params?: IGetBalanceParams): Promise<IGetBalanceResponse>;
|
|
210
|
+
getStorage(params?: IGetStorageParams): Promise<IGetStorageResponse>;
|
|
211
|
+
getBlock(params: IGetBlockParams): Promise<IRpcResponse>;
|
|
212
|
+
getTransaction(params: IGetTransactionParams): Promise<IRpcResponse>;
|
|
213
|
+
getApplicationLog(params: IGetApplicationLogParams): Promise<IRpcResponse>;
|
|
214
|
+
verifyMessage(params: IVerifyMessageParams): Promise<IVerifyMessageResponse>;
|
|
215
|
+
verifyMessageV2(params: IVerifyMessageV2Params): Promise<IVerifyMessageV2Response>;
|
|
216
|
+
invokeRead(params: IInvokeReadParams): Promise<IInvokeReadResponse>;
|
|
217
|
+
invokeReadMulti(params: IInvokeReadMultiParams): Promise<IInvokeReadResponse>;
|
|
218
|
+
pickAddress(): Promise<IPickAddressResponse>;
|
|
219
|
+
AddressToScriptHash(params: IAddressToScriptHashParams): Promise<IAddressToScriptHashResponse>;
|
|
220
|
+
ScriptHashToAddress(params: IScriptHashToAddressParams): Promise<IScriptHashToAddressResponse>;
|
|
221
|
+
/** Write Methods */
|
|
222
|
+
send(params: ISendParams): Promise<ISendResponse>;
|
|
223
|
+
invoke(params: IInvokeParams): Promise<IInvokeResponse>;
|
|
224
|
+
invokeMultiple(params: IInvokeMultipleParams): Promise<IInvokeResponse>;
|
|
225
|
+
signMessage(params: ISignMessageV2Params): Promise<ISignMessageV2Response>;
|
|
226
|
+
signMessageV2(params: ISignMessageV2Params): Promise<ISignMessageV2Response>;
|
|
227
|
+
signMessageWithoutSalt(params: ISignMessageWithoutSaltV2Params): Promise<ISignMessageWithoutSaltV2Response>;
|
|
228
|
+
signMessageWithoutSaltV2(params: ISignMessageWithoutSaltV2Params): Promise<ISignMessageWithoutSaltV2Response>;
|
|
229
|
+
signTransaction(params: ISignTransactionParams): Promise<ISignTransactionResponse>;
|
|
230
|
+
switchWalletNetwork(params: ISwitchWalletNetworkParams): Promise<ISwitchWalletNetworkResponse>;
|
|
231
|
+
switchWalletAccount(): Promise<IGetAccountResponse>;
|
|
232
|
+
}
|
|
233
|
+
export interface NeoProviderEventsMap {
|
|
234
|
+
connect: () => void;
|
|
235
|
+
disconnect: () => void;
|
|
236
|
+
accountChanged: () => void;
|
|
237
|
+
message_low_level: (payload: {
|
|
238
|
+
method: string;
|
|
239
|
+
[key: string]: any;
|
|
240
|
+
}) => void;
|
|
241
|
+
}
|
|
242
|
+
export type JsBridgeRequest = {
|
|
243
|
+
[K in keyof INeoProviderMethods]: (params: Parameters<INeoProviderMethods[K]>[0]) => Promise<TypeUtils.WireStringified<TypeUtils.ResolvePromise<ReturnType<INeoProviderMethods[K]>>>>;
|
|
244
|
+
};
|
|
245
|
+
export type JsBridgeRequestParams<T extends keyof JsBridgeRequest> = Parameters<JsBridgeRequest[T]>[0];
|
|
246
|
+
export type JsBridgeRequestResponse<T extends keyof JsBridgeRequest> = ReturnType<JsBridgeRequest[T]>;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@onekeyfe/onekey-neo-provider",
|
|
3
|
+
"version": "2.2.15",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"cross-inpage-provider"
|
|
6
|
+
],
|
|
7
|
+
"author": "dev-fe@onekey.so",
|
|
8
|
+
"repository": "https://github.com/OneKeyHQ/cross-inpage-provider",
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"files": [
|
|
15
|
+
"dist/*"
|
|
16
|
+
],
|
|
17
|
+
"exports": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.js",
|
|
20
|
+
"require": "./dist/cjs/index.js"
|
|
21
|
+
},
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"module": "./dist/index.js",
|
|
24
|
+
"main": "./dist/cjs/index.js",
|
|
25
|
+
"scripts": {
|
|
26
|
+
"prebuild": "rm -rf dist",
|
|
27
|
+
"build": "tsc && tsc --project tsconfig.cjs.json",
|
|
28
|
+
"start": "tsc --watch"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@onekeyfe/cross-inpage-provider-core": "2.2.15",
|
|
32
|
+
"@onekeyfe/cross-inpage-provider-errors": "2.2.15",
|
|
33
|
+
"@onekeyfe/cross-inpage-provider-types": "2.2.15",
|
|
34
|
+
"@onekeyfe/extension-bridge-injected": "2.2.15"
|
|
35
|
+
},
|
|
36
|
+
"gitHead": "4b2fffea66eb0e243ec7687dbde92758718e638c"
|
|
37
|
+
}
|