@onekeyfe/hd-web-sdk 0.0.2 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/iframe.html +1 -1
- package/build/js/iframe.9d569b5bafb1b842b4a0.js +3 -0
- package/build/js/{iframe.8d7c0d03eb4d55512f11.js.LICENSE.txt → iframe.9d569b5bafb1b842b4a0.js.LICENSE.txt} +0 -0
- package/build/js/iframe.9d569b5bafb1b842b4a0.js.map +1 -0
- package/build/onekey-js-sdk.js +478 -194
- package/build/onekey-js-sdk.js.map +1 -1
- package/build/onekey-js-sdk.min.js +1 -1
- package/build/onekey-js-sdk.min.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -7
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +8 -7
- package/build/js/iframe.8d7c0d03eb4d55512f11.js +0 -3
- package/build/js/iframe.8d7c0d03eb4d55512f11.js.map +0 -1
package/build/onekey-js-sdk.js
CHANGED
|
@@ -4108,10 +4108,10 @@ const inject = ({
|
|
|
4108
4108
|
connectId,
|
|
4109
4109
|
method: 'deviceReset'
|
|
4110
4110
|
})),
|
|
4111
|
-
deviceSettings: connectId => call({
|
|
4111
|
+
deviceSettings: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4112
4112
|
connectId,
|
|
4113
4113
|
method: 'deviceSettings'
|
|
4114
|
-
}),
|
|
4114
|
+
})),
|
|
4115
4115
|
deviceUpdateReboot: connectId => call({
|
|
4116
4116
|
connectId,
|
|
4117
4117
|
method: 'deviceUpdateReboot'
|
|
@@ -4167,6 +4167,26 @@ const inject = ({
|
|
|
4167
4167
|
btcVerifyMessage: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4168
4168
|
connectId,
|
|
4169
4169
|
method: 'btcVerifyMessage'
|
|
4170
|
+
})),
|
|
4171
|
+
starcoinGetAddress: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4172
|
+
connectId,
|
|
4173
|
+
method: 'starcoinGetAddress'
|
|
4174
|
+
})),
|
|
4175
|
+
starcoinGetPublicKey: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4176
|
+
connectId,
|
|
4177
|
+
method: 'starcoinGetPublicKey'
|
|
4178
|
+
})),
|
|
4179
|
+
starcoinSignMessage: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4180
|
+
connectId,
|
|
4181
|
+
method: 'starcoinSignMessage'
|
|
4182
|
+
})),
|
|
4183
|
+
starcoinSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4184
|
+
connectId,
|
|
4185
|
+
method: 'starcoinSignTransaction'
|
|
4186
|
+
})),
|
|
4187
|
+
starcoinVerifyMessage: (connectId, params) => call(Object.assign(Object.assign({}, params), {
|
|
4188
|
+
connectId,
|
|
4189
|
+
method: 'starcoinVerifyMessage'
|
|
4170
4190
|
}))
|
|
4171
4191
|
};
|
|
4172
4192
|
return api;
|
|
@@ -4978,6 +4998,173 @@ function create(arg, data) {
|
|
|
4978
4998
|
};
|
|
4979
4999
|
}
|
|
4980
5000
|
|
|
5001
|
+
const getDeviceType = features => {
|
|
5002
|
+
if (!features || typeof features !== 'object' || !features.serial_no) {
|
|
5003
|
+
return 'classic';
|
|
5004
|
+
}
|
|
5005
|
+
|
|
5006
|
+
const serialNo = features.serial_no;
|
|
5007
|
+
const miniFlag = serialNo.slice(0, 2);
|
|
5008
|
+
if (miniFlag.toLowerCase() === 'mi') return 'mini';
|
|
5009
|
+
return 'classic';
|
|
5010
|
+
};
|
|
5011
|
+
|
|
5012
|
+
const getDeviceUUID = features => {
|
|
5013
|
+
const deviceType = getDeviceType(features);
|
|
5014
|
+
|
|
5015
|
+
if (deviceType === 'classic') {
|
|
5016
|
+
return features.onekey_serial;
|
|
5017
|
+
}
|
|
5018
|
+
|
|
5019
|
+
return features.serial_no;
|
|
5020
|
+
};
|
|
5021
|
+
|
|
5022
|
+
const getDeviceLabel = features => {
|
|
5023
|
+
const deviceType = getDeviceType(features);
|
|
5024
|
+
|
|
5025
|
+
if (typeof features.label === 'string') {
|
|
5026
|
+
return features.label;
|
|
5027
|
+
}
|
|
5028
|
+
|
|
5029
|
+
return `My OneKey ${deviceType.charAt(0).toUpperCase() + deviceType.slice(1)}`;
|
|
5030
|
+
};
|
|
5031
|
+
|
|
5032
|
+
const getDeviceFirmwareVersion = features => {
|
|
5033
|
+
if (features.onekey_version) {
|
|
5034
|
+
return features.onekey_version.split('.');
|
|
5035
|
+
}
|
|
5036
|
+
|
|
5037
|
+
return [features.major_version, features.minor_version, features.patch_version];
|
|
5038
|
+
};
|
|
5039
|
+
|
|
5040
|
+
const getDeviceBLEFirmwareVersion = features => {
|
|
5041
|
+
if (!features.ble_ver) {
|
|
5042
|
+
return null;
|
|
5043
|
+
}
|
|
5044
|
+
|
|
5045
|
+
return features.ble_ver.split('.');
|
|
5046
|
+
};
|
|
5047
|
+
|
|
5048
|
+
const HD_HARDENED = 0x80000000;
|
|
5049
|
+
|
|
5050
|
+
const toHardened = n => (n | HD_HARDENED) >>> 0;
|
|
5051
|
+
|
|
5052
|
+
const fromHardened = n => (n & ~HD_HARDENED) >>> 0;
|
|
5053
|
+
|
|
5054
|
+
const PATH_NOT_VALID = TypedError('Method_InvalidParameter', 'Not a valid path');
|
|
5055
|
+
const PATH_NEGATIVE_VALUES = TypedError('Method_InvalidParameter', 'Path cannot contain negative values');
|
|
5056
|
+
|
|
5057
|
+
const getHDPath = path => {
|
|
5058
|
+
const parts = path.toLowerCase().split('/');
|
|
5059
|
+
if (parts[0] !== 'm') throw PATH_NOT_VALID;
|
|
5060
|
+
return parts.filter(p => p !== 'm' && p !== '').map(p => {
|
|
5061
|
+
let hardened = false;
|
|
5062
|
+
|
|
5063
|
+
if (p.substr(p.length - 1) === "'") {
|
|
5064
|
+
hardened = true;
|
|
5065
|
+
p = p.substr(0, p.length - 1);
|
|
5066
|
+
}
|
|
5067
|
+
|
|
5068
|
+
let n = parseInt(p);
|
|
5069
|
+
|
|
5070
|
+
if (Number.isNaN(n)) {
|
|
5071
|
+
throw PATH_NOT_VALID;
|
|
5072
|
+
} else if (n < 0) {
|
|
5073
|
+
throw PATH_NEGATIVE_VALUES;
|
|
5074
|
+
}
|
|
5075
|
+
|
|
5076
|
+
if (hardened) {
|
|
5077
|
+
n = toHardened(n);
|
|
5078
|
+
}
|
|
5079
|
+
|
|
5080
|
+
return n;
|
|
5081
|
+
});
|
|
5082
|
+
};
|
|
5083
|
+
|
|
5084
|
+
const isMultisigPath = path => Array.isArray(path) && path[0] === toHardened(48);
|
|
5085
|
+
|
|
5086
|
+
const isSegwitPath = path => Array.isArray(path) && path[0] === toHardened(49);
|
|
5087
|
+
|
|
5088
|
+
const getScriptType = path => {
|
|
5089
|
+
if (!Array.isArray(path) || path.length < 1) return 'SPENDADDRESS';
|
|
5090
|
+
const p1 = fromHardened(path[0]);
|
|
5091
|
+
|
|
5092
|
+
switch (p1) {
|
|
5093
|
+
case 48:
|
|
5094
|
+
return 'SPENDMULTISIG';
|
|
5095
|
+
|
|
5096
|
+
case 49:
|
|
5097
|
+
return 'SPENDP2SHWITNESS';
|
|
5098
|
+
|
|
5099
|
+
case 84:
|
|
5100
|
+
return 'SPENDWITNESS';
|
|
5101
|
+
|
|
5102
|
+
default:
|
|
5103
|
+
return 'SPENDADDRESS';
|
|
5104
|
+
}
|
|
5105
|
+
};
|
|
5106
|
+
|
|
5107
|
+
const getOutputScriptType = path => {
|
|
5108
|
+
if (!Array.isArray(path) || path.length < 1) return 'PAYTOADDRESS';
|
|
5109
|
+
|
|
5110
|
+
if (path[0] === 49) {
|
|
5111
|
+
return 'PAYTOP2SHWITNESS';
|
|
5112
|
+
}
|
|
5113
|
+
|
|
5114
|
+
const p = fromHardened(path[0]);
|
|
5115
|
+
|
|
5116
|
+
switch (p) {
|
|
5117
|
+
case 48:
|
|
5118
|
+
return 'PAYTOMULTISIG';
|
|
5119
|
+
|
|
5120
|
+
case 49:
|
|
5121
|
+
return 'PAYTOP2SHWITNESS';
|
|
5122
|
+
|
|
5123
|
+
case 84:
|
|
5124
|
+
return 'PAYTOWITNESS';
|
|
5125
|
+
|
|
5126
|
+
default:
|
|
5127
|
+
return 'PAYTOADDRESS';
|
|
5128
|
+
}
|
|
5129
|
+
};
|
|
5130
|
+
|
|
5131
|
+
const serializedPath = path => {
|
|
5132
|
+
const pathStr = path.map(p => {
|
|
5133
|
+
if (p & HD_HARDENED) {
|
|
5134
|
+
return `${p & ~HD_HARDENED}'`;
|
|
5135
|
+
}
|
|
5136
|
+
|
|
5137
|
+
return p;
|
|
5138
|
+
}).join('/');
|
|
5139
|
+
return `m/${pathStr}`;
|
|
5140
|
+
};
|
|
5141
|
+
|
|
5142
|
+
const validatePath = (path, length = 0, base = false) => {
|
|
5143
|
+
let valid;
|
|
5144
|
+
|
|
5145
|
+
if (typeof path === 'string') {
|
|
5146
|
+
valid = getHDPath(path);
|
|
5147
|
+
} else if (Array.isArray(path)) {
|
|
5148
|
+
valid = path.map(p => {
|
|
5149
|
+
const n = parseInt(p);
|
|
5150
|
+
|
|
5151
|
+
if (Number.isNaN(n)) {
|
|
5152
|
+
throw PATH_NOT_VALID;
|
|
5153
|
+
} else if (n < 0) {
|
|
5154
|
+
throw PATH_NEGATIVE_VALUES;
|
|
5155
|
+
}
|
|
5156
|
+
|
|
5157
|
+
return n;
|
|
5158
|
+
});
|
|
5159
|
+
} else {
|
|
5160
|
+
valid = undefined;
|
|
5161
|
+
}
|
|
5162
|
+
|
|
5163
|
+
if (!valid) throw PATH_NOT_VALID;
|
|
5164
|
+
if (length > 0 && valid.length < length) throw PATH_NOT_VALID;
|
|
5165
|
+
return base ? valid.splice(0, 3) : valid;
|
|
5166
|
+
};
|
|
5167
|
+
|
|
4981
5168
|
var nested = {
|
|
4982
5169
|
BinanceGetAddress: {
|
|
4983
5170
|
fields: {
|
|
@@ -13638,53 +13825,6 @@ var MessagesJSON = {
|
|
|
13638
13825
|
nested: nested
|
|
13639
13826
|
};
|
|
13640
13827
|
|
|
13641
|
-
const getDeviceType = features => {
|
|
13642
|
-
if (!features || typeof features !== 'object' || !features.serial_no) {
|
|
13643
|
-
return 'classic';
|
|
13644
|
-
}
|
|
13645
|
-
|
|
13646
|
-
const serialNo = features.serial_no;
|
|
13647
|
-
const miniFlag = serialNo.slice(0, 2);
|
|
13648
|
-
if (miniFlag.toLowerCase() === 'mi') return 'mini';
|
|
13649
|
-
return 'classic';
|
|
13650
|
-
};
|
|
13651
|
-
|
|
13652
|
-
const getDeviceUUID = features => {
|
|
13653
|
-
const deviceType = getDeviceType(features);
|
|
13654
|
-
|
|
13655
|
-
if (deviceType === 'classic') {
|
|
13656
|
-
return features.onekey_serial;
|
|
13657
|
-
}
|
|
13658
|
-
|
|
13659
|
-
return features.serial_no;
|
|
13660
|
-
};
|
|
13661
|
-
|
|
13662
|
-
const getDeviceLabel = features => {
|
|
13663
|
-
const deviceType = getDeviceType(features);
|
|
13664
|
-
|
|
13665
|
-
if (typeof features.label === 'string') {
|
|
13666
|
-
return features.label;
|
|
13667
|
-
}
|
|
13668
|
-
|
|
13669
|
-
return `My OneKey ${deviceType.charAt(0).toUpperCase() + deviceType.slice(1)}`;
|
|
13670
|
-
};
|
|
13671
|
-
|
|
13672
|
-
const getDeviceFirmwareVersion = features => {
|
|
13673
|
-
if (features.onekey_version) {
|
|
13674
|
-
return features.onekey_version.split('.');
|
|
13675
|
-
}
|
|
13676
|
-
|
|
13677
|
-
return [features.major_version, features.minor_version, features.patch_version];
|
|
13678
|
-
};
|
|
13679
|
-
|
|
13680
|
-
const getDeviceBLEFirmwareVersion = features => {
|
|
13681
|
-
if (!features.ble_ver) {
|
|
13682
|
-
return null;
|
|
13683
|
-
}
|
|
13684
|
-
|
|
13685
|
-
return features.ble_ver.split('.');
|
|
13686
|
-
};
|
|
13687
|
-
|
|
13688
13828
|
var _a;
|
|
13689
13829
|
|
|
13690
13830
|
class DataManager {
|
|
@@ -13926,7 +14066,10 @@ const createErrorMessage = error => ({
|
|
|
13926
14066
|
|
|
13927
14067
|
const UI_EVENT = 'UI_EVENT';
|
|
13928
14068
|
const UI_REQUEST$1 = {
|
|
13929
|
-
REQUEST_PIN: 'ui-request_pin'
|
|
14069
|
+
REQUEST_PIN: 'ui-request_pin',
|
|
14070
|
+
INVALID_PIN: 'ui-invalid_pin',
|
|
14071
|
+
REQUEST_BUTTON: 'ui-button',
|
|
14072
|
+
CLOSE_UI_WINDOW: 'ui-close_window'
|
|
13930
14073
|
};
|
|
13931
14074
|
|
|
13932
14075
|
const createUiMessage = (type, payload) => ({
|
|
@@ -13967,6 +14110,7 @@ const createUiResponse = (type, payload) => ({
|
|
|
13967
14110
|
payload
|
|
13968
14111
|
});
|
|
13969
14112
|
|
|
14113
|
+
const DEVICE_EVENT = 'DEVICE_EVENT';
|
|
13970
14114
|
const DEVICE = {
|
|
13971
14115
|
CONNECT: 'device-connect',
|
|
13972
14116
|
CONNECT_UNACQUIRED: 'device-connect_unacquired',
|
|
@@ -13986,6 +14130,12 @@ const DEVICE = {
|
|
|
13986
14130
|
WORD: 'word'
|
|
13987
14131
|
};
|
|
13988
14132
|
|
|
14133
|
+
const createDeviceMessage = (type, payload) => ({
|
|
14134
|
+
event: DEVICE_EVENT,
|
|
14135
|
+
type,
|
|
14136
|
+
payload
|
|
14137
|
+
});
|
|
14138
|
+
|
|
13989
14139
|
const assertType = (res, resType) => {
|
|
13990
14140
|
const splitResTypes = Array.isArray(resType) ? resType : resType.split('|');
|
|
13991
14141
|
|
|
@@ -14732,126 +14882,6 @@ class GetFeatures extends BaseMethod {
|
|
|
14732
14882
|
|
|
14733
14883
|
}
|
|
14734
14884
|
|
|
14735
|
-
const HD_HARDENED = 0x80000000;
|
|
14736
|
-
|
|
14737
|
-
const toHardened = n => (n | HD_HARDENED) >>> 0;
|
|
14738
|
-
|
|
14739
|
-
const fromHardened = n => (n & ~HD_HARDENED) >>> 0;
|
|
14740
|
-
|
|
14741
|
-
const PATH_NOT_VALID = TypedError('Method_InvalidParameter', 'Not a valid path');
|
|
14742
|
-
const PATH_NEGATIVE_VALUES = TypedError('Method_InvalidParameter', 'Path cannot contain negative values');
|
|
14743
|
-
|
|
14744
|
-
const getHDPath = path => {
|
|
14745
|
-
const parts = path.toLowerCase().split('/');
|
|
14746
|
-
if (parts[0] !== 'm') throw PATH_NOT_VALID;
|
|
14747
|
-
return parts.filter(p => p !== 'm' && p !== '').map(p => {
|
|
14748
|
-
let hardened = false;
|
|
14749
|
-
|
|
14750
|
-
if (p.substr(p.length - 1) === "'") {
|
|
14751
|
-
hardened = true;
|
|
14752
|
-
p = p.substr(0, p.length - 1);
|
|
14753
|
-
}
|
|
14754
|
-
|
|
14755
|
-
let n = parseInt(p);
|
|
14756
|
-
|
|
14757
|
-
if (Number.isNaN(n)) {
|
|
14758
|
-
throw PATH_NOT_VALID;
|
|
14759
|
-
} else if (n < 0) {
|
|
14760
|
-
throw PATH_NEGATIVE_VALUES;
|
|
14761
|
-
}
|
|
14762
|
-
|
|
14763
|
-
if (hardened) {
|
|
14764
|
-
n = toHardened(n);
|
|
14765
|
-
}
|
|
14766
|
-
|
|
14767
|
-
return n;
|
|
14768
|
-
});
|
|
14769
|
-
};
|
|
14770
|
-
|
|
14771
|
-
const isMultisigPath = path => Array.isArray(path) && path[0] === toHardened(48);
|
|
14772
|
-
|
|
14773
|
-
const isSegwitPath = path => Array.isArray(path) && path[0] === toHardened(49);
|
|
14774
|
-
|
|
14775
|
-
const getScriptType = path => {
|
|
14776
|
-
if (!Array.isArray(path) || path.length < 1) return 'SPENDADDRESS';
|
|
14777
|
-
const p1 = fromHardened(path[0]);
|
|
14778
|
-
|
|
14779
|
-
switch (p1) {
|
|
14780
|
-
case 48:
|
|
14781
|
-
return 'SPENDMULTISIG';
|
|
14782
|
-
|
|
14783
|
-
case 49:
|
|
14784
|
-
return 'SPENDP2SHWITNESS';
|
|
14785
|
-
|
|
14786
|
-
case 84:
|
|
14787
|
-
return 'SPENDWITNESS';
|
|
14788
|
-
|
|
14789
|
-
default:
|
|
14790
|
-
return 'SPENDADDRESS';
|
|
14791
|
-
}
|
|
14792
|
-
};
|
|
14793
|
-
|
|
14794
|
-
const getOutputScriptType = path => {
|
|
14795
|
-
if (!Array.isArray(path) || path.length < 1) return 'PAYTOADDRESS';
|
|
14796
|
-
|
|
14797
|
-
if (path[0] === 49) {
|
|
14798
|
-
return 'PAYTOP2SHWITNESS';
|
|
14799
|
-
}
|
|
14800
|
-
|
|
14801
|
-
const p = fromHardened(path[0]);
|
|
14802
|
-
|
|
14803
|
-
switch (p) {
|
|
14804
|
-
case 48:
|
|
14805
|
-
return 'PAYTOMULTISIG';
|
|
14806
|
-
|
|
14807
|
-
case 49:
|
|
14808
|
-
return 'PAYTOP2SHWITNESS';
|
|
14809
|
-
|
|
14810
|
-
case 84:
|
|
14811
|
-
return 'PAYTOWITNESS';
|
|
14812
|
-
|
|
14813
|
-
default:
|
|
14814
|
-
return 'PAYTOADDRESS';
|
|
14815
|
-
}
|
|
14816
|
-
};
|
|
14817
|
-
|
|
14818
|
-
const serializedPath = path => {
|
|
14819
|
-
const pathStr = path.map(p => {
|
|
14820
|
-
if (p & HD_HARDENED) {
|
|
14821
|
-
return `${p & ~HD_HARDENED}'`;
|
|
14822
|
-
}
|
|
14823
|
-
|
|
14824
|
-
return p;
|
|
14825
|
-
}).join('/');
|
|
14826
|
-
return `m/${pathStr}`;
|
|
14827
|
-
};
|
|
14828
|
-
|
|
14829
|
-
const validatePath = (path, length = 0, base = false) => {
|
|
14830
|
-
let valid;
|
|
14831
|
-
|
|
14832
|
-
if (typeof path === 'string') {
|
|
14833
|
-
valid = getHDPath(path);
|
|
14834
|
-
} else if (Array.isArray(path)) {
|
|
14835
|
-
valid = path.map(p => {
|
|
14836
|
-
const n = parseInt(p);
|
|
14837
|
-
|
|
14838
|
-
if (Number.isNaN(n)) {
|
|
14839
|
-
throw PATH_NOT_VALID;
|
|
14840
|
-
} else if (n < 0) {
|
|
14841
|
-
throw PATH_NEGATIVE_VALUES;
|
|
14842
|
-
}
|
|
14843
|
-
|
|
14844
|
-
return n;
|
|
14845
|
-
});
|
|
14846
|
-
} else {
|
|
14847
|
-
valid = undefined;
|
|
14848
|
-
}
|
|
14849
|
-
|
|
14850
|
-
if (!valid) throw PATH_NOT_VALID;
|
|
14851
|
-
if (length > 0 && valid.length < length) throw PATH_NOT_VALID;
|
|
14852
|
-
return base ? valid.splice(0, 3) : valid;
|
|
14853
|
-
};
|
|
14854
|
-
|
|
14855
14885
|
const hasHexPrefix = str => str.slice(0, 2).toLowerCase() === '0x';
|
|
14856
14886
|
|
|
14857
14887
|
const stripHexPrefix = str => hasHexPrefix(str) ? str.slice(2) : str;
|
|
@@ -15265,8 +15295,8 @@ class BTCGetPublicKey extends BaseMethod {
|
|
|
15265
15295
|
|
|
15266
15296
|
init() {
|
|
15267
15297
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
15268
|
-
|
|
15269
|
-
const payload = hasBundle ? this.payload : {
|
|
15298
|
+
this.hasBundle = Object.prototype.hasOwnProperty.call(this.payload, 'bundle');
|
|
15299
|
+
const payload = this.hasBundle ? this.payload : {
|
|
15270
15300
|
bundle: [this.payload]
|
|
15271
15301
|
};
|
|
15272
15302
|
validateParams(payload, [{
|
|
@@ -16446,7 +16476,7 @@ class EVMGetPublicKey extends BaseMethod {
|
|
|
16446
16476
|
|
|
16447
16477
|
}
|
|
16448
16478
|
|
|
16449
|
-
class EVMSignMessage$
|
|
16479
|
+
class EVMSignMessage$2 extends BaseMethod {
|
|
16450
16480
|
init() {
|
|
16451
16481
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
16452
16482
|
validateParams(this.payload, [{
|
|
@@ -16536,7 +16566,7 @@ class EVMSignTransaction extends BaseMethod {
|
|
|
16536
16566
|
const r = request.signature_r;
|
|
16537
16567
|
const s = request.signature_s;
|
|
16538
16568
|
|
|
16539
|
-
if (
|
|
16569
|
+
if (v == null || r == null || s == null) {
|
|
16540
16570
|
throw TypedError('Runtime', 'processTxRequest: Unexpected request');
|
|
16541
16571
|
}
|
|
16542
16572
|
|
|
@@ -16799,7 +16829,7 @@ class EVMSignMessageEIP712 extends BaseMethod {
|
|
|
16799
16829
|
|
|
16800
16830
|
}
|
|
16801
16831
|
|
|
16802
|
-
class EVMSignMessage extends BaseMethod {
|
|
16832
|
+
class EVMSignMessage$1 extends BaseMethod {
|
|
16803
16833
|
init() {
|
|
16804
16834
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
16805
16835
|
validateParams(this.payload, [{
|
|
@@ -16836,6 +16866,217 @@ class EVMSignMessage extends BaseMethod {
|
|
|
16836
16866
|
|
|
16837
16867
|
}
|
|
16838
16868
|
|
|
16869
|
+
class StarcoinGetAddress extends BaseMethod {
|
|
16870
|
+
constructor() {
|
|
16871
|
+
super(...arguments);
|
|
16872
|
+
this.hasBundle = false;
|
|
16873
|
+
}
|
|
16874
|
+
|
|
16875
|
+
init() {
|
|
16876
|
+
var _a;
|
|
16877
|
+
|
|
16878
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
16879
|
+
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
16880
|
+
const payload = this.hasBundle ? this.payload : {
|
|
16881
|
+
bundle: [this.payload]
|
|
16882
|
+
};
|
|
16883
|
+
validateParams(payload, [{
|
|
16884
|
+
name: 'bundle',
|
|
16885
|
+
type: 'array'
|
|
16886
|
+
}]);
|
|
16887
|
+
this.params = [];
|
|
16888
|
+
payload.bundle.forEach(batch => {
|
|
16889
|
+
var _a;
|
|
16890
|
+
|
|
16891
|
+
const addressN = validatePath(batch.path, 3);
|
|
16892
|
+
validateParams(batch, [{
|
|
16893
|
+
name: 'path',
|
|
16894
|
+
required: true
|
|
16895
|
+
}, {
|
|
16896
|
+
name: 'showOnOneKey',
|
|
16897
|
+
type: 'boolean'
|
|
16898
|
+
}]);
|
|
16899
|
+
const showOnOneKey = (_a = batch.showOnOneKey) !== null && _a !== void 0 ? _a : true;
|
|
16900
|
+
this.params.push({
|
|
16901
|
+
address_n: addressN,
|
|
16902
|
+
show_display: showOnOneKey
|
|
16903
|
+
});
|
|
16904
|
+
});
|
|
16905
|
+
}
|
|
16906
|
+
|
|
16907
|
+
run() {
|
|
16908
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16909
|
+
const responses = [];
|
|
16910
|
+
|
|
16911
|
+
for (let i = 0; i < this.params.length; i++) {
|
|
16912
|
+
const param = this.params[i];
|
|
16913
|
+
const res = yield this.device.commands.typedCall('StarcoinGetAddress', 'StarcoinAddress', Object.assign({}, param));
|
|
16914
|
+
responses.push(Object.assign({
|
|
16915
|
+
path: serializedPath(param.address_n)
|
|
16916
|
+
}, res.message));
|
|
16917
|
+
}
|
|
16918
|
+
|
|
16919
|
+
return Promise.resolve(this.hasBundle ? responses : responses[0]);
|
|
16920
|
+
});
|
|
16921
|
+
}
|
|
16922
|
+
|
|
16923
|
+
}
|
|
16924
|
+
|
|
16925
|
+
class StarcoinGetPublicKey extends BaseMethod {
|
|
16926
|
+
constructor() {
|
|
16927
|
+
super(...arguments);
|
|
16928
|
+
this.hasBundle = false;
|
|
16929
|
+
}
|
|
16930
|
+
|
|
16931
|
+
init() {
|
|
16932
|
+
var _a;
|
|
16933
|
+
|
|
16934
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
16935
|
+
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
16936
|
+
const payload = this.hasBundle ? this.payload : {
|
|
16937
|
+
bundle: [this.payload]
|
|
16938
|
+
};
|
|
16939
|
+
validateParams(payload, [{
|
|
16940
|
+
name: 'bundle',
|
|
16941
|
+
type: 'array'
|
|
16942
|
+
}]);
|
|
16943
|
+
this.params = [];
|
|
16944
|
+
payload.bundle.forEach(batch => {
|
|
16945
|
+
var _a;
|
|
16946
|
+
|
|
16947
|
+
const addressN = validatePath(batch.path, 3);
|
|
16948
|
+
validateParams(batch, [{
|
|
16949
|
+
name: 'path',
|
|
16950
|
+
required: true
|
|
16951
|
+
}, {
|
|
16952
|
+
name: 'showOnOneKey',
|
|
16953
|
+
type: 'boolean'
|
|
16954
|
+
}]);
|
|
16955
|
+
const showOnOneKey = (_a = batch.showOnOneKey) !== null && _a !== void 0 ? _a : true;
|
|
16956
|
+
this.params.push({
|
|
16957
|
+
address_n: addressN,
|
|
16958
|
+
show_display: showOnOneKey
|
|
16959
|
+
});
|
|
16960
|
+
});
|
|
16961
|
+
}
|
|
16962
|
+
|
|
16963
|
+
run() {
|
|
16964
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16965
|
+
const responses = [];
|
|
16966
|
+
|
|
16967
|
+
for (let i = 0; i < this.params.length; i++) {
|
|
16968
|
+
const param = this.params[i];
|
|
16969
|
+
const res = yield this.device.commands.typedCall('StarcoinGetPublicKey', 'StarcoinPublicKey', Object.assign({}, param));
|
|
16970
|
+
responses.push(Object.assign({
|
|
16971
|
+
path: serializedPath(param.address_n)
|
|
16972
|
+
}, res.message));
|
|
16973
|
+
}
|
|
16974
|
+
|
|
16975
|
+
return Promise.resolve(this.hasBundle ? responses : responses[0]);
|
|
16976
|
+
});
|
|
16977
|
+
}
|
|
16978
|
+
|
|
16979
|
+
}
|
|
16980
|
+
|
|
16981
|
+
class StarcoinSignMessage extends BaseMethod {
|
|
16982
|
+
init() {
|
|
16983
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
16984
|
+
validateParams(this.payload, [{
|
|
16985
|
+
name: 'path',
|
|
16986
|
+
required: true
|
|
16987
|
+
}, {
|
|
16988
|
+
name: 'messageHex',
|
|
16989
|
+
type: 'hexString',
|
|
16990
|
+
required: true
|
|
16991
|
+
}]);
|
|
16992
|
+
const {
|
|
16993
|
+
path,
|
|
16994
|
+
messageHex
|
|
16995
|
+
} = this.payload;
|
|
16996
|
+
const addressN = validatePath(path, 3);
|
|
16997
|
+
this.params = {
|
|
16998
|
+
address_n: addressN,
|
|
16999
|
+
message: formatAnyHex(messageHex)
|
|
17000
|
+
};
|
|
17001
|
+
}
|
|
17002
|
+
|
|
17003
|
+
run() {
|
|
17004
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17005
|
+
const res = yield this.device.commands.typedCall('StarcoinSignMessage', 'StarcoinMessageSignature', Object.assign({}, this.params));
|
|
17006
|
+
return Promise.resolve(res.message);
|
|
17007
|
+
});
|
|
17008
|
+
}
|
|
17009
|
+
|
|
17010
|
+
}
|
|
17011
|
+
|
|
17012
|
+
class StarcoinSignTransaction extends BaseMethod {
|
|
17013
|
+
init() {
|
|
17014
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
17015
|
+
validateParams(this.payload, [{
|
|
17016
|
+
name: 'path',
|
|
17017
|
+
required: true
|
|
17018
|
+
}, {
|
|
17019
|
+
name: 'rawTx',
|
|
17020
|
+
type: 'hexString',
|
|
17021
|
+
required: true
|
|
17022
|
+
}]);
|
|
17023
|
+
const {
|
|
17024
|
+
path,
|
|
17025
|
+
rawTx
|
|
17026
|
+
} = this.payload;
|
|
17027
|
+
const addressN = validatePath(path, 3);
|
|
17028
|
+
this.params = {
|
|
17029
|
+
address_n: addressN,
|
|
17030
|
+
raw_tx: formatAnyHex(rawTx)
|
|
17031
|
+
};
|
|
17032
|
+
}
|
|
17033
|
+
|
|
17034
|
+
run() {
|
|
17035
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17036
|
+
const res = yield this.device.commands.typedCall('StarcoinSignTx', 'StarcoinSignedTx', Object.assign({}, this.params));
|
|
17037
|
+
return Promise.resolve(res.message);
|
|
17038
|
+
});
|
|
17039
|
+
}
|
|
17040
|
+
|
|
17041
|
+
}
|
|
17042
|
+
|
|
17043
|
+
class EVMSignMessage extends BaseMethod {
|
|
17044
|
+
init() {
|
|
17045
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
17046
|
+
validateParams(this.payload, [{
|
|
17047
|
+
name: 'publicKey',
|
|
17048
|
+
type: 'string',
|
|
17049
|
+
required: true
|
|
17050
|
+
}, {
|
|
17051
|
+
name: 'messageHex',
|
|
17052
|
+
type: 'hexString',
|
|
17053
|
+
required: true
|
|
17054
|
+
}, {
|
|
17055
|
+
name: 'signature',
|
|
17056
|
+
type: 'hexString',
|
|
17057
|
+
required: true
|
|
17058
|
+
}]);
|
|
17059
|
+
const {
|
|
17060
|
+
publicKey,
|
|
17061
|
+
messageHex,
|
|
17062
|
+
signature
|
|
17063
|
+
} = formatAnyHex(this.payload);
|
|
17064
|
+
this.params = {
|
|
17065
|
+
public_key: publicKey,
|
|
17066
|
+
message: messageHex,
|
|
17067
|
+
signature
|
|
17068
|
+
};
|
|
17069
|
+
}
|
|
17070
|
+
|
|
17071
|
+
run() {
|
|
17072
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17073
|
+
const res = yield this.device.commands.typedCall('StarcoinVerifyMessage', 'Success', Object.assign({}, this.params));
|
|
17074
|
+
return Promise.resolve(res.message);
|
|
17075
|
+
});
|
|
17076
|
+
}
|
|
17077
|
+
|
|
17078
|
+
}
|
|
17079
|
+
|
|
16839
17080
|
var ApiMethods = /*#__PURE__*/Object.freeze({
|
|
16840
17081
|
__proto__: null,
|
|
16841
17082
|
searchDevices: SearchDevices,
|
|
@@ -16859,11 +17100,16 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
|
|
|
16859
17100
|
deviceWipe: DeviceWipe,
|
|
16860
17101
|
evmGetAddress: EvmGetAddress,
|
|
16861
17102
|
evmGetPublicKey: EVMGetPublicKey,
|
|
16862
|
-
evmSignMessage: EVMSignMessage$
|
|
17103
|
+
evmSignMessage: EVMSignMessage$2,
|
|
16863
17104
|
evmSignMessageEIP712: EVMSignMessageEIP712$1,
|
|
16864
17105
|
evmSignTransaction: EVMSignTransaction,
|
|
16865
17106
|
evmSignTypedData: EVMSignMessageEIP712,
|
|
16866
|
-
evmVerifyMessage: EVMSignMessage
|
|
17107
|
+
evmVerifyMessage: EVMSignMessage$1,
|
|
17108
|
+
starcoinGetAddress: StarcoinGetAddress,
|
|
17109
|
+
starcoinGetPublicKey: StarcoinGetPublicKey,
|
|
17110
|
+
starcoinSignMessage: StarcoinSignMessage,
|
|
17111
|
+
starcoinSignTransaction: StarcoinSignTransaction,
|
|
17112
|
+
starcoinVerifyMessage: EVMSignMessage
|
|
16867
17113
|
});
|
|
16868
17114
|
|
|
16869
17115
|
function findMethod(message) {
|
|
@@ -17105,6 +17351,9 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
17105
17351
|
Log.debug('Call API - setDevice: ', device);
|
|
17106
17352
|
(_a = method.setDevice) === null || _a === void 0 ? void 0 : _a.call(method, device);
|
|
17107
17353
|
device.on(DEVICE.PIN, onDevicePinHandler);
|
|
17354
|
+
device.on(DEVICE.BUTTON, (d, code) => {
|
|
17355
|
+
onDeviceButtonHandler(d, code);
|
|
17356
|
+
});
|
|
17108
17357
|
|
|
17109
17358
|
try {
|
|
17110
17359
|
const inner = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -17147,6 +17396,9 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
17147
17396
|
method.dispose();
|
|
17148
17397
|
}
|
|
17149
17398
|
}
|
|
17399
|
+
|
|
17400
|
+
closePopup();
|
|
17401
|
+
cleanup();
|
|
17150
17402
|
}
|
|
17151
17403
|
});
|
|
17152
17404
|
|
|
@@ -17210,6 +17462,15 @@ function initDeviceForBle(method) {
|
|
|
17210
17462
|
return device;
|
|
17211
17463
|
}
|
|
17212
17464
|
|
|
17465
|
+
const cleanup = () => {
|
|
17466
|
+
_uiPromises = [];
|
|
17467
|
+
Log.debug('Cleanup...');
|
|
17468
|
+
};
|
|
17469
|
+
|
|
17470
|
+
const closePopup = () => {
|
|
17471
|
+
postMessage(createUiMessage(UI_REQUEST$1.CLOSE_UI_WINDOW));
|
|
17472
|
+
};
|
|
17473
|
+
|
|
17213
17474
|
const onDevicePinHandler = (...[device, type, callback]) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17214
17475
|
console.log('onDevicePinHandler');
|
|
17215
17476
|
const uiPromise = createUiPromise(UI_RESPONSE.RECEIVE_PIN, device);
|
|
@@ -17221,6 +17482,15 @@ const onDevicePinHandler = (...[device, type, callback]) => __awaiter(void 0, vo
|
|
|
17221
17482
|
callback(null, uiResp.payload);
|
|
17222
17483
|
});
|
|
17223
17484
|
|
|
17485
|
+
const onDeviceButtonHandler = (...[device, request]) => {
|
|
17486
|
+
postMessage(createDeviceMessage(DEVICE.BUTTON, Object.assign(Object.assign({}, request), {
|
|
17487
|
+
device: device.toMessageObject()
|
|
17488
|
+
})));
|
|
17489
|
+
postMessage(createUiMessage(UI_REQUEST$1.REQUEST_BUTTON, {
|
|
17490
|
+
device: device.toMessageObject()
|
|
17491
|
+
}));
|
|
17492
|
+
};
|
|
17493
|
+
|
|
17224
17494
|
const postMessage = message => {
|
|
17225
17495
|
_core.emit(CORE_EVENT, message);
|
|
17226
17496
|
};
|
|
@@ -17328,6 +17598,7 @@ __webpack_unused_export__ = CORE_EVENT;
|
|
|
17328
17598
|
__webpack_unused_export__ = Core;
|
|
17329
17599
|
__webpack_unused_export__ = DEFAULT_PRIORITY;
|
|
17330
17600
|
__webpack_unused_export__ = DEVICE;
|
|
17601
|
+
__webpack_unused_export__ = DEVICE_EVENT;
|
|
17331
17602
|
__webpack_unused_export__ = DataManager;
|
|
17332
17603
|
exports.Sg = errors;
|
|
17333
17604
|
exports.Bg = IFRAME;
|
|
@@ -17337,6 +17608,7 @@ __webpack_unused_export__ = UI_REQUEST$1;
|
|
|
17337
17608
|
__webpack_unused_export__ = UI_RESPONSE;
|
|
17338
17609
|
__webpack_unused_export__ = corsValidator;
|
|
17339
17610
|
exports.Ue = create;
|
|
17611
|
+
__webpack_unused_export__ = createDeviceMessage;
|
|
17340
17612
|
exports.xG = createErrorMessage;
|
|
17341
17613
|
__webpack_unused_export__ = createIFrameMessage;
|
|
17342
17614
|
__webpack_unused_export__ = createResponseMessage;
|
|
@@ -17344,7 +17616,12 @@ __webpack_unused_export__ = createUiMessage;
|
|
|
17344
17616
|
__webpack_unused_export__ = createUiResponse;
|
|
17345
17617
|
exports.ZP = HardwareSdk;
|
|
17346
17618
|
exports.yI = enableLog;
|
|
17619
|
+
__webpack_unused_export__ = getDeviceLabel;
|
|
17620
|
+
__webpack_unused_export__ = getDeviceType;
|
|
17621
|
+
__webpack_unused_export__ = getDeviceUUID;
|
|
17347
17622
|
__webpack_unused_export__ = getEnv;
|
|
17623
|
+
__webpack_unused_export__ = getHDPath;
|
|
17624
|
+
__webpack_unused_export__ = getScriptType;
|
|
17348
17625
|
__webpack_unused_export__ = getTimeStamp;
|
|
17349
17626
|
__webpack_unused_export__ = httpRequest;
|
|
17350
17627
|
__webpack_unused_export__ = init;
|
|
@@ -17671,22 +17948,28 @@ function buildOne(messages, name, data) {
|
|
|
17671
17948
|
});
|
|
17672
17949
|
}
|
|
17673
17950
|
|
|
17674
|
-
const
|
|
17951
|
+
const buildBuffers = (messages, name, data) => {
|
|
17675
17952
|
const {
|
|
17676
17953
|
Message,
|
|
17677
17954
|
messageType
|
|
17678
17955
|
} = createMessageFromName(messages, name);
|
|
17679
17956
|
const buffer = encode$1(Message, data);
|
|
17680
|
-
const
|
|
17957
|
+
const encodeBuffers = encode(buffer, {
|
|
17681
17958
|
addTrezorHeaders: true,
|
|
17682
|
-
chunked:
|
|
17959
|
+
chunked: true,
|
|
17683
17960
|
messageType
|
|
17684
17961
|
});
|
|
17685
|
-
const
|
|
17686
|
-
|
|
17687
|
-
|
|
17688
|
-
|
|
17689
|
-
|
|
17962
|
+
const outBuffers = [];
|
|
17963
|
+
|
|
17964
|
+
for (const buf of encodeBuffers) {
|
|
17965
|
+
const chunkBuffer = new ByteBuffer__default["default"](BUFFER_SIZE + 1);
|
|
17966
|
+
chunkBuffer.writeByte(MESSAGE_TOP_CHAR);
|
|
17967
|
+
chunkBuffer.append(buf);
|
|
17968
|
+
chunkBuffer.reset();
|
|
17969
|
+
outBuffers.push(chunkBuffer);
|
|
17970
|
+
}
|
|
17971
|
+
|
|
17972
|
+
return outBuffers;
|
|
17690
17973
|
};
|
|
17691
17974
|
|
|
17692
17975
|
function receiveOne(messages, data) {
|
|
@@ -18357,7 +18640,7 @@ protobuf__namespace.configure();
|
|
|
18357
18640
|
var index = {
|
|
18358
18641
|
check,
|
|
18359
18642
|
buildOne,
|
|
18360
|
-
|
|
18643
|
+
buildBuffers,
|
|
18361
18644
|
receiveOne,
|
|
18362
18645
|
parseConfigure
|
|
18363
18646
|
};
|
|
@@ -42953,7 +43236,7 @@ const createJSBridge = messageEvent => {
|
|
|
42953
43236
|
}
|
|
42954
43237
|
};
|
|
42955
43238
|
|
|
42956
|
-
const src_init = settings => {
|
|
43239
|
+
const src_init = async settings => {
|
|
42957
43240
|
if (instance) {
|
|
42958
43241
|
throw dist/* ERRORS.TypedError */.Sg.TypedError('Init_AlreadyInitialized');
|
|
42959
43242
|
}
|
|
@@ -42961,17 +43244,18 @@ const src_init = settings => {
|
|
|
42961
43244
|
_settings = (0,dist/* parseConnectSettings */._4)({ ..._settings,
|
|
42962
43245
|
...settings
|
|
42963
43246
|
});
|
|
42964
|
-
|
|
42965
|
-
if (_settings.lazyLoad) {
|
|
42966
|
-
_settings.lazyLoad = false;
|
|
42967
|
-
return;
|
|
42968
|
-
}
|
|
42969
|
-
|
|
42970
43247
|
(0,dist/* enableLog */.yI)(!!settings.debug);
|
|
42971
43248
|
src_Log.debug('init');
|
|
42972
43249
|
window.addEventListener('message', createJSBridge);
|
|
42973
43250
|
window.addEventListener('unload', src_dispose);
|
|
42974
|
-
|
|
43251
|
+
|
|
43252
|
+
try {
|
|
43253
|
+
await init(_settings);
|
|
43254
|
+
return true;
|
|
43255
|
+
} catch (e) {
|
|
43256
|
+
console.log('init error: ', e);
|
|
43257
|
+
return false;
|
|
43258
|
+
}
|
|
42975
43259
|
};
|
|
42976
43260
|
|
|
42977
43261
|
const call = async params => {
|