@onekeyfe/hd-core 0.0.7 → 0.0.10
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/dist/api/BaseMethod.d.ts +2 -0
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/CipherKeyValue.d.ts +9 -0
- package/dist/api/CipherKeyValue.d.ts.map +1 -0
- package/dist/api/device/DeviceRebootToBootloader.d.ts +8 -0
- package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
- package/dist/api/evm/EVMSignMessageEIP712.d.ts +5 -0
- package/dist/api/evm/EVMSignMessageEIP712.d.ts.map +1 -1
- package/dist/api/evm/EVMSignTransaction.d.ts +5 -0
- package/dist/api/evm/EVMSignTransaction.d.ts.map +1 -1
- package/dist/api/evm/EVMSignTypedData.d.ts +7 -1
- package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
- package/dist/api/helpers/hexUtils.d.ts.map +1 -1
- package/dist/api/index.d.ts +7 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/nem/NEMGetAddress.d.ts +9 -0
- package/dist/api/nem/NEMGetAddress.d.ts.map +1 -0
- package/dist/api/nem/NEMSignTransaction.d.ts +20 -0
- package/dist/api/nem/NEMSignTransaction.d.ts.map +1 -0
- package/dist/api/solana/SolGetAddress.d.ts +9 -0
- package/dist/api/solana/SolGetAddress.d.ts.map +1 -0
- package/dist/api/solana/SolSignTransaction.d.ts +17 -0
- package/dist/api/solana/SolSignTransaction.d.ts.map +1 -0
- package/dist/api/stellar/StellarGetAddress.d.ts +9 -0
- package/dist/api/stellar/StellarGetAddress.d.ts.map +1 -0
- package/dist/api/stellar/StellarSignTransaction.d.ts +335 -0
- package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data/version.d.ts +1 -1
- package/dist/data/version.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +1 -1
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +299 -3
- package/dist/index.js +729 -20
- package/dist/inject.d.ts.map +1 -1
- package/dist/types/api/cipherKeyValue.d.ts +19 -0
- package/dist/types/api/cipherKeyValue.d.ts.map +1 -0
- package/dist/types/api/export.d.ts +7 -0
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +14 -0
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/nemGetAddress.d.ts +15 -0
- package/dist/types/api/nemGetAddress.d.ts.map +1 -0
- package/dist/types/api/nemSignTransaction.d.ts +93 -0
- package/dist/types/api/nemSignTransaction.d.ts.map +1 -0
- package/dist/types/api/solGetAddress.d.ts +14 -0
- package/dist/types/api/solGetAddress.d.ts.map +1 -0
- package/dist/types/api/solSignTransaction.d.ts +14 -0
- package/dist/types/api/solSignTransaction.d.ts.map +1 -0
- package/dist/types/api/stellarGetAddress.d.ts +14 -0
- package/dist/types/api/stellarGetAddress.d.ts.map +1 -0
- package/dist/types/api/stellarSignTransaction.d.ts +130 -0
- package/dist/types/api/stellarSignTransaction.d.ts.map +1 -0
- package/dist/types/device.d.ts +7 -0
- package/dist/types/device.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +49 -2
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/api/BaseMethod.ts +5 -0
- package/src/api/CipherKeyValue.ts +66 -0
- package/src/api/device/DeviceRebootToBootloader.ts +11 -0
- package/src/api/evm/EVMSignMessageEIP712.ts +8 -0
- package/src/api/evm/EVMSignTransaction.ts +15 -0
- package/src/api/evm/EVMSignTypedData.ts +55 -15
- package/src/api/helpers/hexUtils.ts +0 -1
- package/src/api/index.ts +10 -0
- package/src/api/nem/NEMGetAddress.ts +61 -0
- package/src/api/nem/NEMSignTransaction.ts +246 -0
- package/src/api/solana/SolGetAddress.ts +59 -0
- package/src/api/solana/SolSignTransaction.ts +69 -0
- package/src/api/stellar/StellarGetAddress.ts +59 -0
- package/src/api/stellar/StellarSignTransaction.ts +213 -0
- package/src/core/index.ts +50 -6
- package/src/data/version.ts +1 -1
- package/src/events/ui-request.ts +1 -1
- package/src/inject.ts +15 -0
- package/src/types/api/cipherKeyValue.ts +26 -0
- package/src/types/api/export.ts +27 -0
- package/src/types/api/index.ts +18 -0
- package/src/types/api/nemGetAddress.ts +22 -0
- package/src/types/api/nemSignTransaction.ts +117 -0
- package/src/types/api/solGetAddress.ts +21 -0
- package/src/types/api/solSignTransaction.ts +21 -0
- package/src/types/api/stellarGetAddress.ts +21 -0
- package/src/types/api/stellarSignTransaction.ts +153 -0
- package/src/types/device.ts +8 -0
- package/src/utils/deviceFeaturesUtils.ts +16 -2
package/dist/index.js
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var semver = require('semver');
|
|
5
6
|
var hdTransport = require('@onekeyfe/hd-transport');
|
|
6
7
|
var axios = require('axios');
|
|
7
|
-
var semver = require('semver');
|
|
8
8
|
var BigNumber = require('bignumber.js');
|
|
9
9
|
|
|
10
10
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
11
|
|
|
12
|
-
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
13
12
|
var semver__default = /*#__PURE__*/_interopDefaultLegacy(semver);
|
|
13
|
+
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
14
14
|
var BigNumber__default = /*#__PURE__*/_interopDefaultLegacy(BigNumber);
|
|
15
15
|
|
|
16
16
|
const inject = ({ call, cancel, dispose, eventEmitter, init, uiResponse, }) => {
|
|
@@ -34,6 +34,7 @@ const inject = ({ call, cancel, dispose, eventEmitter, init, uiResponse, }) => {
|
|
|
34
34
|
checkFirmwareRelease: connectId => call({ connectId, method: 'checkFirmwareRelease' }),
|
|
35
35
|
checkBLEFirmwareRelease: connectId => call({ connectId, method: 'checkBLEFirmwareRelease' }),
|
|
36
36
|
checkTransportRelease: () => call({ method: 'checkTransportRelease' }),
|
|
37
|
+
cipherKeyValue: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'cipherKeyValue' })),
|
|
37
38
|
deviceBackup: connectId => call({ connectId, method: 'deviceBackup' }),
|
|
38
39
|
deviceChangePin: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceChangePin' })),
|
|
39
40
|
deviceFlags: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'deviceFlags' })),
|
|
@@ -60,6 +61,12 @@ const inject = ({ call, cancel, dispose, eventEmitter, init, uiResponse, }) => {
|
|
|
60
61
|
starcoinSignMessage: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'starcoinSignMessage' })),
|
|
61
62
|
starcoinSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'starcoinSignTransaction' })),
|
|
62
63
|
starcoinVerifyMessage: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'starcoinVerifyMessage' })),
|
|
64
|
+
nemGetAddress: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'nemGetAddress' })),
|
|
65
|
+
nemSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'nemSignTransaction' })),
|
|
66
|
+
solGetAddress: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'solGetAddress' })),
|
|
67
|
+
solSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'solSignTransaction' })),
|
|
68
|
+
stellarGetAddress: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'stellarGetAddress' })),
|
|
69
|
+
stellarSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), { connectId, method: 'stellarSignTransaction' })),
|
|
63
70
|
};
|
|
64
71
|
return api;
|
|
65
72
|
};
|
|
@@ -79,6 +86,18 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
79
86
|
PERFORMANCE OF THIS SOFTWARE.
|
|
80
87
|
***************************************************************************** */
|
|
81
88
|
|
|
89
|
+
function __rest(s, e) {
|
|
90
|
+
var t = {};
|
|
91
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
92
|
+
t[p] = s[p];
|
|
93
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
94
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
95
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
96
|
+
t[p[i]] = s[p[i]];
|
|
97
|
+
}
|
|
98
|
+
return t;
|
|
99
|
+
}
|
|
100
|
+
|
|
82
101
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
83
102
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
84
103
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -808,6 +827,15 @@ function create(arg, data) {
|
|
|
808
827
|
};
|
|
809
828
|
}
|
|
810
829
|
|
|
830
|
+
const getDeviceModel = (features) => {
|
|
831
|
+
if (!features || typeof features !== 'object') {
|
|
832
|
+
return 'model_mini';
|
|
833
|
+
}
|
|
834
|
+
if (features.model === '1') {
|
|
835
|
+
return 'model_mini';
|
|
836
|
+
}
|
|
837
|
+
return 'model_touch';
|
|
838
|
+
};
|
|
811
839
|
const getDeviceType = (features) => {
|
|
812
840
|
if (!features || typeof features !== 'object' || !features.serial_no) {
|
|
813
841
|
return 'classic';
|
|
@@ -853,6 +881,8 @@ const getDeviceLabel = (features) => {
|
|
|
853
881
|
return `My OneKey ${deviceType.charAt(0).toUpperCase() + deviceType.slice(1)}`;
|
|
854
882
|
};
|
|
855
883
|
const getDeviceFirmwareVersion = (features) => {
|
|
884
|
+
if (!features)
|
|
885
|
+
return [0, 0, 0];
|
|
856
886
|
if (features.onekey_version) {
|
|
857
887
|
return features.onekey_version.split('.');
|
|
858
888
|
}
|
|
@@ -10125,7 +10155,7 @@ const UI_REQUEST = {
|
|
|
10125
10155
|
};
|
|
10126
10156
|
|
|
10127
10157
|
const VERSION = '1.0.0-alpha.1';
|
|
10128
|
-
const DEFAULT_DOMAIN = `https://
|
|
10158
|
+
const DEFAULT_DOMAIN = `https://hardware-sdk.onekey.so/`;
|
|
10129
10159
|
|
|
10130
10160
|
const DEFAULT_PRIORITY = 2;
|
|
10131
10161
|
const initialSettings = {
|
|
@@ -10562,6 +10592,9 @@ class BaseMethod {
|
|
|
10562
10592
|
this.allowDeviceMode = [UI_REQUEST.INITIALIZE];
|
|
10563
10593
|
this.requireDeviceMode = [];
|
|
10564
10594
|
}
|
|
10595
|
+
getVersionRange() {
|
|
10596
|
+
return {};
|
|
10597
|
+
}
|
|
10565
10598
|
setDevice(device) {
|
|
10566
10599
|
this.device = device;
|
|
10567
10600
|
this.connectId = device.originalDescriptor.path;
|
|
@@ -10653,7 +10686,6 @@ const formatAnyHex = value => {
|
|
|
10653
10686
|
if (typeof value === 'object') {
|
|
10654
10687
|
return modifyValues(value, value => formatAnyHex(value));
|
|
10655
10688
|
}
|
|
10656
|
-
console.log('unexpected value', value);
|
|
10657
10689
|
return value;
|
|
10658
10690
|
};
|
|
10659
10691
|
|
|
@@ -10710,6 +10742,53 @@ const validateParams = (values, fields) => {
|
|
|
10710
10742
|
});
|
|
10711
10743
|
};
|
|
10712
10744
|
|
|
10745
|
+
class CipherKeyValue extends BaseMethod {
|
|
10746
|
+
constructor() {
|
|
10747
|
+
super(...arguments);
|
|
10748
|
+
this.hasBundle = false;
|
|
10749
|
+
}
|
|
10750
|
+
init() {
|
|
10751
|
+
var _a;
|
|
10752
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
10753
|
+
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
10754
|
+
const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
|
|
10755
|
+
validateParams(payload, [{ name: 'bundle', type: 'array' }]);
|
|
10756
|
+
this.params = [];
|
|
10757
|
+
payload.bundle.forEach((batch) => {
|
|
10758
|
+
const addressN = validatePath(batch.path);
|
|
10759
|
+
validateParams(batch, [
|
|
10760
|
+
{ name: 'path', required: true },
|
|
10761
|
+
{ name: 'key', type: 'string' },
|
|
10762
|
+
{ name: 'value', type: 'hexString' },
|
|
10763
|
+
{ name: 'encrypt', type: 'boolean' },
|
|
10764
|
+
{ name: 'askOnEncrypt', type: 'boolean' },
|
|
10765
|
+
{ name: 'askOnDecrypt', type: 'boolean' },
|
|
10766
|
+
{ name: 'iv', type: 'hexString' },
|
|
10767
|
+
]);
|
|
10768
|
+
this.params.push({
|
|
10769
|
+
address_n: addressN,
|
|
10770
|
+
key: batch.key,
|
|
10771
|
+
value: formatAnyHex(batch.value),
|
|
10772
|
+
encrypt: batch.encrypt,
|
|
10773
|
+
ask_on_encrypt: batch.askOnEncrypt,
|
|
10774
|
+
ask_on_decrypt: batch.askOnDecrypt,
|
|
10775
|
+
iv: formatAnyHex(batch.iv),
|
|
10776
|
+
});
|
|
10777
|
+
});
|
|
10778
|
+
}
|
|
10779
|
+
run() {
|
|
10780
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
10781
|
+
const responses = [];
|
|
10782
|
+
for (let i = 0; i < this.params.length; i++) {
|
|
10783
|
+
const param = this.params[i];
|
|
10784
|
+
const res = yield this.device.commands.typedCall('CipherKeyValue', 'CipheredKeyValue', Object.assign({}, param));
|
|
10785
|
+
responses.push(Object.assign({ path: serializedPath(param.address_n) }, res.message));
|
|
10786
|
+
}
|
|
10787
|
+
return Promise.resolve(this.hasBundle ? responses : responses[0]);
|
|
10788
|
+
});
|
|
10789
|
+
}
|
|
10790
|
+
}
|
|
10791
|
+
|
|
10713
10792
|
var bitcoin = [
|
|
10714
10793
|
{
|
|
10715
10794
|
name: "Bitcoin",
|
|
@@ -11551,6 +11630,16 @@ class DeviceFlags extends BaseMethod {
|
|
|
11551
11630
|
|
|
11552
11631
|
class DeviceRebootToBootloader extends BaseMethod {
|
|
11553
11632
|
init() { }
|
|
11633
|
+
getVersionRange() {
|
|
11634
|
+
return {
|
|
11635
|
+
classic: {
|
|
11636
|
+
min: '2.1.11',
|
|
11637
|
+
},
|
|
11638
|
+
mini: {
|
|
11639
|
+
min: '2.1.11',
|
|
11640
|
+
},
|
|
11641
|
+
};
|
|
11642
|
+
}
|
|
11554
11643
|
run() {
|
|
11555
11644
|
return __awaiter(this, void 0, void 0, function* () {
|
|
11556
11645
|
const res = yield this.device.commands.typedCall('RebootToBootloader', 'Success');
|
|
@@ -11787,7 +11876,7 @@ class EVMSignMessage$2 extends BaseMethod {
|
|
|
11787
11876
|
}
|
|
11788
11877
|
}
|
|
11789
11878
|
|
|
11790
|
-
class EVMSignMessageEIP712
|
|
11879
|
+
class EVMSignMessageEIP712 extends BaseMethod {
|
|
11791
11880
|
init() {
|
|
11792
11881
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
11793
11882
|
validateParams(this.payload, [
|
|
@@ -11803,6 +11892,13 @@ class EVMSignMessageEIP712$1 extends BaseMethod {
|
|
|
11803
11892
|
message_hash: formatAnyHex(messageHash),
|
|
11804
11893
|
};
|
|
11805
11894
|
}
|
|
11895
|
+
getVersionRange() {
|
|
11896
|
+
return {
|
|
11897
|
+
model_mini: {
|
|
11898
|
+
min: '2.1.9',
|
|
11899
|
+
},
|
|
11900
|
+
};
|
|
11901
|
+
}
|
|
11806
11902
|
run() {
|
|
11807
11903
|
return __awaiter(this, void 0, void 0, function* () {
|
|
11808
11904
|
const res = yield this.device.commands.typedCall('EthereumSignMessageEIP712', 'EthereumMessageSignature', Object.assign({}, this.params));
|
|
@@ -11923,6 +12019,20 @@ class EVMSignTransaction extends BaseMethod {
|
|
|
11923
12019
|
validateParams(tx, schema);
|
|
11924
12020
|
this.formattedTx = formatAnyHex(tx);
|
|
11925
12021
|
}
|
|
12022
|
+
getVersionRange() {
|
|
12023
|
+
if (this.isEIP1559) {
|
|
12024
|
+
return {
|
|
12025
|
+
model_mini: {
|
|
12026
|
+
min: '2.1.11',
|
|
12027
|
+
},
|
|
12028
|
+
};
|
|
12029
|
+
}
|
|
12030
|
+
return {
|
|
12031
|
+
model_mini: {
|
|
12032
|
+
min: '1.0.0',
|
|
12033
|
+
},
|
|
12034
|
+
};
|
|
12035
|
+
}
|
|
11926
12036
|
run() {
|
|
11927
12037
|
return __awaiter(this, void 0, void 0, function* () {
|
|
11928
12038
|
const { addressN, isEIP1559, formattedTx } = this;
|
|
@@ -11934,13 +12044,13 @@ class EVMSignTransaction extends BaseMethod {
|
|
|
11934
12044
|
}
|
|
11935
12045
|
}
|
|
11936
12046
|
|
|
11937
|
-
class
|
|
12047
|
+
class EVMSignTypedData extends BaseMethod {
|
|
11938
12048
|
init() {
|
|
11939
12049
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
11940
12050
|
validateParams(this.payload, [
|
|
11941
12051
|
{ name: 'path', required: true },
|
|
11942
|
-
{ name: 'metamaskV4Compat', type: 'boolean'
|
|
11943
|
-
{ name: 'data', type: 'object'
|
|
12052
|
+
{ name: 'metamaskV4Compat', type: 'boolean' },
|
|
12053
|
+
{ name: 'data', type: 'object' },
|
|
11944
12054
|
{ name: 'domainHash', type: 'hexString' },
|
|
11945
12055
|
{ name: 'messageHash', type: 'hexString' },
|
|
11946
12056
|
]);
|
|
@@ -11956,28 +12066,57 @@ class EVMSignMessageEIP712 extends BaseMethod {
|
|
|
11956
12066
|
if (messageHash) {
|
|
11957
12067
|
this.params.messageHash = formatAnyHex(messageHash);
|
|
11958
12068
|
}
|
|
11959
|
-
else if (!data.primaryType || data.primaryType !== 'EIP712Domain') {
|
|
12069
|
+
else if (!!data && (!data.primaryType || data.primaryType !== 'EIP712Domain')) {
|
|
11960
12070
|
throw TypedError('Method_InvalidParameter', 'message_hash should only be empty when data.primaryType=EIP712Domain');
|
|
11961
12071
|
}
|
|
11962
12072
|
}
|
|
11963
12073
|
}
|
|
12074
|
+
getVersionRange() {
|
|
12075
|
+
return {
|
|
12076
|
+
model_mini: {
|
|
12077
|
+
min: '2.1.9',
|
|
12078
|
+
},
|
|
12079
|
+
};
|
|
12080
|
+
}
|
|
12081
|
+
supportSignTyped() {
|
|
12082
|
+
const deviceType = getDeviceType(this.device.features);
|
|
12083
|
+
if (deviceType === 'classic' || deviceType === 'mini') {
|
|
12084
|
+
const currentVersion = getDeviceFirmwareVersion(this.device.features).join('.');
|
|
12085
|
+
const supportSignTypedVersion = '2.2.0';
|
|
12086
|
+
if (semver__default["default"].lt(currentVersion, supportSignTypedVersion)) {
|
|
12087
|
+
return false;
|
|
12088
|
+
}
|
|
12089
|
+
}
|
|
12090
|
+
return true;
|
|
12091
|
+
}
|
|
11964
12092
|
run() {
|
|
11965
12093
|
return __awaiter(this, void 0, void 0, function* () {
|
|
11966
12094
|
if (!this.device.features) {
|
|
11967
12095
|
throw TypedError('Device_InitializeFailed', 'Device initialization failed. Please try again.');
|
|
11968
12096
|
}
|
|
11969
12097
|
const { addressN } = this.params;
|
|
11970
|
-
|
|
12098
|
+
const deviceType = getDeviceType(this.device.features);
|
|
12099
|
+
if (deviceType === 'classic' || deviceType === 'mini') {
|
|
11971
12100
|
validateParams(this.params, [
|
|
11972
12101
|
{ name: 'domainHash', type: 'hexString', required: true },
|
|
11973
|
-
{ name: 'messageHash', type: 'hexString' },
|
|
12102
|
+
{ name: 'messageHash', type: 'hexString', required: true },
|
|
11974
12103
|
]);
|
|
11975
12104
|
const { domainHash, messageHash } = this.params;
|
|
11976
|
-
|
|
11977
|
-
|
|
11978
|
-
|
|
11979
|
-
|
|
11980
|
-
|
|
12105
|
+
let response;
|
|
12106
|
+
if (this.supportSignTyped()) {
|
|
12107
|
+
response = yield this.device.commands.typedCall('EthereumSignTypedHash', 'EthereumTypedDataSignature', {
|
|
12108
|
+
address_n: addressN,
|
|
12109
|
+
domain_separator_hash: domainHash !== null && domainHash !== void 0 ? domainHash : '',
|
|
12110
|
+
message_hash: messageHash,
|
|
12111
|
+
});
|
|
12112
|
+
}
|
|
12113
|
+
else {
|
|
12114
|
+
response = yield this.device.commands.typedCall('EthereumSignMessageEIP712', 'EthereumMessageSignature', {
|
|
12115
|
+
address_n: addressN,
|
|
12116
|
+
domain_hash: domainHash !== null && domainHash !== void 0 ? domainHash : '',
|
|
12117
|
+
message_hash: messageHash !== null && messageHash !== void 0 ? messageHash : '',
|
|
12118
|
+
});
|
|
12119
|
+
}
|
|
11981
12120
|
return Promise.resolve(response.message);
|
|
11982
12121
|
}
|
|
11983
12122
|
return Promise.resolve(TypedError('Runtime', 'Not implemented'));
|
|
@@ -12153,10 +12292,549 @@ class EVMSignMessage extends BaseMethod {
|
|
|
12153
12292
|
}
|
|
12154
12293
|
}
|
|
12155
12294
|
|
|
12295
|
+
const MAINNET = 0x68;
|
|
12296
|
+
class NEMGetAddress extends BaseMethod {
|
|
12297
|
+
constructor() {
|
|
12298
|
+
super(...arguments);
|
|
12299
|
+
this.hasBundle = false;
|
|
12300
|
+
}
|
|
12301
|
+
init() {
|
|
12302
|
+
var _a;
|
|
12303
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
12304
|
+
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
12305
|
+
const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
|
|
12306
|
+
validateParams(payload, [{ name: 'bundle', type: 'array' }]);
|
|
12307
|
+
this.params = [];
|
|
12308
|
+
payload.bundle.forEach((batch) => {
|
|
12309
|
+
var _a;
|
|
12310
|
+
const addressN = validatePath(batch.path, 3);
|
|
12311
|
+
validateParams(batch, [
|
|
12312
|
+
{ name: 'path', required: true },
|
|
12313
|
+
{ name: 'network', type: 'number' },
|
|
12314
|
+
{ name: 'showOnOneKey', type: 'boolean' },
|
|
12315
|
+
]);
|
|
12316
|
+
const showOnOneKey = (_a = batch.showOnOneKey) !== null && _a !== void 0 ? _a : true;
|
|
12317
|
+
this.params.push({
|
|
12318
|
+
address_n: addressN,
|
|
12319
|
+
network: batch.network || MAINNET,
|
|
12320
|
+
show_display: showOnOneKey,
|
|
12321
|
+
});
|
|
12322
|
+
});
|
|
12323
|
+
}
|
|
12324
|
+
run() {
|
|
12325
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
12326
|
+
const responses = [];
|
|
12327
|
+
for (let i = 0; i < this.params.length; i++) {
|
|
12328
|
+
const param = this.params[i];
|
|
12329
|
+
const res = yield this.device.commands.typedCall('NEMGetAddress', 'NEMAddress', Object.assign({}, param));
|
|
12330
|
+
responses.push(Object.assign({ path: serializedPath(param.address_n) }, res.message));
|
|
12331
|
+
}
|
|
12332
|
+
return Promise.resolve(this.hasBundle ? responses : responses[0]);
|
|
12333
|
+
});
|
|
12334
|
+
}
|
|
12335
|
+
}
|
|
12336
|
+
|
|
12337
|
+
const NEM_TRANSFER = 0x0101;
|
|
12338
|
+
const NEM_COSIGNING = 0x0102;
|
|
12339
|
+
const NEM_IMPORTANCE_TRANSFER = 0x0801;
|
|
12340
|
+
const NEM_AGGREGATE_MODIFICATION = 0x1001;
|
|
12341
|
+
const NEM_MULTISIG_SIGNATURE = 0x1002;
|
|
12342
|
+
const NEM_MULTISIG = 0x1004;
|
|
12343
|
+
const NEM_PROVISION_NAMESPACE = 0x2001;
|
|
12344
|
+
const NEM_MOSAIC_CREATION = 0x4001;
|
|
12345
|
+
const NEM_SUPPLY_CHANGE = 0x4002;
|
|
12346
|
+
class NEMSignTransaction extends BaseMethod {
|
|
12347
|
+
constructor() {
|
|
12348
|
+
super(...arguments);
|
|
12349
|
+
this.NEM_MOSAIC_LEVY_TYPES = {
|
|
12350
|
+
1: 'MosaicLevy_Absolute',
|
|
12351
|
+
2: 'MosaicLevy_Percentile',
|
|
12352
|
+
};
|
|
12353
|
+
this.NEM_SUPPLY_CHANGE_TYPES = {
|
|
12354
|
+
1: 'SupplyChange_Increase',
|
|
12355
|
+
2: 'SupplyChange_Decrease',
|
|
12356
|
+
};
|
|
12357
|
+
this.NEM_AGGREGATE_MODIFICATION_TYPES = {
|
|
12358
|
+
1: 'CosignatoryModification_Add',
|
|
12359
|
+
2: 'CosignatoryModification_Delete',
|
|
12360
|
+
};
|
|
12361
|
+
this.NEM_IMPORTANCE_TRANSFER_MODES = {
|
|
12362
|
+
1: 'ImportanceTransfer_Activate',
|
|
12363
|
+
2: 'ImportanceTransfer_Deactivate',
|
|
12364
|
+
};
|
|
12365
|
+
this.getCommon = (tx, address_n) => {
|
|
12366
|
+
var _a;
|
|
12367
|
+
return ({
|
|
12368
|
+
address_n,
|
|
12369
|
+
network: (tx.version >> 24) & 0xff,
|
|
12370
|
+
timestamp: tx.timeStamp,
|
|
12371
|
+
fee: tx.fee,
|
|
12372
|
+
deadline: (_a = tx.deadline) !== null && _a !== void 0 ? _a : 0,
|
|
12373
|
+
signer: address_n ? undefined : tx.signer,
|
|
12374
|
+
});
|
|
12375
|
+
};
|
|
12376
|
+
this.transferMessage = (tx) => {
|
|
12377
|
+
const mosaics = tx.mosaics
|
|
12378
|
+
? tx.mosaics.map(mosaic => ({
|
|
12379
|
+
namespace: mosaic.mosaicId.namespaceId,
|
|
12380
|
+
mosaic: mosaic.mosaicId.name,
|
|
12381
|
+
quantity: mosaic.quantity,
|
|
12382
|
+
}))
|
|
12383
|
+
: undefined;
|
|
12384
|
+
return {
|
|
12385
|
+
recipient: tx.recipient,
|
|
12386
|
+
amount: tx.amount,
|
|
12387
|
+
payload: tx.message ? tx.message.payload : undefined,
|
|
12388
|
+
public_key: tx.message && tx.message.type === 0x02 ? tx.message.publicKey : undefined,
|
|
12389
|
+
mosaics,
|
|
12390
|
+
};
|
|
12391
|
+
};
|
|
12392
|
+
this.importanceTransferMessage = (tx) => ({
|
|
12393
|
+
mode: this.NEM_IMPORTANCE_TRANSFER_MODES[tx.importanceTransfer.mode],
|
|
12394
|
+
public_key: tx.importanceTransfer.publicKey,
|
|
12395
|
+
});
|
|
12396
|
+
this.aggregateModificationMessage = (tx) => {
|
|
12397
|
+
const modifications = tx.modifications
|
|
12398
|
+
? tx.modifications.map(modification => ({
|
|
12399
|
+
type: this.NEM_AGGREGATE_MODIFICATION_TYPES[modification.modificationType],
|
|
12400
|
+
public_key: modification.cosignatoryAccount,
|
|
12401
|
+
}))
|
|
12402
|
+
: undefined;
|
|
12403
|
+
return {
|
|
12404
|
+
modifications,
|
|
12405
|
+
relative_change: tx.minCosignatories.relativeChange,
|
|
12406
|
+
};
|
|
12407
|
+
};
|
|
12408
|
+
this.provisionNamespaceMessage = (tx) => {
|
|
12409
|
+
var _a, _b, _c;
|
|
12410
|
+
return ({
|
|
12411
|
+
namespace: (_a = tx.newPart) !== null && _a !== void 0 ? _a : '',
|
|
12412
|
+
parent: tx.parent || undefined,
|
|
12413
|
+
sink: (_b = tx.rentalFeeSink) !== null && _b !== void 0 ? _b : '',
|
|
12414
|
+
fee: (_c = tx.rentalFee) !== null && _c !== void 0 ? _c : 0,
|
|
12415
|
+
});
|
|
12416
|
+
};
|
|
12417
|
+
this.mosaicCreationMessage = (tx) => {
|
|
12418
|
+
var _a, _b;
|
|
12419
|
+
const { levy } = tx.mosaicDefinition;
|
|
12420
|
+
const definition = {
|
|
12421
|
+
namespace: tx.mosaicDefinition.id.namespaceId,
|
|
12422
|
+
mosaic: tx.mosaicDefinition.id.name,
|
|
12423
|
+
levy: levy && levy.type ? this.NEM_MOSAIC_LEVY_TYPES[levy.type] : undefined,
|
|
12424
|
+
fee: levy && levy.fee,
|
|
12425
|
+
levy_address: levy && levy.recipient,
|
|
12426
|
+
levy_namespace: levy && levy.mosaicId && levy.mosaicId.namespaceId,
|
|
12427
|
+
levy_mosaic: levy && levy.mosaicId && levy.mosaicId.name,
|
|
12428
|
+
description: tx.mosaicDefinition.description,
|
|
12429
|
+
};
|
|
12430
|
+
const { properties } = tx.mosaicDefinition;
|
|
12431
|
+
if (Array.isArray(properties)) {
|
|
12432
|
+
properties.forEach(property => {
|
|
12433
|
+
const { name, value } = property;
|
|
12434
|
+
switch (name) {
|
|
12435
|
+
case 'divisibility':
|
|
12436
|
+
definition.divisibility = parseInt(value);
|
|
12437
|
+
break;
|
|
12438
|
+
case 'initialSupply':
|
|
12439
|
+
definition.supply = parseInt(value);
|
|
12440
|
+
break;
|
|
12441
|
+
case 'supplyMutable':
|
|
12442
|
+
definition.mutable_supply = value === 'true';
|
|
12443
|
+
break;
|
|
12444
|
+
case 'transferable':
|
|
12445
|
+
definition.transferable = value === 'true';
|
|
12446
|
+
break;
|
|
12447
|
+
}
|
|
12448
|
+
});
|
|
12449
|
+
}
|
|
12450
|
+
return {
|
|
12451
|
+
definition,
|
|
12452
|
+
sink: (_a = tx.creationFeeSink) !== null && _a !== void 0 ? _a : '',
|
|
12453
|
+
fee: (_b = tx.creationFee) !== null && _b !== void 0 ? _b : 0,
|
|
12454
|
+
};
|
|
12455
|
+
};
|
|
12456
|
+
this.supplyChangeMessage = (tx) => {
|
|
12457
|
+
var _a;
|
|
12458
|
+
return ({
|
|
12459
|
+
namespace: tx.mosaicId.namespaceId,
|
|
12460
|
+
mosaic: tx.mosaicId.name,
|
|
12461
|
+
type: this.NEM_SUPPLY_CHANGE_TYPES[tx.supplyType],
|
|
12462
|
+
delta: (_a = tx.delta) !== null && _a !== void 0 ? _a : 0,
|
|
12463
|
+
});
|
|
12464
|
+
};
|
|
12465
|
+
this.parseTx = (tx, address_n) => {
|
|
12466
|
+
let transaction = tx;
|
|
12467
|
+
const message = {
|
|
12468
|
+
transaction: this.getCommon(tx, address_n),
|
|
12469
|
+
transfer: undefined,
|
|
12470
|
+
importance_transfer: undefined,
|
|
12471
|
+
aggregate_modification: undefined,
|
|
12472
|
+
provision_namespace: undefined,
|
|
12473
|
+
mosaic_creation: undefined,
|
|
12474
|
+
supply_change: undefined,
|
|
12475
|
+
};
|
|
12476
|
+
if (tx.type === NEM_COSIGNING ||
|
|
12477
|
+
tx.type === NEM_MULTISIG ||
|
|
12478
|
+
tx.type === NEM_MULTISIG_SIGNATURE) {
|
|
12479
|
+
message.cosigning = tx.type === NEM_COSIGNING || tx.type === NEM_MULTISIG_SIGNATURE;
|
|
12480
|
+
transaction = tx.otherTrans;
|
|
12481
|
+
message.multisig = this.getCommon(transaction);
|
|
12482
|
+
}
|
|
12483
|
+
switch (transaction.type) {
|
|
12484
|
+
case NEM_TRANSFER:
|
|
12485
|
+
message.transfer = this.transferMessage(transaction);
|
|
12486
|
+
break;
|
|
12487
|
+
case NEM_IMPORTANCE_TRANSFER:
|
|
12488
|
+
message.importance_transfer = this.importanceTransferMessage(transaction);
|
|
12489
|
+
break;
|
|
12490
|
+
case NEM_AGGREGATE_MODIFICATION:
|
|
12491
|
+
message.aggregate_modification = this.aggregateModificationMessage(transaction);
|
|
12492
|
+
break;
|
|
12493
|
+
case NEM_PROVISION_NAMESPACE:
|
|
12494
|
+
message.provision_namespace = this.provisionNamespaceMessage(transaction);
|
|
12495
|
+
break;
|
|
12496
|
+
case NEM_MOSAIC_CREATION:
|
|
12497
|
+
message.mosaic_creation = this.mosaicCreationMessage(transaction);
|
|
12498
|
+
break;
|
|
12499
|
+
case NEM_SUPPLY_CHANGE:
|
|
12500
|
+
message.supply_change = this.supplyChangeMessage(transaction);
|
|
12501
|
+
break;
|
|
12502
|
+
default:
|
|
12503
|
+
throw TypedError('Method_InvalidParameter', 'Unknown transaction type');
|
|
12504
|
+
}
|
|
12505
|
+
return message;
|
|
12506
|
+
};
|
|
12507
|
+
}
|
|
12508
|
+
init() {
|
|
12509
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
12510
|
+
validateParams(this.payload, [
|
|
12511
|
+
{ name: 'path', required: true },
|
|
12512
|
+
{ name: 'transaction', type: 'object', required: true },
|
|
12513
|
+
]);
|
|
12514
|
+
const { path, transaction } = this.payload;
|
|
12515
|
+
const addressN = validatePath(path, 3);
|
|
12516
|
+
this.params = this.parseTx(transaction, addressN);
|
|
12517
|
+
}
|
|
12518
|
+
run() {
|
|
12519
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
12520
|
+
const res = yield this.device.commands.typedCall('NEMSignTx', 'NEMSignedTx', Object.assign({}, this.params));
|
|
12521
|
+
return Promise.resolve(res);
|
|
12522
|
+
});
|
|
12523
|
+
}
|
|
12524
|
+
}
|
|
12525
|
+
|
|
12526
|
+
class SolGetAddress extends BaseMethod {
|
|
12527
|
+
constructor() {
|
|
12528
|
+
super(...arguments);
|
|
12529
|
+
this.hasBundle = false;
|
|
12530
|
+
}
|
|
12531
|
+
init() {
|
|
12532
|
+
var _a;
|
|
12533
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
12534
|
+
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
12535
|
+
const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
|
|
12536
|
+
validateParams(payload, [{ name: 'bundle', type: 'array' }]);
|
|
12537
|
+
this.params = [];
|
|
12538
|
+
payload.bundle.forEach((batch) => {
|
|
12539
|
+
var _a;
|
|
12540
|
+
const addressN = validatePath(batch.path, 3);
|
|
12541
|
+
validateParams(batch, [
|
|
12542
|
+
{ name: 'path', required: true },
|
|
12543
|
+
{ name: 'showOnOneKey', type: 'boolean' },
|
|
12544
|
+
]);
|
|
12545
|
+
const showOnOneKey = (_a = batch.showOnOneKey) !== null && _a !== void 0 ? _a : true;
|
|
12546
|
+
this.params.push({
|
|
12547
|
+
address_n: addressN,
|
|
12548
|
+
show_display: showOnOneKey,
|
|
12549
|
+
});
|
|
12550
|
+
});
|
|
12551
|
+
}
|
|
12552
|
+
run() {
|
|
12553
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
12554
|
+
const responses = [];
|
|
12555
|
+
for (let i = 0; i < this.params.length; i++) {
|
|
12556
|
+
const param = this.params[i];
|
|
12557
|
+
const res = yield this.device.commands.typedCall('SolanaGetAddress', 'SolanaAddress', Object.assign({}, param));
|
|
12558
|
+
const { address } = res.message;
|
|
12559
|
+
responses.push({
|
|
12560
|
+
path: serializedPath(param.address_n),
|
|
12561
|
+
address,
|
|
12562
|
+
});
|
|
12563
|
+
}
|
|
12564
|
+
return Promise.resolve(this.hasBundle ? responses : responses[0]);
|
|
12565
|
+
});
|
|
12566
|
+
}
|
|
12567
|
+
}
|
|
12568
|
+
|
|
12569
|
+
class SolSignTransaction extends BaseMethod {
|
|
12570
|
+
constructor() {
|
|
12571
|
+
super(...arguments);
|
|
12572
|
+
this.hasBundle = false;
|
|
12573
|
+
}
|
|
12574
|
+
init() {
|
|
12575
|
+
var _a;
|
|
12576
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
12577
|
+
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
12578
|
+
const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
|
|
12579
|
+
validateParams(payload, [{ name: 'bundle', type: 'array' }]);
|
|
12580
|
+
this.params = [];
|
|
12581
|
+
payload.bundle.forEach((batch) => {
|
|
12582
|
+
const addressN = validatePath(batch.path, 3);
|
|
12583
|
+
validateParams(batch, [
|
|
12584
|
+
{ name: 'path', required: true },
|
|
12585
|
+
{ name: 'rawTx', type: 'hexString', required: true },
|
|
12586
|
+
]);
|
|
12587
|
+
this.params.push({
|
|
12588
|
+
address_n: addressN,
|
|
12589
|
+
raw_tx: formatAnyHex(batch.rawTx),
|
|
12590
|
+
});
|
|
12591
|
+
});
|
|
12592
|
+
}
|
|
12593
|
+
getVersionRange() {
|
|
12594
|
+
return {
|
|
12595
|
+
classic: {
|
|
12596
|
+
min: '2.1.9',
|
|
12597
|
+
},
|
|
12598
|
+
mini: {
|
|
12599
|
+
min: '2.1.9',
|
|
12600
|
+
},
|
|
12601
|
+
};
|
|
12602
|
+
}
|
|
12603
|
+
run() {
|
|
12604
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
12605
|
+
const responses = [];
|
|
12606
|
+
for (let i = 0; i < this.params.length; i++) {
|
|
12607
|
+
const param = this.params[i];
|
|
12608
|
+
const res = yield this.device.commands.typedCall('SolanaSignTx', 'SolanaSignedTx', Object.assign({}, param));
|
|
12609
|
+
const { signature } = res.message;
|
|
12610
|
+
responses.push({
|
|
12611
|
+
path: serializedPath(param.address_n),
|
|
12612
|
+
signature,
|
|
12613
|
+
});
|
|
12614
|
+
}
|
|
12615
|
+
return Promise.resolve(this.hasBundle ? responses : responses[0]);
|
|
12616
|
+
});
|
|
12617
|
+
}
|
|
12618
|
+
}
|
|
12619
|
+
|
|
12620
|
+
class StellarGetAddress extends BaseMethod {
|
|
12621
|
+
constructor() {
|
|
12622
|
+
super(...arguments);
|
|
12623
|
+
this.hasBundle = false;
|
|
12624
|
+
}
|
|
12625
|
+
init() {
|
|
12626
|
+
var _a;
|
|
12627
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
12628
|
+
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
12629
|
+
const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
|
|
12630
|
+
validateParams(payload, [{ name: 'bundle', type: 'array' }]);
|
|
12631
|
+
this.params = [];
|
|
12632
|
+
payload.bundle.forEach((batch) => {
|
|
12633
|
+
var _a;
|
|
12634
|
+
const addressN = validatePath(batch.path, 3);
|
|
12635
|
+
validateParams(batch, [
|
|
12636
|
+
{ name: 'path', required: true },
|
|
12637
|
+
{ name: 'showOnOneKey', type: 'boolean' },
|
|
12638
|
+
]);
|
|
12639
|
+
const showOnOneKey = (_a = batch.showOnOneKey) !== null && _a !== void 0 ? _a : true;
|
|
12640
|
+
this.params.push({
|
|
12641
|
+
address_n: addressN,
|
|
12642
|
+
show_display: showOnOneKey,
|
|
12643
|
+
});
|
|
12644
|
+
});
|
|
12645
|
+
}
|
|
12646
|
+
run() {
|
|
12647
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
12648
|
+
const responses = [];
|
|
12649
|
+
for (let i = 0; i < this.params.length; i++) {
|
|
12650
|
+
const param = this.params[i];
|
|
12651
|
+
const res = yield this.device.commands.typedCall('StellarGetAddress', 'StellarAddress', Object.assign({}, param));
|
|
12652
|
+
const { address } = res.message;
|
|
12653
|
+
responses.push({
|
|
12654
|
+
path: serializedPath(param.address_n),
|
|
12655
|
+
address,
|
|
12656
|
+
});
|
|
12657
|
+
}
|
|
12658
|
+
return Promise.resolve(this.hasBundle ? responses : responses[0]);
|
|
12659
|
+
});
|
|
12660
|
+
}
|
|
12661
|
+
}
|
|
12662
|
+
|
|
12663
|
+
class StellarSignTransaction extends BaseMethod {
|
|
12664
|
+
constructor() {
|
|
12665
|
+
super(...arguments);
|
|
12666
|
+
this.operations = [];
|
|
12667
|
+
this.parseOperation = (op) => {
|
|
12668
|
+
switch (op.type) {
|
|
12669
|
+
case 'createAccount':
|
|
12670
|
+
validateParams(op, [
|
|
12671
|
+
{ name: 'destination', type: 'string', required: true },
|
|
12672
|
+
{ name: 'startingBalance', type: 'bigNumber', required: true },
|
|
12673
|
+
]);
|
|
12674
|
+
return {
|
|
12675
|
+
type: 'StellarCreateAccountOp',
|
|
12676
|
+
source_account: op.source,
|
|
12677
|
+
new_account: op.destination,
|
|
12678
|
+
starting_balance: op.startingBalance,
|
|
12679
|
+
};
|
|
12680
|
+
case 'payment':
|
|
12681
|
+
validateParams(op, [
|
|
12682
|
+
{ name: 'destination', type: 'string', required: true },
|
|
12683
|
+
{ name: 'amount', type: 'bigNumber', required: true },
|
|
12684
|
+
{ name: 'asset', required: true },
|
|
12685
|
+
]);
|
|
12686
|
+
return {
|
|
12687
|
+
type: 'StellarPaymentOp',
|
|
12688
|
+
source_account: op.source,
|
|
12689
|
+
destination_account: op.destination,
|
|
12690
|
+
asset: op.asset,
|
|
12691
|
+
amount: op.amount,
|
|
12692
|
+
};
|
|
12693
|
+
case 'pathPayment':
|
|
12694
|
+
validateParams(op, [{ name: 'destAmount', type: 'bigNumber', required: true }]);
|
|
12695
|
+
return {
|
|
12696
|
+
type: 'StellarPathPaymentOp',
|
|
12697
|
+
source_account: op.source,
|
|
12698
|
+
send_asset: op.sendAsset,
|
|
12699
|
+
send_max: op.sendMax,
|
|
12700
|
+
destination_account: op.destination,
|
|
12701
|
+
destination_asset: op.destAsset,
|
|
12702
|
+
destination_amount: op.destAmount,
|
|
12703
|
+
paths: op.path,
|
|
12704
|
+
};
|
|
12705
|
+
case 'createPassiveOffer':
|
|
12706
|
+
validateParams(op, [{ name: 'amount', type: 'bigNumber', required: true }]);
|
|
12707
|
+
return {
|
|
12708
|
+
type: 'StellarCreatePassiveOfferOp',
|
|
12709
|
+
source_account: op.source,
|
|
12710
|
+
buying_asset: op.buying,
|
|
12711
|
+
selling_asset: op.selling,
|
|
12712
|
+
amount: op.amount,
|
|
12713
|
+
price_n: op.price.n,
|
|
12714
|
+
price_d: op.price.d,
|
|
12715
|
+
};
|
|
12716
|
+
case 'manageOffer':
|
|
12717
|
+
validateParams(op, [{ name: 'amount', type: 'bigNumber', required: true }]);
|
|
12718
|
+
return {
|
|
12719
|
+
type: 'StellarManageOfferOp',
|
|
12720
|
+
source_account: op.source,
|
|
12721
|
+
buying_asset: op.buying,
|
|
12722
|
+
selling_asset: op.selling,
|
|
12723
|
+
amount: op.amount,
|
|
12724
|
+
offer_id: op.offerId,
|
|
12725
|
+
price_n: op.price.n,
|
|
12726
|
+
price_d: op.price.d,
|
|
12727
|
+
};
|
|
12728
|
+
case 'setOptions': {
|
|
12729
|
+
const signer = op.signer
|
|
12730
|
+
? {
|
|
12731
|
+
signer_type: op.signer.type,
|
|
12732
|
+
signer_key: op.signer.key,
|
|
12733
|
+
signer_weight: op.signer.weight,
|
|
12734
|
+
}
|
|
12735
|
+
: undefined;
|
|
12736
|
+
return Object.assign({ type: 'StellarSetOptionsOp', source_account: op.source, clear_flags: op.clearFlags, set_flags: op.setFlags, master_weight: op.masterWeight, low_threshold: op.lowThreshold, medium_threshold: op.medThreshold, high_threshold: op.highThreshold, home_domain: op.homeDomain, inflation_destination_account: op.inflationDest }, signer);
|
|
12737
|
+
}
|
|
12738
|
+
case 'changeTrust':
|
|
12739
|
+
validateParams(op, [{ name: 'limit', type: 'bigNumber' }]);
|
|
12740
|
+
return {
|
|
12741
|
+
type: 'StellarChangeTrustOp',
|
|
12742
|
+
source_account: op.source,
|
|
12743
|
+
asset: op.line,
|
|
12744
|
+
limit: op.limit,
|
|
12745
|
+
};
|
|
12746
|
+
case 'allowTrust':
|
|
12747
|
+
return {
|
|
12748
|
+
type: 'StellarAllowTrustOp',
|
|
12749
|
+
source_account: op.source,
|
|
12750
|
+
trusted_account: op.trustor,
|
|
12751
|
+
asset_type: op.assetType,
|
|
12752
|
+
asset_code: op.assetCode,
|
|
12753
|
+
is_authorized: op.authorize ? 1 : 0,
|
|
12754
|
+
};
|
|
12755
|
+
case 'accountMerge':
|
|
12756
|
+
return {
|
|
12757
|
+
type: 'StellarAccountMergeOp',
|
|
12758
|
+
source_account: op.source,
|
|
12759
|
+
destination_account: op.destination,
|
|
12760
|
+
};
|
|
12761
|
+
case 'manageData':
|
|
12762
|
+
return {
|
|
12763
|
+
type: 'StellarManageDataOp',
|
|
12764
|
+
source_account: op.source,
|
|
12765
|
+
key: op.name,
|
|
12766
|
+
value: op.value,
|
|
12767
|
+
};
|
|
12768
|
+
case 'bumpSequence':
|
|
12769
|
+
return {
|
|
12770
|
+
type: 'StellarBumpSequenceOp',
|
|
12771
|
+
source_account: op.source,
|
|
12772
|
+
bump_to: op.bumpTo,
|
|
12773
|
+
};
|
|
12774
|
+
default:
|
|
12775
|
+
return {};
|
|
12776
|
+
}
|
|
12777
|
+
};
|
|
12778
|
+
this.processTxRequest = (operations, index) => __awaiter(this, void 0, void 0, function* () {
|
|
12779
|
+
const isLastOp = index + 1 >= operations.length;
|
|
12780
|
+
const _a = operations[index], { type } = _a, op = __rest(_a, ["type"]);
|
|
12781
|
+
if (isLastOp) {
|
|
12782
|
+
const response = yield this.device.commands.typedCall(type, 'StellarSignedTx', op);
|
|
12783
|
+
return response.message;
|
|
12784
|
+
}
|
|
12785
|
+
yield this.device.commands.typedCall(type, 'StellarTxOpRequest', op);
|
|
12786
|
+
return this.processTxRequest(operations, index + 1);
|
|
12787
|
+
});
|
|
12788
|
+
}
|
|
12789
|
+
init() {
|
|
12790
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
12791
|
+
validateParams(this.payload, [
|
|
12792
|
+
{ name: 'path', required: true },
|
|
12793
|
+
{ name: 'networkPassphrase', type: 'string', required: true },
|
|
12794
|
+
{ name: 'transaction', type: 'object', required: true },
|
|
12795
|
+
]);
|
|
12796
|
+
const addressN = validatePath(this.payload.path, 3);
|
|
12797
|
+
const { transaction, networkPassphrase } = this.payload;
|
|
12798
|
+
this.params = {
|
|
12799
|
+
address_n: addressN,
|
|
12800
|
+
network_passphrase: networkPassphrase,
|
|
12801
|
+
source_account: transaction.source,
|
|
12802
|
+
fee: transaction.fee,
|
|
12803
|
+
sequence_number: transaction.sequence,
|
|
12804
|
+
num_operations: transaction.operations.length,
|
|
12805
|
+
};
|
|
12806
|
+
if (transaction.timebounds) {
|
|
12807
|
+
this.params.timebounds_start = transaction.timebounds.minTime;
|
|
12808
|
+
this.params.timebounds_end = transaction.timebounds.maxTime;
|
|
12809
|
+
}
|
|
12810
|
+
if (transaction.memo) {
|
|
12811
|
+
this.params.memo_type = transaction.memo.type;
|
|
12812
|
+
this.params.memo_text = transaction.memo.text;
|
|
12813
|
+
this.params.memo_id = transaction.memo.id;
|
|
12814
|
+
this.params.memo_hash = transaction.memo.hash;
|
|
12815
|
+
}
|
|
12816
|
+
transaction.operations.forEach(op => {
|
|
12817
|
+
const transformed = this.parseOperation(op);
|
|
12818
|
+
if (transformed) {
|
|
12819
|
+
this.operations.push(transformed);
|
|
12820
|
+
}
|
|
12821
|
+
});
|
|
12822
|
+
console.log('StellarSignTransactionParams', this.params);
|
|
12823
|
+
console.log('StellarSignTransactionOperations', this.operations);
|
|
12824
|
+
}
|
|
12825
|
+
run() {
|
|
12826
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
12827
|
+
yield this.device.commands.typedCall('StellarSignTx', 'StellarTxOpRequest', Object.assign({}, this.params));
|
|
12828
|
+
return this.processTxRequest(this.operations, 0);
|
|
12829
|
+
});
|
|
12830
|
+
}
|
|
12831
|
+
}
|
|
12832
|
+
|
|
12156
12833
|
var ApiMethods = /*#__PURE__*/Object.freeze({
|
|
12157
12834
|
__proto__: null,
|
|
12158
12835
|
searchDevices: SearchDevices,
|
|
12159
12836
|
getFeatures: GetFeatures,
|
|
12837
|
+
cipherKeyValue: CipherKeyValue,
|
|
12160
12838
|
btcGetAddress: BTCGetAddress,
|
|
12161
12839
|
btcGetPublicKey: BTCGetPublicKey,
|
|
12162
12840
|
btcSignMessage: BTCSignMessage,
|
|
@@ -12177,15 +12855,21 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
|
|
|
12177
12855
|
evmGetAddress: EvmGetAddress,
|
|
12178
12856
|
evmGetPublicKey: EVMGetPublicKey,
|
|
12179
12857
|
evmSignMessage: EVMSignMessage$2,
|
|
12180
|
-
evmSignMessageEIP712: EVMSignMessageEIP712
|
|
12858
|
+
evmSignMessageEIP712: EVMSignMessageEIP712,
|
|
12181
12859
|
evmSignTransaction: EVMSignTransaction,
|
|
12182
|
-
evmSignTypedData:
|
|
12860
|
+
evmSignTypedData: EVMSignTypedData,
|
|
12183
12861
|
evmVerifyMessage: EVMSignMessage$1,
|
|
12184
12862
|
starcoinGetAddress: StarcoinGetAddress,
|
|
12185
12863
|
starcoinGetPublicKey: StarcoinGetPublicKey,
|
|
12186
12864
|
starcoinSignMessage: StarcoinSignMessage,
|
|
12187
12865
|
starcoinSignTransaction: StarcoinSignTransaction,
|
|
12188
|
-
starcoinVerifyMessage: EVMSignMessage
|
|
12866
|
+
starcoinVerifyMessage: EVMSignMessage,
|
|
12867
|
+
nemGetAddress: NEMGetAddress,
|
|
12868
|
+
nemSignTransaction: NEMSignTransaction,
|
|
12869
|
+
solGetAddress: SolGetAddress,
|
|
12870
|
+
solSignTransaction: SolSignTransaction,
|
|
12871
|
+
stellarGetAddress: StellarGetAddress,
|
|
12872
|
+
stellarSignTransaction: StellarSignTransaction
|
|
12189
12873
|
});
|
|
12190
12874
|
|
|
12191
12875
|
function findMethod(message) {
|
|
@@ -12403,6 +13087,22 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
12403
13087
|
});
|
|
12404
13088
|
try {
|
|
12405
13089
|
const inner = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
13090
|
+
const deviceType = getDeviceType(device.features);
|
|
13091
|
+
const deviceModel = getDeviceModel(device.features);
|
|
13092
|
+
const versionRangeType = method.getVersionRange()[deviceType];
|
|
13093
|
+
const versionRangeModel = method.getVersionRange()[deviceModel];
|
|
13094
|
+
const versionRange = versionRangeType !== null && versionRangeType !== void 0 ? versionRangeType : versionRangeModel;
|
|
13095
|
+
if (versionRange && device.features) {
|
|
13096
|
+
const currentVersion = getDeviceFirmwareVersion(device.features).join('.');
|
|
13097
|
+
if (semver__default["default"].valid(versionRange.min) && semver__default["default"].lt(currentVersion, versionRange.min)) {
|
|
13098
|
+
return Promise.reject(TypedError('Device_FwException', `Device firmware version is too low, please update to ${versionRange.min}`));
|
|
13099
|
+
}
|
|
13100
|
+
if (versionRange.max &&
|
|
13101
|
+
semver__default["default"].valid(versionRange.max) &&
|
|
13102
|
+
semver__default["default"].gt(currentVersion, versionRange.max)) {
|
|
13103
|
+
return Promise.reject(TypedError('Device_FwException', `Device firmware version is too high, this method has been deprecated in ${versionRange.max}`));
|
|
13104
|
+
}
|
|
13105
|
+
}
|
|
12406
13106
|
const unexpectedMode = device.hasUnexpectedMode(method.allowDeviceMode, method.requireDeviceMode);
|
|
12407
13107
|
if (unexpectedMode) {
|
|
12408
13108
|
return Promise.reject(TypedError('Device_UnexpectedMode', unexpectedMode));
|
|
@@ -12436,6 +13136,7 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
12436
13136
|
catch (error) {
|
|
12437
13137
|
messageResponse = createResponseMessage(method.responseID, false, error);
|
|
12438
13138
|
_callPromise === null || _callPromise === void 0 ? void 0 : _callPromise.reject(TypedError('Call_API', error));
|
|
13139
|
+
Log.debug('Call API - Run Error: ', error);
|
|
12439
13140
|
}
|
|
12440
13141
|
finally {
|
|
12441
13142
|
const response = messageResponse;
|
|
@@ -12514,7 +13215,15 @@ const onDevicePinHandler = (...[device, type, callback]) => __awaiter(void 0, vo
|
|
|
12514
13215
|
});
|
|
12515
13216
|
const onDeviceButtonHandler = (...[device, request]) => {
|
|
12516
13217
|
postMessage(createDeviceMessage(DEVICE.BUTTON, Object.assign(Object.assign({}, request), { device: device.toMessageObject() })));
|
|
12517
|
-
|
|
13218
|
+
if (request.code === 'ButtonRequest_PinEntry') {
|
|
13219
|
+
postMessage(createUiMessage(UI_REQUEST$1.REQUEST_PIN, {
|
|
13220
|
+
device: device.toMessageObject(),
|
|
13221
|
+
type: 'ButtonRequest_PinEntry',
|
|
13222
|
+
}));
|
|
13223
|
+
}
|
|
13224
|
+
else {
|
|
13225
|
+
postMessage(createUiMessage(UI_REQUEST$1.REQUEST_BUTTON, { device: device.toMessageObject() }));
|
|
13226
|
+
}
|
|
12518
13227
|
};
|
|
12519
13228
|
const postMessage = (message) => {
|
|
12520
13229
|
_core.emit(CORE_EVENT, message);
|