@onekeyfe/onekey-ton-provider 2.1.11 → 2.1.12
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.
|
@@ -29,6 +29,8 @@ export interface IProviderTon extends ProviderTonBase {
|
|
|
29
29
|
type OneKeyTonProviderProps = IInpageProviderConfig & {
|
|
30
30
|
timeout?: number;
|
|
31
31
|
};
|
|
32
|
+
export declare function createTonProviderOpenMask(originalProvider: ProviderTon): ProviderTon;
|
|
33
|
+
export declare function createTonProvider(originalProvider: ProviderTon, customDeviceInfo: Partial<DeviceInfo>, customWalletInfo: Partial<WalletInfo>): ProviderTon;
|
|
32
34
|
export declare class ProviderTon extends ProviderTonBase implements IProviderTon {
|
|
33
35
|
private _accountInfo;
|
|
34
36
|
deviceInfo: DeviceInfo;
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { getOrCreateExtInjectedJsBridge } from '@onekeyfe/extension-bridge-injected';
|
|
11
11
|
import { ProviderTonBase } from './ProviderTonBase';
|
|
12
|
-
import { CONNECT_EVENT_ERROR_CODES, SEND_TRANSACTION_ERROR_CODES } from '@tonconnect/protocol';
|
|
12
|
+
import { CONNECT_EVENT_ERROR_CODES, SEND_TRANSACTION_ERROR_CODES, } from '@tonconnect/protocol';
|
|
13
13
|
import { ConnectEventErrorMessage, SendTransactionErrorMessage, } from './types';
|
|
14
14
|
const PROVIDER_EVENTS = {
|
|
15
15
|
'disconnect': 'disconnect',
|
|
@@ -19,29 +19,50 @@ const PROVIDER_EVENTS = {
|
|
|
19
19
|
function isWalletEventMethodMatch({ method, name }) {
|
|
20
20
|
return method === `wallet_events_${name}`;
|
|
21
21
|
}
|
|
22
|
+
export function createTonProviderOpenMask(originalProvider) {
|
|
23
|
+
return createTonProvider(originalProvider, {
|
|
24
|
+
appName: 'openmask',
|
|
25
|
+
appVersion: '0.21.1',
|
|
26
|
+
}, {
|
|
27
|
+
name: 'OpenMask',
|
|
28
|
+
image: 'https://raw.githubusercontent.com/OpenProduct/openmask-extension/main/public/openmask-logo-288.png',
|
|
29
|
+
about_url: 'https://www.openmask.app/',
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export function createTonProvider(originalProvider, customDeviceInfo, customWalletInfo) {
|
|
33
|
+
return new Proxy(originalProvider, {
|
|
34
|
+
get(target, prop, receiver) {
|
|
35
|
+
if (prop === 'deviceInfo') {
|
|
36
|
+
return Object.assign(Object.assign({}, target.deviceInfo), customDeviceInfo);
|
|
37
|
+
}
|
|
38
|
+
if (prop === 'walletInfo') {
|
|
39
|
+
return Object.assign(Object.assign({}, target.walletInfo), customWalletInfo);
|
|
40
|
+
}
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
42
|
+
return Reflect.get(target, prop, receiver);
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
}
|
|
22
46
|
export class ProviderTon extends ProviderTonBase {
|
|
23
47
|
constructor(props) {
|
|
24
48
|
super(Object.assign(Object.assign({}, props), { bridge: props.bridge || getOrCreateExtInjectedJsBridge({ timeout: props.timeout }) }));
|
|
25
49
|
this._accountInfo = null;
|
|
26
50
|
this.deviceInfo = {
|
|
27
51
|
platform: this._getPlatform(),
|
|
28
|
-
appName: '
|
|
52
|
+
appName: 'onekey',
|
|
29
53
|
appVersion: '0.0.0',
|
|
30
54
|
maxProtocolVersion: 2,
|
|
31
|
-
features: [
|
|
32
|
-
{ name: 'SendTransaction', maxMessages: 4 },
|
|
33
|
-
{ name: 'SignData' },
|
|
34
|
-
],
|
|
55
|
+
features: [{ name: 'SendTransaction', maxMessages: 4 }, { name: 'SignData' }],
|
|
35
56
|
};
|
|
36
57
|
this.walletInfo = {
|
|
37
58
|
name: 'OneKey',
|
|
38
|
-
image: 'https://
|
|
59
|
+
image: 'https://common.onekey-asset.com/logo/onekey-x288.png',
|
|
39
60
|
about_url: 'https://onekey.so',
|
|
40
61
|
};
|
|
41
62
|
this.protocolVersion = 2;
|
|
42
63
|
this.isWalletBrowser = false;
|
|
43
64
|
this._id = 0;
|
|
44
|
-
void this._getDeviceInfo();
|
|
65
|
+
// void this._getDeviceInfo();
|
|
45
66
|
this._registerEvents();
|
|
46
67
|
}
|
|
47
68
|
_getPlatform() {
|
|
@@ -134,52 +155,55 @@ export class ProviderTon extends ProviderTonBase {
|
|
|
134
155
|
_connect(protocolVersion, message) {
|
|
135
156
|
return __awaiter(this, void 0, void 0, function* () {
|
|
136
157
|
const id = ++this._id;
|
|
137
|
-
const isGetTonAddr = !message || (message && message.items.some((item) => item.name ===
|
|
138
|
-
const proofItem = message &&
|
|
158
|
+
const isGetTonAddr = !message || (message && message.items.some((item) => item.name === 'ton_addr'));
|
|
159
|
+
const proofItem = message &&
|
|
160
|
+
message.items.find((item) => item.name === 'ton_proof');
|
|
139
161
|
const items = [];
|
|
140
162
|
if (isGetTonAddr) {
|
|
141
163
|
if (this._accountInfo) {
|
|
142
|
-
items.push(Object.assign({ name:
|
|
164
|
+
items.push(Object.assign({ name: 'ton_addr' }, this._accountInfo));
|
|
143
165
|
}
|
|
144
166
|
else {
|
|
145
167
|
const result = yield this._callBridge({
|
|
146
168
|
method: 'connect',
|
|
147
|
-
params:
|
|
169
|
+
params: protocolVersion && message ? [protocolVersion, message] : [],
|
|
148
170
|
});
|
|
149
171
|
if (!result) {
|
|
150
172
|
return {
|
|
151
|
-
event:
|
|
173
|
+
event: 'connect_error',
|
|
152
174
|
id,
|
|
153
175
|
payload: {
|
|
154
176
|
code: CONNECT_EVENT_ERROR_CODES.UNKNOWN_ERROR,
|
|
155
|
-
message: ConnectEventErrorMessage.UNKNOWN_ERROR
|
|
156
|
-
}
|
|
177
|
+
message: ConnectEventErrorMessage.UNKNOWN_ERROR,
|
|
178
|
+
},
|
|
157
179
|
};
|
|
158
180
|
}
|
|
159
|
-
items.push(Object.assign({ name:
|
|
181
|
+
items.push(Object.assign({ name: 'ton_addr' }, result));
|
|
160
182
|
this._handleConnected(result, { emit: true });
|
|
161
183
|
}
|
|
162
184
|
}
|
|
163
185
|
if (proofItem) {
|
|
164
186
|
const result = yield this._callBridge({
|
|
165
187
|
method: 'signProof',
|
|
166
|
-
params: [
|
|
188
|
+
params: [
|
|
189
|
+
{
|
|
167
190
|
payload: proofItem.payload,
|
|
168
|
-
}
|
|
191
|
+
},
|
|
192
|
+
],
|
|
169
193
|
});
|
|
170
194
|
if (!result) {
|
|
171
195
|
return {
|
|
172
|
-
event:
|
|
196
|
+
event: 'connect_error',
|
|
173
197
|
id,
|
|
174
198
|
payload: {
|
|
175
199
|
code: CONNECT_EVENT_ERROR_CODES.UNKNOWN_ERROR,
|
|
176
|
-
message: ConnectEventErrorMessage.UNKNOWN_ERROR
|
|
177
|
-
}
|
|
200
|
+
message: ConnectEventErrorMessage.UNKNOWN_ERROR,
|
|
201
|
+
},
|
|
178
202
|
};
|
|
179
203
|
}
|
|
180
204
|
items.push({
|
|
181
|
-
name:
|
|
182
|
-
proof: Object.assign(Object.assign({}, result), { payload: proofItem.payload })
|
|
205
|
+
name: 'ton_proof',
|
|
206
|
+
proof: Object.assign(Object.assign({}, result), { payload: proofItem.payload }),
|
|
183
207
|
});
|
|
184
208
|
}
|
|
185
209
|
return {
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.ProviderTon = void 0;
|
|
12
|
+
exports.ProviderTon = exports.createTonProvider = exports.createTonProviderOpenMask = void 0;
|
|
13
13
|
const extension_bridge_injected_1 = require("@onekeyfe/extension-bridge-injected");
|
|
14
14
|
const ProviderTonBase_1 = require("./ProviderTonBase");
|
|
15
15
|
const protocol_1 = require("@tonconnect/protocol");
|
|
@@ -22,29 +22,52 @@ const PROVIDER_EVENTS = {
|
|
|
22
22
|
function isWalletEventMethodMatch({ method, name }) {
|
|
23
23
|
return method === `wallet_events_${name}`;
|
|
24
24
|
}
|
|
25
|
+
function createTonProviderOpenMask(originalProvider) {
|
|
26
|
+
return createTonProvider(originalProvider, {
|
|
27
|
+
appName: 'openmask',
|
|
28
|
+
appVersion: '0.21.1',
|
|
29
|
+
}, {
|
|
30
|
+
name: 'OpenMask',
|
|
31
|
+
image: 'https://raw.githubusercontent.com/OpenProduct/openmask-extension/main/public/openmask-logo-288.png',
|
|
32
|
+
about_url: 'https://www.openmask.app/',
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
exports.createTonProviderOpenMask = createTonProviderOpenMask;
|
|
36
|
+
function createTonProvider(originalProvider, customDeviceInfo, customWalletInfo) {
|
|
37
|
+
return new Proxy(originalProvider, {
|
|
38
|
+
get(target, prop, receiver) {
|
|
39
|
+
if (prop === 'deviceInfo') {
|
|
40
|
+
return Object.assign(Object.assign({}, target.deviceInfo), customDeviceInfo);
|
|
41
|
+
}
|
|
42
|
+
if (prop === 'walletInfo') {
|
|
43
|
+
return Object.assign(Object.assign({}, target.walletInfo), customWalletInfo);
|
|
44
|
+
}
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
46
|
+
return Reflect.get(target, prop, receiver);
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
exports.createTonProvider = createTonProvider;
|
|
25
51
|
class ProviderTon extends ProviderTonBase_1.ProviderTonBase {
|
|
26
52
|
constructor(props) {
|
|
27
53
|
super(Object.assign(Object.assign({}, props), { bridge: props.bridge || (0, extension_bridge_injected_1.getOrCreateExtInjectedJsBridge)({ timeout: props.timeout }) }));
|
|
28
54
|
this._accountInfo = null;
|
|
29
55
|
this.deviceInfo = {
|
|
30
56
|
platform: this._getPlatform(),
|
|
31
|
-
appName: '
|
|
57
|
+
appName: 'onekey',
|
|
32
58
|
appVersion: '0.0.0',
|
|
33
59
|
maxProtocolVersion: 2,
|
|
34
|
-
features: [
|
|
35
|
-
{ name: 'SendTransaction', maxMessages: 4 },
|
|
36
|
-
{ name: 'SignData' },
|
|
37
|
-
],
|
|
60
|
+
features: [{ name: 'SendTransaction', maxMessages: 4 }, { name: 'SignData' }],
|
|
38
61
|
};
|
|
39
62
|
this.walletInfo = {
|
|
40
63
|
name: 'OneKey',
|
|
41
|
-
image: 'https://
|
|
64
|
+
image: 'https://common.onekey-asset.com/logo/onekey-x288.png',
|
|
42
65
|
about_url: 'https://onekey.so',
|
|
43
66
|
};
|
|
44
67
|
this.protocolVersion = 2;
|
|
45
68
|
this.isWalletBrowser = false;
|
|
46
69
|
this._id = 0;
|
|
47
|
-
void this._getDeviceInfo();
|
|
70
|
+
// void this._getDeviceInfo();
|
|
48
71
|
this._registerEvents();
|
|
49
72
|
}
|
|
50
73
|
_getPlatform() {
|
|
@@ -137,52 +160,55 @@ class ProviderTon extends ProviderTonBase_1.ProviderTonBase {
|
|
|
137
160
|
_connect(protocolVersion, message) {
|
|
138
161
|
return __awaiter(this, void 0, void 0, function* () {
|
|
139
162
|
const id = ++this._id;
|
|
140
|
-
const isGetTonAddr = !message || (message && message.items.some((item) => item.name ===
|
|
141
|
-
const proofItem = message &&
|
|
163
|
+
const isGetTonAddr = !message || (message && message.items.some((item) => item.name === 'ton_addr'));
|
|
164
|
+
const proofItem = message &&
|
|
165
|
+
message.items.find((item) => item.name === 'ton_proof');
|
|
142
166
|
const items = [];
|
|
143
167
|
if (isGetTonAddr) {
|
|
144
168
|
if (this._accountInfo) {
|
|
145
|
-
items.push(Object.assign({ name:
|
|
169
|
+
items.push(Object.assign({ name: 'ton_addr' }, this._accountInfo));
|
|
146
170
|
}
|
|
147
171
|
else {
|
|
148
172
|
const result = yield this._callBridge({
|
|
149
173
|
method: 'connect',
|
|
150
|
-
params:
|
|
174
|
+
params: protocolVersion && message ? [protocolVersion, message] : [],
|
|
151
175
|
});
|
|
152
176
|
if (!result) {
|
|
153
177
|
return {
|
|
154
|
-
event:
|
|
178
|
+
event: 'connect_error',
|
|
155
179
|
id,
|
|
156
180
|
payload: {
|
|
157
181
|
code: protocol_1.CONNECT_EVENT_ERROR_CODES.UNKNOWN_ERROR,
|
|
158
|
-
message: types_1.ConnectEventErrorMessage.UNKNOWN_ERROR
|
|
159
|
-
}
|
|
182
|
+
message: types_1.ConnectEventErrorMessage.UNKNOWN_ERROR,
|
|
183
|
+
},
|
|
160
184
|
};
|
|
161
185
|
}
|
|
162
|
-
items.push(Object.assign({ name:
|
|
186
|
+
items.push(Object.assign({ name: 'ton_addr' }, result));
|
|
163
187
|
this._handleConnected(result, { emit: true });
|
|
164
188
|
}
|
|
165
189
|
}
|
|
166
190
|
if (proofItem) {
|
|
167
191
|
const result = yield this._callBridge({
|
|
168
192
|
method: 'signProof',
|
|
169
|
-
params: [
|
|
193
|
+
params: [
|
|
194
|
+
{
|
|
170
195
|
payload: proofItem.payload,
|
|
171
|
-
}
|
|
196
|
+
},
|
|
197
|
+
],
|
|
172
198
|
});
|
|
173
199
|
if (!result) {
|
|
174
200
|
return {
|
|
175
|
-
event:
|
|
201
|
+
event: 'connect_error',
|
|
176
202
|
id,
|
|
177
203
|
payload: {
|
|
178
204
|
code: protocol_1.CONNECT_EVENT_ERROR_CODES.UNKNOWN_ERROR,
|
|
179
|
-
message: types_1.ConnectEventErrorMessage.UNKNOWN_ERROR
|
|
180
|
-
}
|
|
205
|
+
message: types_1.ConnectEventErrorMessage.UNKNOWN_ERROR,
|
|
206
|
+
},
|
|
181
207
|
};
|
|
182
208
|
}
|
|
183
209
|
items.push({
|
|
184
|
-
name:
|
|
185
|
-
proof: Object.assign(Object.assign({}, result), { payload: proofItem.payload })
|
|
210
|
+
name: 'ton_proof',
|
|
211
|
+
proof: Object.assign(Object.assign({}, result), { payload: proofItem.payload }),
|
|
186
212
|
});
|
|
187
213
|
}
|
|
188
214
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/onekey-ton-provider",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.12",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"cross-inpage-provider"
|
|
6
6
|
],
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
"start": "tsc --watch"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@onekeyfe/cross-inpage-provider-core": "2.1.
|
|
32
|
-
"@onekeyfe/cross-inpage-provider-errors": "2.1.
|
|
33
|
-
"@onekeyfe/cross-inpage-provider-types": "2.1.
|
|
34
|
-
"@onekeyfe/extension-bridge-injected": "2.1.
|
|
31
|
+
"@onekeyfe/cross-inpage-provider-core": "2.1.12",
|
|
32
|
+
"@onekeyfe/cross-inpage-provider-errors": "2.1.12",
|
|
33
|
+
"@onekeyfe/cross-inpage-provider-types": "2.1.12",
|
|
34
|
+
"@onekeyfe/extension-bridge-injected": "2.1.12",
|
|
35
35
|
"@tonconnect/protocol": "^2.2.6"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "5407a590d267cfd0a5fccd4fab057e0d9ff45732"
|
|
38
38
|
}
|