@onekeyfe/hd-web-sdk 0.2.7 → 0.2.9
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/data/messages/messages.json +217 -69
- package/build/iframe.html +1 -1
- package/build/js/iframe.8c60e46473a94b579154.js +3 -0
- package/build/js/{iframe.4213283e3f22e5567768.js.LICENSE.txt → iframe.8c60e46473a94b579154.js.LICENSE.txt} +0 -0
- package/build/js/iframe.8c60e46473a94b579154.js.map +1 -0
- package/build/onekey-js-sdk.js +1580 -20
- 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/package.json +6 -6
- package/build/js/iframe.4213283e3f22e5567768.js +0 -3
- package/build/js/iframe.4213283e3f22e5567768.js.map +0 -1
package/build/onekey-js-sdk.js
CHANGED
|
@@ -7452,6 +7452,36 @@ const inject = ({
|
|
|
7452
7452
|
connectId,
|
|
7453
7453
|
deviceId,
|
|
7454
7454
|
method: 'xrpSignTransaction'
|
|
7455
|
+
})),
|
|
7456
|
+
suiGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
7457
|
+
connectId,
|
|
7458
|
+
deviceId,
|
|
7459
|
+
method: 'suiGetAddress'
|
|
7460
|
+
})),
|
|
7461
|
+
suiGetPublicKey: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
7462
|
+
connectId,
|
|
7463
|
+
deviceId,
|
|
7464
|
+
method: 'suiGetPublicKey'
|
|
7465
|
+
})),
|
|
7466
|
+
suiSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
7467
|
+
connectId,
|
|
7468
|
+
deviceId,
|
|
7469
|
+
method: 'suiSignTransaction'
|
|
7470
|
+
})),
|
|
7471
|
+
cardanoGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
7472
|
+
connectId,
|
|
7473
|
+
deviceId,
|
|
7474
|
+
method: 'cardanoGetAddress'
|
|
7475
|
+
})),
|
|
7476
|
+
cardanoGetPublicKey: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
7477
|
+
connectId,
|
|
7478
|
+
deviceId,
|
|
7479
|
+
method: 'cardanoGetPublicKey'
|
|
7480
|
+
})),
|
|
7481
|
+
cardanoSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
|
|
7482
|
+
connectId,
|
|
7483
|
+
deviceId,
|
|
7484
|
+
method: 'cardanoSignTransaction'
|
|
7455
7485
|
}))
|
|
7456
7486
|
};
|
|
7457
7487
|
return api;
|
|
@@ -10253,6 +10283,45 @@ var nested = {
|
|
|
10253
10283
|
rule: "required",
|
|
10254
10284
|
type: "CardanoDerivationType",
|
|
10255
10285
|
id: 14
|
|
10286
|
+
},
|
|
10287
|
+
include_network_id: {
|
|
10288
|
+
type: "bool",
|
|
10289
|
+
id: 15,
|
|
10290
|
+
options: {
|
|
10291
|
+
"default": false
|
|
10292
|
+
}
|
|
10293
|
+
},
|
|
10294
|
+
script_data_hash: {
|
|
10295
|
+
type: "bytes",
|
|
10296
|
+
id: 16
|
|
10297
|
+
},
|
|
10298
|
+
collateral_inputs_count: {
|
|
10299
|
+
rule: "required",
|
|
10300
|
+
type: "uint32",
|
|
10301
|
+
id: 17
|
|
10302
|
+
},
|
|
10303
|
+
required_signers_count: {
|
|
10304
|
+
rule: "required",
|
|
10305
|
+
type: "uint32",
|
|
10306
|
+
id: 18
|
|
10307
|
+
},
|
|
10308
|
+
has_collateral_return: {
|
|
10309
|
+
type: "bool",
|
|
10310
|
+
id: 19,
|
|
10311
|
+
options: {
|
|
10312
|
+
"default": false
|
|
10313
|
+
}
|
|
10314
|
+
},
|
|
10315
|
+
total_collateral: {
|
|
10316
|
+
type: "uint64",
|
|
10317
|
+
id: 20
|
|
10318
|
+
},
|
|
10319
|
+
reference_inputs_count: {
|
|
10320
|
+
type: "uint32",
|
|
10321
|
+
id: 21,
|
|
10322
|
+
options: {
|
|
10323
|
+
"default": 0
|
|
10324
|
+
}
|
|
10256
10325
|
}
|
|
10257
10326
|
}
|
|
10258
10327
|
},
|
|
@@ -13885,6 +13954,52 @@ var nested = {
|
|
|
13885
13954
|
RebootToBootloader: {
|
|
13886
13955
|
fields: {}
|
|
13887
13956
|
},
|
|
13957
|
+
RebootToBoardloader: {
|
|
13958
|
+
fields: {}
|
|
13959
|
+
},
|
|
13960
|
+
ListResDir: {
|
|
13961
|
+
fields: {
|
|
13962
|
+
path: {
|
|
13963
|
+
rule: "required",
|
|
13964
|
+
type: "string",
|
|
13965
|
+
id: 1
|
|
13966
|
+
}
|
|
13967
|
+
}
|
|
13968
|
+
},
|
|
13969
|
+
FileInfoList: {
|
|
13970
|
+
fields: {
|
|
13971
|
+
files: {
|
|
13972
|
+
rule: "repeated",
|
|
13973
|
+
type: "FileInfo",
|
|
13974
|
+
id: 1
|
|
13975
|
+
}
|
|
13976
|
+
},
|
|
13977
|
+
nested: {
|
|
13978
|
+
FileInfo: {
|
|
13979
|
+
fields: {
|
|
13980
|
+
name: {
|
|
13981
|
+
rule: "required",
|
|
13982
|
+
type: "string",
|
|
13983
|
+
id: 1
|
|
13984
|
+
},
|
|
13985
|
+
size: {
|
|
13986
|
+
rule: "required",
|
|
13987
|
+
type: "uint64",
|
|
13988
|
+
id: 2
|
|
13989
|
+
}
|
|
13990
|
+
}
|
|
13991
|
+
}
|
|
13992
|
+
}
|
|
13993
|
+
},
|
|
13994
|
+
DeviceEraseSector: {
|
|
13995
|
+
fields: {
|
|
13996
|
+
sector: {
|
|
13997
|
+
rule: "required",
|
|
13998
|
+
type: "uint32",
|
|
13999
|
+
id: 1
|
|
14000
|
+
}
|
|
14001
|
+
}
|
|
14002
|
+
},
|
|
13888
14003
|
MoneroTransactionSourceEntry: {
|
|
13889
14004
|
fields: {
|
|
13890
14005
|
outputs: {
|
|
@@ -16018,6 +16133,61 @@ var nested = {
|
|
|
16018
16133
|
}
|
|
16019
16134
|
}
|
|
16020
16135
|
},
|
|
16136
|
+
SuiGetAddress: {
|
|
16137
|
+
fields: {
|
|
16138
|
+
address_n: {
|
|
16139
|
+
rule: "repeated",
|
|
16140
|
+
type: "uint32",
|
|
16141
|
+
id: 1,
|
|
16142
|
+
options: {
|
|
16143
|
+
packed: false
|
|
16144
|
+
}
|
|
16145
|
+
},
|
|
16146
|
+
show_display: {
|
|
16147
|
+
type: "bool",
|
|
16148
|
+
id: 2
|
|
16149
|
+
}
|
|
16150
|
+
}
|
|
16151
|
+
},
|
|
16152
|
+
SuiAddress: {
|
|
16153
|
+
fields: {
|
|
16154
|
+
address: {
|
|
16155
|
+
type: "string",
|
|
16156
|
+
id: 1
|
|
16157
|
+
}
|
|
16158
|
+
}
|
|
16159
|
+
},
|
|
16160
|
+
SuiSignTx: {
|
|
16161
|
+
fields: {
|
|
16162
|
+
address_n: {
|
|
16163
|
+
rule: "repeated",
|
|
16164
|
+
type: "uint32",
|
|
16165
|
+
id: 1,
|
|
16166
|
+
options: {
|
|
16167
|
+
packed: false
|
|
16168
|
+
}
|
|
16169
|
+
},
|
|
16170
|
+
raw_tx: {
|
|
16171
|
+
rule: "required",
|
|
16172
|
+
type: "bytes",
|
|
16173
|
+
id: 2
|
|
16174
|
+
}
|
|
16175
|
+
}
|
|
16176
|
+
},
|
|
16177
|
+
SuiSignedTx: {
|
|
16178
|
+
fields: {
|
|
16179
|
+
public_key: {
|
|
16180
|
+
rule: "required",
|
|
16181
|
+
type: "bytes",
|
|
16182
|
+
id: 1
|
|
16183
|
+
},
|
|
16184
|
+
signature: {
|
|
16185
|
+
rule: "required",
|
|
16186
|
+
type: "bytes",
|
|
16187
|
+
id: 2
|
|
16188
|
+
}
|
|
16189
|
+
}
|
|
16190
|
+
},
|
|
16021
16191
|
TezosGetAddress: {
|
|
16022
16192
|
fields: {
|
|
16023
16193
|
address_n: {
|
|
@@ -17015,6 +17185,10 @@ var nested = {
|
|
|
17015
17185
|
MessageType_AlgorandAddress: 10901,
|
|
17016
17186
|
MessageType_AlgorandSignTx: 10902,
|
|
17017
17187
|
MessageType_AlgorandSignedTx: 10903,
|
|
17188
|
+
MessageType_SuiGetAddress: 11100,
|
|
17189
|
+
MessageType_SuiAddress: 11101,
|
|
17190
|
+
MessageType_SuiSignTx: 11102,
|
|
17191
|
+
MessageType_SuiSignedTx: 11103,
|
|
17018
17192
|
MessageType_DeviceBackToBoot: 903,
|
|
17019
17193
|
MessageType_DeviceInfoSettings: 10001,
|
|
17020
17194
|
MessageType_GetDeviceInfo: 10002,
|
|
@@ -17035,7 +17209,11 @@ var nested = {
|
|
|
17035
17209
|
MessageType_ZoomRequest: 10019,
|
|
17036
17210
|
MessageType_ResourceRequest: 10020,
|
|
17037
17211
|
MessageType_ResourceAck: 10021,
|
|
17038
|
-
MessageType_ResourceUpdate: 10022
|
|
17212
|
+
MessageType_ResourceUpdate: 10022,
|
|
17213
|
+
MessageType_ListResDir: 10023,
|
|
17214
|
+
MessageType_FileInfoList: 10024,
|
|
17215
|
+
MessageType_RebootToBoardloader: 10025,
|
|
17216
|
+
MessageType_DeviceEraseSector: 10026
|
|
17039
17217
|
}
|
|
17040
17218
|
},
|
|
17041
17219
|
google: {
|
|
@@ -19328,6 +19506,10 @@ class Device extends events.exports {
|
|
|
19328
19506
|
payload.session_id = internalState;
|
|
19329
19507
|
}
|
|
19330
19508
|
|
|
19509
|
+
if (options === null || options === void 0 ? void 0 : options.deriveCardano) {
|
|
19510
|
+
payload.derive_cardano = true;
|
|
19511
|
+
}
|
|
19512
|
+
|
|
19331
19513
|
Log$5.debug('initialize payload:', payload);
|
|
19332
19514
|
const {
|
|
19333
19515
|
message
|
|
@@ -19694,8 +19876,10 @@ class BaseMethod {
|
|
|
19694
19876
|
checkDeviceSupportFeature() {
|
|
19695
19877
|
if (!this.device || !this.device.features) return;
|
|
19696
19878
|
const inputPinOnSoftware = supportInputPinOnSoftware(this.device.features);
|
|
19879
|
+
const modifyHomescreen = supportModifyHomescreen(this.device.features);
|
|
19697
19880
|
this.postMessage(createDeviceMessage(DEVICE.SUPPORT_FEATURES, {
|
|
19698
19881
|
inputPinOnSoftware,
|
|
19882
|
+
modifyHomescreen,
|
|
19699
19883
|
device: this.device.toMessageObject()
|
|
19700
19884
|
}));
|
|
19701
19885
|
}
|
|
@@ -20025,6 +20209,17 @@ const validateParams = (values, fields) => {
|
|
|
20025
20209
|
|
|
20026
20210
|
break;
|
|
20027
20211
|
|
|
20212
|
+
case 'uint':
|
|
20213
|
+
if (typeof value !== 'string' && typeof value !== 'number') {
|
|
20214
|
+
throw invalidParameter(`Parameter [${field.name}] has invalid type. "string|number" expected.`);
|
|
20215
|
+
}
|
|
20216
|
+
|
|
20217
|
+
if (typeof value === 'number' && !Number.isSafeInteger(value) || !/^(?:[1-9]\d*|\d)$/.test(value.toString().replace(/^-/, field.allowNegative ? '' : '-'))) {
|
|
20218
|
+
throw invalidParameter(`Parameter [${field.name}] has invalid value "${value}". Integer representation expected.`);
|
|
20219
|
+
}
|
|
20220
|
+
|
|
20221
|
+
break;
|
|
20222
|
+
|
|
20028
20223
|
case 'bigNumber':
|
|
20029
20224
|
if (typeof value !== 'string') {
|
|
20030
20225
|
throw invalidParameter(`Parameter [${field.name}] is of type invalid and should be [string].`);
|
|
@@ -20562,8 +20757,6 @@ const getInfo = ({
|
|
|
20562
20757
|
return findLatestRelease(releaseInfo);
|
|
20563
20758
|
};
|
|
20564
20759
|
|
|
20565
|
-
getLogger(exports.d0.Device);
|
|
20566
|
-
|
|
20567
20760
|
const postConfirmationMessage = device => {
|
|
20568
20761
|
var _a;
|
|
20569
20762
|
|
|
@@ -21948,7 +22141,7 @@ const saveTxSignatures = (serializedTx, signatures, txRequest) => {
|
|
|
21948
22141
|
|
|
21949
22142
|
if (typeof signature_index === 'number') {
|
|
21950
22143
|
if (!signature) {
|
|
21951
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'saveTxSignatures: Unexpected null in
|
|
22144
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'saveTxSignatures: Unexpected null in oneKey:TxRequestSerialized signature.');
|
|
21952
22145
|
}
|
|
21953
22146
|
|
|
21954
22147
|
signatures[signature_index] = signature;
|
|
@@ -25403,6 +25596,1378 @@ class XrpGetAddress extends BaseMethod {
|
|
|
25403
25596
|
|
|
25404
25597
|
}
|
|
25405
25598
|
|
|
25599
|
+
class SuiGetAddress extends BaseMethod {
|
|
25600
|
+
constructor() {
|
|
25601
|
+
super(...arguments);
|
|
25602
|
+
this.hasBundle = false;
|
|
25603
|
+
}
|
|
25604
|
+
|
|
25605
|
+
init() {
|
|
25606
|
+
var _a;
|
|
25607
|
+
|
|
25608
|
+
this.checkDeviceId = true;
|
|
25609
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
25610
|
+
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
25611
|
+
const payload = this.hasBundle ? this.payload : {
|
|
25612
|
+
bundle: [this.payload]
|
|
25613
|
+
};
|
|
25614
|
+
validateParams(payload, [{
|
|
25615
|
+
name: 'bundle',
|
|
25616
|
+
type: 'array'
|
|
25617
|
+
}]);
|
|
25618
|
+
this.params = [];
|
|
25619
|
+
payload.bundle.forEach(batch => {
|
|
25620
|
+
var _a;
|
|
25621
|
+
|
|
25622
|
+
const addressN = validatePath(batch.path, 3);
|
|
25623
|
+
validateParams(batch, [{
|
|
25624
|
+
name: 'path',
|
|
25625
|
+
required: true
|
|
25626
|
+
}, {
|
|
25627
|
+
name: 'showOnOneKey',
|
|
25628
|
+
type: 'boolean'
|
|
25629
|
+
}]);
|
|
25630
|
+
const showOnOneKey = (_a = batch.showOnOneKey) !== null && _a !== void 0 ? _a : true;
|
|
25631
|
+
this.params.push({
|
|
25632
|
+
address_n: addressN,
|
|
25633
|
+
show_display: showOnOneKey
|
|
25634
|
+
});
|
|
25635
|
+
});
|
|
25636
|
+
}
|
|
25637
|
+
|
|
25638
|
+
publicKeyToAddress(publicKey) {
|
|
25639
|
+
const hash = sha3.sha3_256.create();
|
|
25640
|
+
hash.update('\x00');
|
|
25641
|
+
hash.update(hexToBytes(publicKey));
|
|
25642
|
+
return `0x${utils.bytesToHex(hash.digest().slice(0, 20))}`;
|
|
25643
|
+
}
|
|
25644
|
+
|
|
25645
|
+
getVersionRange() {
|
|
25646
|
+
return {
|
|
25647
|
+
model_mini: {
|
|
25648
|
+
min: '2.9.0'
|
|
25649
|
+
},
|
|
25650
|
+
model_touch: {
|
|
25651
|
+
min: '3.5.0'
|
|
25652
|
+
}
|
|
25653
|
+
};
|
|
25654
|
+
}
|
|
25655
|
+
|
|
25656
|
+
run() {
|
|
25657
|
+
var _a;
|
|
25658
|
+
|
|
25659
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25660
|
+
if (this.hasBundle && supportBatchPublicKey((_a = this.device) === null || _a === void 0 ? void 0 : _a.features)) {
|
|
25661
|
+
const res = yield this.device.commands.typedCall('BatchGetPublickeys', 'EcdsaPublicKeys', {
|
|
25662
|
+
paths: this.params,
|
|
25663
|
+
ecdsa_curve_name: 'ed25519'
|
|
25664
|
+
});
|
|
25665
|
+
const result = res.message.public_keys.map((publicKey, index) => ({
|
|
25666
|
+
path: serializedPath(this.params[index].address_n),
|
|
25667
|
+
publicKey,
|
|
25668
|
+
address: this.publicKeyToAddress(publicKey)
|
|
25669
|
+
}));
|
|
25670
|
+
return Promise.resolve(result);
|
|
25671
|
+
}
|
|
25672
|
+
|
|
25673
|
+
const responses = [];
|
|
25674
|
+
|
|
25675
|
+
for (let i = 0; i < this.params.length; i++) {
|
|
25676
|
+
const param = this.params[i];
|
|
25677
|
+
const res = yield this.device.commands.typedCall('SuiGetAddress', 'SuiAddress', Object.assign({}, param));
|
|
25678
|
+
const {
|
|
25679
|
+
address
|
|
25680
|
+
} = res.message;
|
|
25681
|
+
responses.push({
|
|
25682
|
+
path: serializedPath(param.address_n),
|
|
25683
|
+
address: address === null || address === void 0 ? void 0 : address.toLowerCase()
|
|
25684
|
+
});
|
|
25685
|
+
}
|
|
25686
|
+
|
|
25687
|
+
return Promise.resolve(this.hasBundle ? responses : responses[0]);
|
|
25688
|
+
});
|
|
25689
|
+
}
|
|
25690
|
+
|
|
25691
|
+
}
|
|
25692
|
+
|
|
25693
|
+
class SuiGetPublicKey extends BaseMethod {
|
|
25694
|
+
constructor() {
|
|
25695
|
+
super(...arguments);
|
|
25696
|
+
this.hasBundle = false;
|
|
25697
|
+
}
|
|
25698
|
+
|
|
25699
|
+
init() {
|
|
25700
|
+
var _a;
|
|
25701
|
+
|
|
25702
|
+
this.checkDeviceId = true;
|
|
25703
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
25704
|
+
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
25705
|
+
const payload = this.hasBundle ? this.payload : {
|
|
25706
|
+
bundle: [this.payload]
|
|
25707
|
+
};
|
|
25708
|
+
validateParams(payload, [{
|
|
25709
|
+
name: 'bundle',
|
|
25710
|
+
type: 'array'
|
|
25711
|
+
}]);
|
|
25712
|
+
this.params = [];
|
|
25713
|
+
payload.bundle.forEach(batch => {
|
|
25714
|
+
var _a;
|
|
25715
|
+
|
|
25716
|
+
const addressN = validatePath(batch.path, 3);
|
|
25717
|
+
validateParams(batch, [{
|
|
25718
|
+
name: 'path',
|
|
25719
|
+
required: true
|
|
25720
|
+
}, {
|
|
25721
|
+
name: 'showOnOneKey',
|
|
25722
|
+
type: 'boolean'
|
|
25723
|
+
}]);
|
|
25724
|
+
const showOnOneKey = (_a = batch.showOnOneKey) !== null && _a !== void 0 ? _a : true;
|
|
25725
|
+
this.params.push({
|
|
25726
|
+
address_n: addressN,
|
|
25727
|
+
show_display: showOnOneKey
|
|
25728
|
+
});
|
|
25729
|
+
});
|
|
25730
|
+
}
|
|
25731
|
+
|
|
25732
|
+
getVersionRange() {
|
|
25733
|
+
return {
|
|
25734
|
+
model_mini: {
|
|
25735
|
+
min: '2.9.0'
|
|
25736
|
+
},
|
|
25737
|
+
model_touch: {
|
|
25738
|
+
min: '3.5.0'
|
|
25739
|
+
}
|
|
25740
|
+
};
|
|
25741
|
+
}
|
|
25742
|
+
|
|
25743
|
+
run() {
|
|
25744
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25745
|
+
const res = yield this.device.commands.typedCall('BatchGetPublickeys', 'EcdsaPublicKeys', {
|
|
25746
|
+
paths: this.params,
|
|
25747
|
+
ecdsa_curve_name: 'ed25519'
|
|
25748
|
+
});
|
|
25749
|
+
const responses = res.message.public_keys.map((publicKey, index) => ({
|
|
25750
|
+
path: serializedPath(this.params[index].address_n),
|
|
25751
|
+
publicKey
|
|
25752
|
+
}));
|
|
25753
|
+
return Promise.resolve(this.hasBundle ? responses : responses[0]);
|
|
25754
|
+
});
|
|
25755
|
+
}
|
|
25756
|
+
|
|
25757
|
+
}
|
|
25758
|
+
|
|
25759
|
+
class SuiSignTransaction extends BaseMethod {
|
|
25760
|
+
init() {
|
|
25761
|
+
this.checkDeviceId = true;
|
|
25762
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
25763
|
+
validateParams(this.payload, [{
|
|
25764
|
+
name: 'path',
|
|
25765
|
+
required: true
|
|
25766
|
+
}, {
|
|
25767
|
+
name: 'rawTx',
|
|
25768
|
+
type: 'hexString',
|
|
25769
|
+
required: true
|
|
25770
|
+
}]);
|
|
25771
|
+
const {
|
|
25772
|
+
path,
|
|
25773
|
+
rawTx
|
|
25774
|
+
} = this.payload;
|
|
25775
|
+
const addressN = validatePath(path, 3);
|
|
25776
|
+
this.params = {
|
|
25777
|
+
address_n: addressN,
|
|
25778
|
+
raw_tx: formatAnyHex(rawTx)
|
|
25779
|
+
};
|
|
25780
|
+
}
|
|
25781
|
+
|
|
25782
|
+
getVersionRange() {
|
|
25783
|
+
return {
|
|
25784
|
+
model_mini: {
|
|
25785
|
+
min: '2.9.0'
|
|
25786
|
+
},
|
|
25787
|
+
model_touch: {
|
|
25788
|
+
min: '3.5.0'
|
|
25789
|
+
}
|
|
25790
|
+
};
|
|
25791
|
+
}
|
|
25792
|
+
|
|
25793
|
+
run() {
|
|
25794
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25795
|
+
const res = yield this.device.commands.typedCall('SuiSignTx', 'SuiSignedTx', Object.assign({}, this.params));
|
|
25796
|
+
return Promise.resolve(res.message);
|
|
25797
|
+
});
|
|
25798
|
+
}
|
|
25799
|
+
|
|
25800
|
+
}
|
|
25801
|
+
|
|
25802
|
+
const safeThrowError = error => {
|
|
25803
|
+
if (error instanceof hdShared.HardwareError) {
|
|
25804
|
+
throw error;
|
|
25805
|
+
} else if (error.code === 'ERR_NETWORK') {
|
|
25806
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeNotInstalled);
|
|
25807
|
+
} else if (error.code === 'ECONNABORTED') {
|
|
25808
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError);
|
|
25809
|
+
} else {
|
|
25810
|
+
throw hdShared.ERRORS.TypedError(error);
|
|
25811
|
+
}
|
|
25812
|
+
};
|
|
25813
|
+
|
|
25814
|
+
const validateAddressParameters = addressParameters => {
|
|
25815
|
+
validateParams(addressParameters, [{
|
|
25816
|
+
name: 'addressType',
|
|
25817
|
+
type: 'number',
|
|
25818
|
+
required: true
|
|
25819
|
+
}, {
|
|
25820
|
+
name: 'stakingKeyHash',
|
|
25821
|
+
type: 'string'
|
|
25822
|
+
}, {
|
|
25823
|
+
name: 'paymentScriptHash',
|
|
25824
|
+
type: 'string'
|
|
25825
|
+
}, {
|
|
25826
|
+
name: 'stakingScriptHash',
|
|
25827
|
+
type: 'string'
|
|
25828
|
+
}]);
|
|
25829
|
+
|
|
25830
|
+
if (addressParameters.path) {
|
|
25831
|
+
validatePath(addressParameters.path);
|
|
25832
|
+
}
|
|
25833
|
+
|
|
25834
|
+
if (addressParameters.stakingPath) {
|
|
25835
|
+
validatePath(addressParameters.stakingPath);
|
|
25836
|
+
}
|
|
25837
|
+
|
|
25838
|
+
if (addressParameters.certificatePointer) {
|
|
25839
|
+
validateParams(addressParameters.certificatePointer, [{
|
|
25840
|
+
name: 'blockIndex',
|
|
25841
|
+
type: 'number',
|
|
25842
|
+
required: true
|
|
25843
|
+
}, {
|
|
25844
|
+
name: 'txIndex',
|
|
25845
|
+
type: 'number',
|
|
25846
|
+
required: true
|
|
25847
|
+
}, {
|
|
25848
|
+
name: 'certificateIndex',
|
|
25849
|
+
type: 'number',
|
|
25850
|
+
required: true
|
|
25851
|
+
}]);
|
|
25852
|
+
}
|
|
25853
|
+
};
|
|
25854
|
+
|
|
25855
|
+
const addressParametersToProto = addressParameters => {
|
|
25856
|
+
let path = [];
|
|
25857
|
+
|
|
25858
|
+
if (addressParameters.path) {
|
|
25859
|
+
path = validatePath(addressParameters.path, 3);
|
|
25860
|
+
}
|
|
25861
|
+
|
|
25862
|
+
let stakingPath = [];
|
|
25863
|
+
|
|
25864
|
+
if (addressParameters.stakingPath) {
|
|
25865
|
+
stakingPath = validatePath(addressParameters.stakingPath, 3);
|
|
25866
|
+
}
|
|
25867
|
+
|
|
25868
|
+
let certificatePointer;
|
|
25869
|
+
|
|
25870
|
+
if (addressParameters.certificatePointer) {
|
|
25871
|
+
certificatePointer = {
|
|
25872
|
+
block_index: addressParameters.certificatePointer.blockIndex,
|
|
25873
|
+
tx_index: addressParameters.certificatePointer.txIndex,
|
|
25874
|
+
certificate_index: addressParameters.certificatePointer.certificateIndex
|
|
25875
|
+
};
|
|
25876
|
+
}
|
|
25877
|
+
|
|
25878
|
+
return {
|
|
25879
|
+
address_type: addressParameters.addressType,
|
|
25880
|
+
address_n: path,
|
|
25881
|
+
address_n_staking: stakingPath,
|
|
25882
|
+
staking_key_hash: addressParameters.stakingKeyHash,
|
|
25883
|
+
certificate_pointer: certificatePointer,
|
|
25884
|
+
script_payment_hash: addressParameters.paymentScriptHash,
|
|
25885
|
+
script_staking_hash: addressParameters.stakingScriptHash
|
|
25886
|
+
};
|
|
25887
|
+
};
|
|
25888
|
+
|
|
25889
|
+
const addressParametersFromProto = addressParameters => {
|
|
25890
|
+
let certificatePointer;
|
|
25891
|
+
|
|
25892
|
+
if (addressParameters.certificate_pointer) {
|
|
25893
|
+
certificatePointer = {
|
|
25894
|
+
blockIndex: addressParameters.certificate_pointer.block_index,
|
|
25895
|
+
txIndex: addressParameters.certificate_pointer.tx_index,
|
|
25896
|
+
certificateIndex: addressParameters.certificate_pointer.certificate_index
|
|
25897
|
+
};
|
|
25898
|
+
}
|
|
25899
|
+
|
|
25900
|
+
return {
|
|
25901
|
+
addressType: addressParameters.address_type,
|
|
25902
|
+
path: addressParameters.address_n,
|
|
25903
|
+
stakingPath: addressParameters.address_n_staking,
|
|
25904
|
+
stakingKeyHash: addressParameters.staking_key_hash,
|
|
25905
|
+
certificatePointer
|
|
25906
|
+
};
|
|
25907
|
+
};
|
|
25908
|
+
|
|
25909
|
+
const modifyAddressParametersForBackwardsCompatibility = address_parameters => {
|
|
25910
|
+
if (address_parameters.address_type === hdTransport.Messages.CardanoAddressType.REWARD) {
|
|
25911
|
+
let {
|
|
25912
|
+
address_n,
|
|
25913
|
+
address_n_staking
|
|
25914
|
+
} = address_parameters;
|
|
25915
|
+
|
|
25916
|
+
if (address_n.length > 0 && address_n_staking.length > 0) {
|
|
25917
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Only stakingPath is allowed for CardanoAddressType.REWARD`);
|
|
25918
|
+
}
|
|
25919
|
+
|
|
25920
|
+
if (address_n.length > 0) {
|
|
25921
|
+
address_n_staking = address_n;
|
|
25922
|
+
address_n = [];
|
|
25923
|
+
}
|
|
25924
|
+
|
|
25925
|
+
return Object.assign(Object.assign({}, address_parameters), {
|
|
25926
|
+
address_n,
|
|
25927
|
+
address_n_staking
|
|
25928
|
+
});
|
|
25929
|
+
}
|
|
25930
|
+
|
|
25931
|
+
return address_parameters;
|
|
25932
|
+
};
|
|
25933
|
+
|
|
25934
|
+
class CardanoGetAddress extends BaseMethod {
|
|
25935
|
+
init() {
|
|
25936
|
+
var _a;
|
|
25937
|
+
|
|
25938
|
+
this.checkDeviceId = true;
|
|
25939
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
25940
|
+
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
25941
|
+
const payload = this.hasBundle ? this.payload : {
|
|
25942
|
+
bundle: [this.payload]
|
|
25943
|
+
};
|
|
25944
|
+
this.params = payload.bundle.map(batch => {
|
|
25945
|
+
validateParams(batch, [{
|
|
25946
|
+
name: 'addressParameters',
|
|
25947
|
+
type: 'object',
|
|
25948
|
+
required: true
|
|
25949
|
+
}, {
|
|
25950
|
+
name: 'networkId',
|
|
25951
|
+
type: 'number',
|
|
25952
|
+
required: true
|
|
25953
|
+
}, {
|
|
25954
|
+
name: 'protocolMagic',
|
|
25955
|
+
type: 'number',
|
|
25956
|
+
required: true
|
|
25957
|
+
}, {
|
|
25958
|
+
name: 'derivationType',
|
|
25959
|
+
type: 'number'
|
|
25960
|
+
}, {
|
|
25961
|
+
name: 'address',
|
|
25962
|
+
type: 'string'
|
|
25963
|
+
}, {
|
|
25964
|
+
name: 'showOnTrezor',
|
|
25965
|
+
type: 'boolean'
|
|
25966
|
+
}]);
|
|
25967
|
+
validateAddressParameters(batch.addressParameters);
|
|
25968
|
+
return {
|
|
25969
|
+
address_parameters: addressParametersToProto(batch.addressParameters),
|
|
25970
|
+
address: batch.address,
|
|
25971
|
+
protocol_magic: batch.protocolMagic,
|
|
25972
|
+
network_id: batch.networkId,
|
|
25973
|
+
derivation_type: typeof batch.derivationType !== 'undefined' ? batch.derivationType : hdTransport.Messages.CardanoDerivationType.ICARUS_TREZOR,
|
|
25974
|
+
show_display: typeof batch.showOnOneKey === 'boolean' ? !!batch.showOneKey : true
|
|
25975
|
+
};
|
|
25976
|
+
});
|
|
25977
|
+
}
|
|
25978
|
+
|
|
25979
|
+
run() {
|
|
25980
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25981
|
+
const responses = [];
|
|
25982
|
+
|
|
25983
|
+
for (const batch of this.params) {
|
|
25984
|
+
const {
|
|
25985
|
+
address_parameters,
|
|
25986
|
+
protocol_magic,
|
|
25987
|
+
network_id,
|
|
25988
|
+
derivation_type,
|
|
25989
|
+
show_display
|
|
25990
|
+
} = batch;
|
|
25991
|
+
const response = yield this.device.commands.typedCall('CardanoGetAddress', 'CardanoAddress', {
|
|
25992
|
+
address_parameters,
|
|
25993
|
+
protocol_magic,
|
|
25994
|
+
network_id,
|
|
25995
|
+
derivation_type,
|
|
25996
|
+
show_display
|
|
25997
|
+
});
|
|
25998
|
+
const publicKeyRes = yield this.device.commands.typedCall('CardanoGetPublicKey', 'CardanoPublicKey', {
|
|
25999
|
+
address_n: address_parameters.address_n.slice(0, 3),
|
|
26000
|
+
derivation_type,
|
|
26001
|
+
show_display
|
|
26002
|
+
});
|
|
26003
|
+
responses.push({
|
|
26004
|
+
addressParameters: addressParametersFromProto(batch.address_parameters),
|
|
26005
|
+
protocolMagic: batch.protocol_magic,
|
|
26006
|
+
networkId: batch.network_id,
|
|
26007
|
+
serializedPath: serializedPath(batch.address_parameters.address_n),
|
|
26008
|
+
serializedStakingPath: serializedPath(batch.address_parameters.address_n_staking),
|
|
26009
|
+
address: response.message.address,
|
|
26010
|
+
xpub: publicKeyRes.message.xpub
|
|
26011
|
+
});
|
|
26012
|
+
}
|
|
26013
|
+
|
|
26014
|
+
return this.hasBundle ? responses : responses[0];
|
|
26015
|
+
});
|
|
26016
|
+
}
|
|
26017
|
+
|
|
26018
|
+
}
|
|
26019
|
+
|
|
26020
|
+
class CardanoGetPublicKey extends BaseMethod {
|
|
26021
|
+
init() {
|
|
26022
|
+
var _a;
|
|
26023
|
+
|
|
26024
|
+
this.checkDeviceId = true;
|
|
26025
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
26026
|
+
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
26027
|
+
const payload = this.hasBundle ? this.payload : {
|
|
26028
|
+
bundle: [this.payload]
|
|
26029
|
+
};
|
|
26030
|
+
validateParams(payload, [{
|
|
26031
|
+
name: 'bundle',
|
|
26032
|
+
type: 'array'
|
|
26033
|
+
}]);
|
|
26034
|
+
this.params = payload.bundle.map(batch => {
|
|
26035
|
+
validateParams(batch, [{
|
|
26036
|
+
name: 'path',
|
|
26037
|
+
required: true
|
|
26038
|
+
}, {
|
|
26039
|
+
name: 'derivationType',
|
|
26040
|
+
type: 'number'
|
|
26041
|
+
}, {
|
|
26042
|
+
name: 'showOnTrezor',
|
|
26043
|
+
type: 'boolean'
|
|
26044
|
+
}]);
|
|
26045
|
+
const path = validatePath(batch.path, 3);
|
|
26046
|
+
return {
|
|
26047
|
+
address_n: path,
|
|
26048
|
+
derivation_type: typeof batch.derivationType !== 'undefined' ? batch.derivationType : hdTransport.Messages.CardanoDerivationType.ICARUS_TREZOR,
|
|
26049
|
+
show_display: typeof batch.showOnOneKey === 'boolean' ? batch.showOnOneKey : false
|
|
26050
|
+
};
|
|
26051
|
+
});
|
|
26052
|
+
}
|
|
26053
|
+
|
|
26054
|
+
run() {
|
|
26055
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26056
|
+
const responses = [];
|
|
26057
|
+
const cmd = this.device.getCommands();
|
|
26058
|
+
|
|
26059
|
+
for (let i = 0; i < this.params.length; i++) {
|
|
26060
|
+
const batch = this.params[i];
|
|
26061
|
+
const {
|
|
26062
|
+
message
|
|
26063
|
+
} = yield cmd.typedCall('CardanoGetPublicKey', 'CardanoPublicKey', batch);
|
|
26064
|
+
responses.push({
|
|
26065
|
+
path: batch.address_n,
|
|
26066
|
+
serializedPath: serializedPath(batch.address_n),
|
|
26067
|
+
publicKey: message.xpub,
|
|
26068
|
+
node: message.node
|
|
26069
|
+
});
|
|
26070
|
+
}
|
|
26071
|
+
|
|
26072
|
+
return this.hasBundle ? responses : responses[0];
|
|
26073
|
+
});
|
|
26074
|
+
}
|
|
26075
|
+
|
|
26076
|
+
}
|
|
26077
|
+
|
|
26078
|
+
const transformInput = input => {
|
|
26079
|
+
validateParams(input, [{
|
|
26080
|
+
name: 'prev_hash',
|
|
26081
|
+
type: 'string',
|
|
26082
|
+
required: true
|
|
26083
|
+
}, {
|
|
26084
|
+
name: 'prev_index',
|
|
26085
|
+
type: 'number',
|
|
26086
|
+
required: true
|
|
26087
|
+
}]);
|
|
26088
|
+
return {
|
|
26089
|
+
input: {
|
|
26090
|
+
prev_hash: input.prev_hash,
|
|
26091
|
+
prev_index: input.prev_index
|
|
26092
|
+
},
|
|
26093
|
+
path: input.path ? validatePath(input.path, 5) : undefined
|
|
26094
|
+
};
|
|
26095
|
+
};
|
|
26096
|
+
|
|
26097
|
+
const transformCollateralInput = collateralInput => {
|
|
26098
|
+
validateParams(collateralInput, [{
|
|
26099
|
+
name: 'prev_hash',
|
|
26100
|
+
type: 'string',
|
|
26101
|
+
required: true
|
|
26102
|
+
}, {
|
|
26103
|
+
name: 'prev_index',
|
|
26104
|
+
type: 'number',
|
|
26105
|
+
required: true
|
|
26106
|
+
}]);
|
|
26107
|
+
return {
|
|
26108
|
+
collateralInput: {
|
|
26109
|
+
prev_hash: collateralInput.prev_hash,
|
|
26110
|
+
prev_index: collateralInput.prev_index
|
|
26111
|
+
},
|
|
26112
|
+
path: collateralInput.path ? validatePath(collateralInput.path, 5) : undefined
|
|
26113
|
+
};
|
|
26114
|
+
};
|
|
26115
|
+
|
|
26116
|
+
const transformReferenceInput = referenceInput => {
|
|
26117
|
+
validateParams(referenceInput, [{
|
|
26118
|
+
name: 'prev_hash',
|
|
26119
|
+
type: 'string',
|
|
26120
|
+
required: true
|
|
26121
|
+
}, {
|
|
26122
|
+
name: 'prev_index',
|
|
26123
|
+
type: 'number',
|
|
26124
|
+
required: true
|
|
26125
|
+
}]);
|
|
26126
|
+
return {
|
|
26127
|
+
prev_hash: referenceInput.prev_hash,
|
|
26128
|
+
prev_index: referenceInput.prev_index
|
|
26129
|
+
};
|
|
26130
|
+
};
|
|
26131
|
+
|
|
26132
|
+
const validateTokens = tokenAmounts => {
|
|
26133
|
+
tokenAmounts.forEach(tokenAmount => {
|
|
26134
|
+
validateParams(tokenAmount, [{
|
|
26135
|
+
name: 'assetNameBytes',
|
|
26136
|
+
type: 'string',
|
|
26137
|
+
required: true
|
|
26138
|
+
}, {
|
|
26139
|
+
name: 'amount',
|
|
26140
|
+
type: 'uint'
|
|
26141
|
+
}, {
|
|
26142
|
+
name: 'mintAmount',
|
|
26143
|
+
type: 'uint',
|
|
26144
|
+
allowNegative: true
|
|
26145
|
+
}]);
|
|
26146
|
+
});
|
|
26147
|
+
};
|
|
26148
|
+
|
|
26149
|
+
const validateTokenBundle = tokenBundle => {
|
|
26150
|
+
tokenBundle.forEach(tokenGroup => {
|
|
26151
|
+
validateParams(tokenGroup, [{
|
|
26152
|
+
name: 'policyId',
|
|
26153
|
+
type: 'string',
|
|
26154
|
+
required: true
|
|
26155
|
+
}, {
|
|
26156
|
+
name: 'tokenAmounts',
|
|
26157
|
+
type: 'array',
|
|
26158
|
+
required: true
|
|
26159
|
+
}]);
|
|
26160
|
+
validateTokens(tokenGroup.tokenAmounts);
|
|
26161
|
+
});
|
|
26162
|
+
};
|
|
26163
|
+
|
|
26164
|
+
const tokenBundleToProto = tokenBundle => {
|
|
26165
|
+
validateTokenBundle(tokenBundle);
|
|
26166
|
+
return tokenBundle.map(tokenGroup => ({
|
|
26167
|
+
policyId: tokenGroup.policyId,
|
|
26168
|
+
tokens: tokenAmountsToProto(tokenGroup.tokenAmounts)
|
|
26169
|
+
}));
|
|
26170
|
+
};
|
|
26171
|
+
|
|
26172
|
+
const tokenAmountsToProto = tokenAmounts => tokenAmounts.map(tokenAmount => ({
|
|
26173
|
+
asset_name_bytes: tokenAmount.assetNameBytes,
|
|
26174
|
+
amount: tokenAmount.amount,
|
|
26175
|
+
mint_amount: tokenAmount.mintAmount
|
|
26176
|
+
}));
|
|
26177
|
+
|
|
26178
|
+
const hexStringByteLength = s => s.length / 2;
|
|
26179
|
+
|
|
26180
|
+
const sendChunkedHexString = (typedCall, data, chunkSize, messageType) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26181
|
+
let processedSize = 0;
|
|
26182
|
+
|
|
26183
|
+
while (processedSize < data.length) {
|
|
26184
|
+
const chunk = data.slice(processedSize, processedSize + chunkSize);
|
|
26185
|
+
yield typedCall(messageType, 'CardanoTxItemAck', {
|
|
26186
|
+
data: chunk
|
|
26187
|
+
});
|
|
26188
|
+
processedSize += chunkSize;
|
|
26189
|
+
}
|
|
26190
|
+
});
|
|
26191
|
+
|
|
26192
|
+
const transformOutput = output => {
|
|
26193
|
+
validateParams(output, [{
|
|
26194
|
+
name: 'address',
|
|
26195
|
+
type: 'string'
|
|
26196
|
+
}, {
|
|
26197
|
+
name: 'amount',
|
|
26198
|
+
type: 'uint',
|
|
26199
|
+
required: true
|
|
26200
|
+
}, {
|
|
26201
|
+
name: 'tokenBundle',
|
|
26202
|
+
type: 'array',
|
|
26203
|
+
allowEmpty: true
|
|
26204
|
+
}, {
|
|
26205
|
+
name: 'datumHash',
|
|
26206
|
+
type: 'string'
|
|
26207
|
+
}, {
|
|
26208
|
+
name: 'format',
|
|
26209
|
+
type: 'number'
|
|
26210
|
+
}, {
|
|
26211
|
+
name: 'inlineDatum',
|
|
26212
|
+
type: 'string'
|
|
26213
|
+
}, {
|
|
26214
|
+
name: 'referenceScript',
|
|
26215
|
+
type: 'string'
|
|
26216
|
+
}]);
|
|
26217
|
+
const result = {
|
|
26218
|
+
output: {
|
|
26219
|
+
amount: output.amount,
|
|
26220
|
+
asset_groups_count: 0,
|
|
26221
|
+
datum_hash: output.datumHash,
|
|
26222
|
+
format: output.format,
|
|
26223
|
+
inline_datum_size: output.inlineDatum ? hexStringByteLength(output.inlineDatum) : undefined,
|
|
26224
|
+
reference_script_size: output.referenceScript ? hexStringByteLength(output.referenceScript) : undefined
|
|
26225
|
+
},
|
|
26226
|
+
inlineDatum: output.inlineDatum,
|
|
26227
|
+
referenceScript: output.referenceScript
|
|
26228
|
+
};
|
|
26229
|
+
|
|
26230
|
+
if (output.addressParameters) {
|
|
26231
|
+
validateAddressParameters(output.addressParameters);
|
|
26232
|
+
result.output.address_parameters = addressParametersToProto(output.addressParameters);
|
|
26233
|
+
} else {
|
|
26234
|
+
result.output.address = output.address;
|
|
26235
|
+
}
|
|
26236
|
+
|
|
26237
|
+
if (output.tokenBundle) {
|
|
26238
|
+
result.tokenBundle = tokenBundleToProto(output.tokenBundle);
|
|
26239
|
+
result.output.asset_groups_count = result.tokenBundle.length;
|
|
26240
|
+
} else {
|
|
26241
|
+
result.output.asset_groups_count = 0;
|
|
26242
|
+
}
|
|
26243
|
+
|
|
26244
|
+
return result;
|
|
26245
|
+
};
|
|
26246
|
+
|
|
26247
|
+
const sendOutput = (typedCall, outputWithData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26248
|
+
const MAX_CHUNK_SIZE = 1024 * 2;
|
|
26249
|
+
const {
|
|
26250
|
+
output,
|
|
26251
|
+
tokenBundle,
|
|
26252
|
+
inlineDatum,
|
|
26253
|
+
referenceScript
|
|
26254
|
+
} = outputWithData;
|
|
26255
|
+
yield typedCall('CardanoTxOutput', 'CardanoTxItemAck', output);
|
|
26256
|
+
|
|
26257
|
+
if (tokenBundle) {
|
|
26258
|
+
for (const assetGroup of tokenBundle) {
|
|
26259
|
+
yield typedCall('CardanoAssetGroup', 'CardanoTxItemAck', {
|
|
26260
|
+
policy_id: assetGroup.policyId,
|
|
26261
|
+
tokens_count: assetGroup.tokens.length
|
|
26262
|
+
});
|
|
26263
|
+
|
|
26264
|
+
for (const token of assetGroup.tokens) {
|
|
26265
|
+
yield typedCall('CardanoToken', 'CardanoTxItemAck', token);
|
|
26266
|
+
}
|
|
26267
|
+
}
|
|
26268
|
+
}
|
|
26269
|
+
|
|
26270
|
+
if (inlineDatum) {
|
|
26271
|
+
yield sendChunkedHexString(typedCall, inlineDatum, MAX_CHUNK_SIZE, 'CardanoTxInlineDatumChunk');
|
|
26272
|
+
}
|
|
26273
|
+
|
|
26274
|
+
if (referenceScript) {
|
|
26275
|
+
yield sendChunkedHexString(typedCall, referenceScript, MAX_CHUNK_SIZE, 'CardanoTxReferenceScriptChunk');
|
|
26276
|
+
}
|
|
26277
|
+
});
|
|
26278
|
+
|
|
26279
|
+
const ipv4AddressToHex = ipv4Address => Buffer.from(ipv4Address.split('.').map(ipPart => parseInt(ipPart, 10))).toString('hex');
|
|
26280
|
+
|
|
26281
|
+
const ipv6AddressToHex = ipv6Address => ipv6Address.split(':').join('');
|
|
26282
|
+
|
|
26283
|
+
const validatePoolMargin = margin => {
|
|
26284
|
+
validateParams(margin, [{
|
|
26285
|
+
name: 'numerator',
|
|
26286
|
+
type: 'string',
|
|
26287
|
+
required: true
|
|
26288
|
+
}, {
|
|
26289
|
+
name: 'denominator',
|
|
26290
|
+
type: 'string',
|
|
26291
|
+
required: true
|
|
26292
|
+
}]);
|
|
26293
|
+
};
|
|
26294
|
+
|
|
26295
|
+
const validatePoolMetadata = metadata => {
|
|
26296
|
+
validateParams(metadata, [{
|
|
26297
|
+
name: 'url',
|
|
26298
|
+
type: 'string',
|
|
26299
|
+
required: true
|
|
26300
|
+
}, {
|
|
26301
|
+
name: 'hash',
|
|
26302
|
+
type: 'string',
|
|
26303
|
+
required: true
|
|
26304
|
+
}]);
|
|
26305
|
+
};
|
|
26306
|
+
|
|
26307
|
+
const validatePoolRelay = relay => {
|
|
26308
|
+
validateParams(relay, [{
|
|
26309
|
+
name: 'type',
|
|
26310
|
+
type: 'number',
|
|
26311
|
+
required: true
|
|
26312
|
+
}]);
|
|
26313
|
+
|
|
26314
|
+
if (relay.type === hdTransport.Messages.CardanoPoolRelayType.SINGLE_HOST_IP) {
|
|
26315
|
+
const paramsToValidate = [{
|
|
26316
|
+
name: 'port',
|
|
26317
|
+
type: 'number',
|
|
26318
|
+
required: true
|
|
26319
|
+
}];
|
|
26320
|
+
|
|
26321
|
+
if (relay.ipv4Address) {
|
|
26322
|
+
paramsToValidate.push({
|
|
26323
|
+
name: 'ipv4Address',
|
|
26324
|
+
type: 'string',
|
|
26325
|
+
required: false
|
|
26326
|
+
});
|
|
26327
|
+
}
|
|
26328
|
+
|
|
26329
|
+
if (relay.ipv6Address) {
|
|
26330
|
+
paramsToValidate.push({
|
|
26331
|
+
name: 'ipv6Address',
|
|
26332
|
+
type: 'string',
|
|
26333
|
+
required: false
|
|
26334
|
+
});
|
|
26335
|
+
}
|
|
26336
|
+
|
|
26337
|
+
validateParams(relay, paramsToValidate);
|
|
26338
|
+
|
|
26339
|
+
if (!relay.ipv4Address && !relay.ipv6Address) {
|
|
26340
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Either ipv4Address or ipv6Address must be supplied');
|
|
26341
|
+
}
|
|
26342
|
+
} else if (relay.type === hdTransport.Messages.CardanoPoolRelayType.SINGLE_HOST_NAME) {
|
|
26343
|
+
validateParams(relay, [{
|
|
26344
|
+
name: 'hostName',
|
|
26345
|
+
type: 'string',
|
|
26346
|
+
required: true
|
|
26347
|
+
}, {
|
|
26348
|
+
name: 'port',
|
|
26349
|
+
type: 'number',
|
|
26350
|
+
required: true
|
|
26351
|
+
}]);
|
|
26352
|
+
} else if (relay.type === hdTransport.Messages.CardanoPoolRelayType.MULTIPLE_HOST_NAME) {
|
|
26353
|
+
validateParams(relay, [{
|
|
26354
|
+
name: 'hostName',
|
|
26355
|
+
type: 'string',
|
|
26356
|
+
required: true
|
|
26357
|
+
}]);
|
|
26358
|
+
}
|
|
26359
|
+
};
|
|
26360
|
+
|
|
26361
|
+
const validatePoolOwners = owners => {
|
|
26362
|
+
owners.forEach(owner => {
|
|
26363
|
+
if (owner.stakingKeyHash) {
|
|
26364
|
+
validateParams(owner, [{
|
|
26365
|
+
name: 'stakingKeyHash',
|
|
26366
|
+
type: 'string',
|
|
26367
|
+
required: !owner.stakingKeyPath
|
|
26368
|
+
}]);
|
|
26369
|
+
}
|
|
26370
|
+
|
|
26371
|
+
if (owner.stakingKeyPath) {
|
|
26372
|
+
validatePath(owner.stakingKeyPath, 5);
|
|
26373
|
+
}
|
|
26374
|
+
|
|
26375
|
+
if (!owner.stakingKeyHash && !owner.stakingKeyPath) {
|
|
26376
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Either stakingKeyHash or stakingKeyPath must be supplied');
|
|
26377
|
+
}
|
|
26378
|
+
});
|
|
26379
|
+
const ownersAsPathCount = owners.filter(owner => !!owner.stakingKeyPath).length;
|
|
26380
|
+
|
|
26381
|
+
if (ownersAsPathCount !== 1) {
|
|
26382
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Exactly one pool owner must be given as a path');
|
|
26383
|
+
}
|
|
26384
|
+
};
|
|
26385
|
+
|
|
26386
|
+
const validatePoolParameters = poolParameters => {
|
|
26387
|
+
validateParams(poolParameters, [{
|
|
26388
|
+
name: 'poolId',
|
|
26389
|
+
type: 'string',
|
|
26390
|
+
required: true
|
|
26391
|
+
}, {
|
|
26392
|
+
name: 'vrfKeyHash',
|
|
26393
|
+
type: 'string',
|
|
26394
|
+
required: true
|
|
26395
|
+
}, {
|
|
26396
|
+
name: 'pledge',
|
|
26397
|
+
type: 'string',
|
|
26398
|
+
required: true
|
|
26399
|
+
}, {
|
|
26400
|
+
name: 'cost',
|
|
26401
|
+
type: 'string',
|
|
26402
|
+
required: true
|
|
26403
|
+
}, {
|
|
26404
|
+
name: 'margin',
|
|
26405
|
+
type: 'object',
|
|
26406
|
+
required: true
|
|
26407
|
+
}, {
|
|
26408
|
+
name: 'rewardAccount',
|
|
26409
|
+
type: 'string',
|
|
26410
|
+
required: true
|
|
26411
|
+
}, {
|
|
26412
|
+
name: 'owners',
|
|
26413
|
+
type: 'array',
|
|
26414
|
+
required: true
|
|
26415
|
+
}, {
|
|
26416
|
+
name: 'relays',
|
|
26417
|
+
type: 'array',
|
|
26418
|
+
required: true,
|
|
26419
|
+
allowEmpty: true
|
|
26420
|
+
}, {
|
|
26421
|
+
name: 'metadata',
|
|
26422
|
+
type: 'object'
|
|
26423
|
+
}]);
|
|
26424
|
+
validatePoolMargin(poolParameters.margin);
|
|
26425
|
+
validatePoolOwners(poolParameters.owners);
|
|
26426
|
+
poolParameters.relays.forEach(validatePoolRelay);
|
|
26427
|
+
|
|
26428
|
+
if (poolParameters.metadata) {
|
|
26429
|
+
validatePoolMetadata(poolParameters.metadata);
|
|
26430
|
+
}
|
|
26431
|
+
};
|
|
26432
|
+
|
|
26433
|
+
const transformPoolParameters = poolParameters => {
|
|
26434
|
+
if (!poolParameters) {
|
|
26435
|
+
return {
|
|
26436
|
+
poolParameters: undefined,
|
|
26437
|
+
poolOwners: [],
|
|
26438
|
+
poolRelays: []
|
|
26439
|
+
};
|
|
26440
|
+
}
|
|
26441
|
+
|
|
26442
|
+
validatePoolParameters(poolParameters);
|
|
26443
|
+
return {
|
|
26444
|
+
poolParameters: {
|
|
26445
|
+
pool_id: poolParameters.poolId,
|
|
26446
|
+
vrf_key_hash: poolParameters.vrfKeyHash,
|
|
26447
|
+
pledge: poolParameters.pledge,
|
|
26448
|
+
cost: poolParameters.cost,
|
|
26449
|
+
margin_numerator: poolParameters.margin.numerator,
|
|
26450
|
+
margin_denominator: poolParameters.margin.denominator,
|
|
26451
|
+
reward_account: poolParameters.rewardAccount,
|
|
26452
|
+
metadata: poolParameters.metadata,
|
|
26453
|
+
owners_count: poolParameters.owners.length,
|
|
26454
|
+
relays_count: poolParameters.relays.length
|
|
26455
|
+
},
|
|
26456
|
+
poolOwners: poolParameters.owners.map(owner => ({
|
|
26457
|
+
staking_key_hash: owner.stakingKeyHash,
|
|
26458
|
+
staking_key_path: owner.stakingKeyPath ? validatePath(owner.stakingKeyPath, 5) : undefined
|
|
26459
|
+
})),
|
|
26460
|
+
poolRelays: poolParameters.relays.map(relay => ({
|
|
26461
|
+
type: relay.type,
|
|
26462
|
+
ipv4_address: relay.ipv4Address ? ipv4AddressToHex(relay.ipv4Address) : undefined,
|
|
26463
|
+
ipv6_address: relay.ipv6Address ? ipv6AddressToHex(relay.ipv6Address) : undefined,
|
|
26464
|
+
host_name: relay.hostName,
|
|
26465
|
+
port: relay.port
|
|
26466
|
+
}))
|
|
26467
|
+
};
|
|
26468
|
+
};
|
|
26469
|
+
|
|
26470
|
+
const transformCertificate = certificate => {
|
|
26471
|
+
const paramsToValidate = [{
|
|
26472
|
+
name: 'type',
|
|
26473
|
+
type: 'number',
|
|
26474
|
+
required: true
|
|
26475
|
+
}];
|
|
26476
|
+
|
|
26477
|
+
if (certificate.type !== hdTransport.Messages.CardanoCertificateType.STAKE_POOL_REGISTRATION) {
|
|
26478
|
+
paramsToValidate.push({
|
|
26479
|
+
name: 'scriptHash',
|
|
26480
|
+
type: 'string'
|
|
26481
|
+
});
|
|
26482
|
+
paramsToValidate.push({
|
|
26483
|
+
name: 'keyHash',
|
|
26484
|
+
type: 'string'
|
|
26485
|
+
});
|
|
26486
|
+
}
|
|
26487
|
+
|
|
26488
|
+
if (certificate.type === hdTransport.Messages.CardanoCertificateType.STAKE_DELEGATION) {
|
|
26489
|
+
paramsToValidate.push({
|
|
26490
|
+
name: 'pool',
|
|
26491
|
+
type: 'string',
|
|
26492
|
+
required: true
|
|
26493
|
+
});
|
|
26494
|
+
}
|
|
26495
|
+
|
|
26496
|
+
if (certificate.type === hdTransport.Messages.CardanoCertificateType.STAKE_POOL_REGISTRATION) {
|
|
26497
|
+
paramsToValidate.push({
|
|
26498
|
+
name: 'poolParameters',
|
|
26499
|
+
type: 'object',
|
|
26500
|
+
required: true
|
|
26501
|
+
});
|
|
26502
|
+
}
|
|
26503
|
+
|
|
26504
|
+
validateParams(certificate, paramsToValidate);
|
|
26505
|
+
const {
|
|
26506
|
+
poolParameters,
|
|
26507
|
+
poolOwners,
|
|
26508
|
+
poolRelays
|
|
26509
|
+
} = transformPoolParameters(certificate.poolParameters);
|
|
26510
|
+
return {
|
|
26511
|
+
certificate: {
|
|
26512
|
+
type: certificate.type,
|
|
26513
|
+
path: certificate.path ? validatePath(certificate.path, 5) : undefined,
|
|
26514
|
+
script_hash: certificate.scriptHash,
|
|
26515
|
+
key_hash: certificate.keyHash,
|
|
26516
|
+
pool: certificate.pool,
|
|
26517
|
+
pool_parameters: poolParameters
|
|
26518
|
+
},
|
|
26519
|
+
poolOwners,
|
|
26520
|
+
poolRelays
|
|
26521
|
+
};
|
|
26522
|
+
};
|
|
26523
|
+
|
|
26524
|
+
const transformCatalystRegistrationParameters = catalystRegistrationParameters => {
|
|
26525
|
+
validateParams(catalystRegistrationParameters, [{
|
|
26526
|
+
name: 'votingPublicKey',
|
|
26527
|
+
type: 'string',
|
|
26528
|
+
required: true
|
|
26529
|
+
}, {
|
|
26530
|
+
name: 'stakingPath',
|
|
26531
|
+
required: true
|
|
26532
|
+
}, {
|
|
26533
|
+
name: 'nonce',
|
|
26534
|
+
type: 'uint',
|
|
26535
|
+
required: true
|
|
26536
|
+
}]);
|
|
26537
|
+
validateAddressParameters(catalystRegistrationParameters.rewardAddressParameters);
|
|
26538
|
+
return {
|
|
26539
|
+
voting_public_key: catalystRegistrationParameters.votingPublicKey,
|
|
26540
|
+
staking_path: validatePath(catalystRegistrationParameters.stakingPath, 3),
|
|
26541
|
+
reward_address_parameters: addressParametersToProto(catalystRegistrationParameters.rewardAddressParameters),
|
|
26542
|
+
nonce: catalystRegistrationParameters.nonce
|
|
26543
|
+
};
|
|
26544
|
+
};
|
|
26545
|
+
|
|
26546
|
+
const transformAuxiliaryData = auxiliaryData => {
|
|
26547
|
+
validateParams(auxiliaryData, [{
|
|
26548
|
+
name: 'hash',
|
|
26549
|
+
type: 'string'
|
|
26550
|
+
}]);
|
|
26551
|
+
let catalystRegistrationParameters;
|
|
26552
|
+
|
|
26553
|
+
if (auxiliaryData.catalystRegistrationParameters) {
|
|
26554
|
+
catalystRegistrationParameters = transformCatalystRegistrationParameters(auxiliaryData.catalystRegistrationParameters);
|
|
26555
|
+
}
|
|
26556
|
+
|
|
26557
|
+
return {
|
|
26558
|
+
hash: auxiliaryData.hash,
|
|
26559
|
+
catalyst_registration_parameters: catalystRegistrationParameters
|
|
26560
|
+
};
|
|
26561
|
+
};
|
|
26562
|
+
|
|
26563
|
+
const modifyAuxiliaryDataForBackwardsCompatibility = auxiliary_data => {
|
|
26564
|
+
const {
|
|
26565
|
+
catalyst_registration_parameters
|
|
26566
|
+
} = auxiliary_data;
|
|
26567
|
+
|
|
26568
|
+
if (catalyst_registration_parameters) {
|
|
26569
|
+
catalyst_registration_parameters.reward_address_parameters = modifyAddressParametersForBackwardsCompatibility(catalyst_registration_parameters.reward_address_parameters);
|
|
26570
|
+
return Object.assign(Object.assign({}, auxiliary_data), {
|
|
26571
|
+
catalyst_registration_parameters
|
|
26572
|
+
});
|
|
26573
|
+
}
|
|
26574
|
+
|
|
26575
|
+
return auxiliary_data;
|
|
26576
|
+
};
|
|
26577
|
+
|
|
26578
|
+
const gatherWitnessPaths = (inputsWithPath, certificatesWithPoolOwnersAndRelays, withdrawals, collateralInputsWithPath, requiredSigners, additionalWitnessRequests, signingMode) => {
|
|
26579
|
+
const witnessPaths = new Map();
|
|
26580
|
+
|
|
26581
|
+
function _insert(path) {
|
|
26582
|
+
const pathKey = JSON.stringify(path);
|
|
26583
|
+
witnessPaths.set(pathKey, path);
|
|
26584
|
+
}
|
|
26585
|
+
|
|
26586
|
+
if (signingMode !== hdTransport.Messages.CardanoTxSigningMode.MULTISIG_TRANSACTION) {
|
|
26587
|
+
inputsWithPath.forEach(({
|
|
26588
|
+
path
|
|
26589
|
+
}) => {
|
|
26590
|
+
if (path) _insert(path);
|
|
26591
|
+
});
|
|
26592
|
+
certificatesWithPoolOwnersAndRelays.forEach(({
|
|
26593
|
+
certificate,
|
|
26594
|
+
poolOwners
|
|
26595
|
+
}) => {
|
|
26596
|
+
if (certificate.path && (certificate.type === hdTransport.Messages.CardanoCertificateType.STAKE_DELEGATION || certificate.type === hdTransport.Messages.CardanoCertificateType.STAKE_DEREGISTRATION)) {
|
|
26597
|
+
_insert(certificate.path);
|
|
26598
|
+
}
|
|
26599
|
+
|
|
26600
|
+
poolOwners.forEach(poolOwner => {
|
|
26601
|
+
if (poolOwner.staking_key_path) _insert(poolOwner.staking_key_path);
|
|
26602
|
+
});
|
|
26603
|
+
});
|
|
26604
|
+
withdrawals.forEach(({
|
|
26605
|
+
path
|
|
26606
|
+
}) => {
|
|
26607
|
+
if (path) _insert(path);
|
|
26608
|
+
});
|
|
26609
|
+
}
|
|
26610
|
+
|
|
26611
|
+
if (signingMode === hdTransport.Messages.CardanoTxSigningMode.PLUTUS_TRANSACTION) {
|
|
26612
|
+
collateralInputsWithPath.forEach(({
|
|
26613
|
+
path
|
|
26614
|
+
}) => {
|
|
26615
|
+
if (path) _insert(path);
|
|
26616
|
+
});
|
|
26617
|
+
}
|
|
26618
|
+
|
|
26619
|
+
requiredSigners.forEach(({
|
|
26620
|
+
key_path
|
|
26621
|
+
}) => {
|
|
26622
|
+
if (key_path) _insert(key_path);
|
|
26623
|
+
});
|
|
26624
|
+
additionalWitnessRequests.forEach(path => {
|
|
26625
|
+
_insert(path);
|
|
26626
|
+
});
|
|
26627
|
+
return Array.from(witnessPaths.values());
|
|
26628
|
+
};
|
|
26629
|
+
|
|
26630
|
+
class CardanoSignTransaction extends BaseMethod {
|
|
26631
|
+
init() {
|
|
26632
|
+
var _a;
|
|
26633
|
+
|
|
26634
|
+
this.checkDeviceId = true;
|
|
26635
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
26636
|
+
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
26637
|
+
const {
|
|
26638
|
+
payload
|
|
26639
|
+
} = this;
|
|
26640
|
+
validateParams(payload, [{
|
|
26641
|
+
name: 'signingMode',
|
|
26642
|
+
type: 'number',
|
|
26643
|
+
required: true
|
|
26644
|
+
}, {
|
|
26645
|
+
name: 'inputs',
|
|
26646
|
+
type: 'array',
|
|
26647
|
+
required: true
|
|
26648
|
+
}, {
|
|
26649
|
+
name: 'outputs',
|
|
26650
|
+
type: 'array',
|
|
26651
|
+
required: true,
|
|
26652
|
+
allowEmpty: true
|
|
26653
|
+
}, {
|
|
26654
|
+
name: 'fee',
|
|
26655
|
+
type: 'uint',
|
|
26656
|
+
required: true
|
|
26657
|
+
}, {
|
|
26658
|
+
name: 'ttl',
|
|
26659
|
+
type: 'uint'
|
|
26660
|
+
}, {
|
|
26661
|
+
name: 'certificates',
|
|
26662
|
+
type: 'array',
|
|
26663
|
+
allowEmpty: true
|
|
26664
|
+
}, {
|
|
26665
|
+
name: 'withdrawals',
|
|
26666
|
+
type: 'array',
|
|
26667
|
+
allowEmpty: true
|
|
26668
|
+
}, {
|
|
26669
|
+
name: 'mint',
|
|
26670
|
+
type: 'array',
|
|
26671
|
+
allowEmpty: true
|
|
26672
|
+
}, {
|
|
26673
|
+
name: 'validityIntervalStart',
|
|
26674
|
+
type: 'uint'
|
|
26675
|
+
}, {
|
|
26676
|
+
name: 'scriptDataHash',
|
|
26677
|
+
type: 'string'
|
|
26678
|
+
}, {
|
|
26679
|
+
name: 'collateralInputs',
|
|
26680
|
+
type: 'array',
|
|
26681
|
+
allowEmpty: true
|
|
26682
|
+
}, {
|
|
26683
|
+
name: 'requiredSigners',
|
|
26684
|
+
type: 'array',
|
|
26685
|
+
allowEmpty: true
|
|
26686
|
+
}, {
|
|
26687
|
+
name: 'totalCollateral',
|
|
26688
|
+
type: 'uint'
|
|
26689
|
+
}, {
|
|
26690
|
+
name: 'referenceInputs',
|
|
26691
|
+
type: 'array',
|
|
26692
|
+
allowEmpty: true
|
|
26693
|
+
}, {
|
|
26694
|
+
name: 'protocolMagic',
|
|
26695
|
+
type: 'number',
|
|
26696
|
+
required: true
|
|
26697
|
+
}, {
|
|
26698
|
+
name: 'networkId',
|
|
26699
|
+
type: 'number',
|
|
26700
|
+
required: true
|
|
26701
|
+
}, {
|
|
26702
|
+
name: 'additionalWitnessRequests',
|
|
26703
|
+
type: 'array',
|
|
26704
|
+
allowEmpty: true
|
|
26705
|
+
}, {
|
|
26706
|
+
name: 'derivationType',
|
|
26707
|
+
type: 'number'
|
|
26708
|
+
}, {
|
|
26709
|
+
name: 'includeNetworkId',
|
|
26710
|
+
type: 'boolean'
|
|
26711
|
+
}]);
|
|
26712
|
+
const inputsWithPath = payload.inputs.map(transformInput);
|
|
26713
|
+
const outputsWithData = payload.outputs.map(transformOutput);
|
|
26714
|
+
let certificatesWithPoolOwnersAndRelays = [];
|
|
26715
|
+
|
|
26716
|
+
if (payload.certificates) {
|
|
26717
|
+
certificatesWithPoolOwnersAndRelays = payload.certificates.map(transformCertificate);
|
|
26718
|
+
}
|
|
26719
|
+
|
|
26720
|
+
let withdrawals = [];
|
|
26721
|
+
|
|
26722
|
+
if (payload.withdrawals) {
|
|
26723
|
+
withdrawals = payload.withdrawals.map(withdrawal => {
|
|
26724
|
+
validateParams(withdrawal, [{
|
|
26725
|
+
name: 'amount',
|
|
26726
|
+
type: 'uint',
|
|
26727
|
+
required: true
|
|
26728
|
+
}, {
|
|
26729
|
+
name: 'scriptHash',
|
|
26730
|
+
type: 'string'
|
|
26731
|
+
}, {
|
|
26732
|
+
name: 'keyHash',
|
|
26733
|
+
type: 'string'
|
|
26734
|
+
}]);
|
|
26735
|
+
return {
|
|
26736
|
+
path: withdrawal.path ? validatePath(withdrawal.path, 5) : undefined,
|
|
26737
|
+
amount: withdrawal.amount,
|
|
26738
|
+
script_hash: withdrawal.scriptHash,
|
|
26739
|
+
key_hash: withdrawal.keyHash
|
|
26740
|
+
};
|
|
26741
|
+
});
|
|
26742
|
+
}
|
|
26743
|
+
|
|
26744
|
+
let mint = [];
|
|
26745
|
+
|
|
26746
|
+
if (payload.mint) {
|
|
26747
|
+
mint = tokenBundleToProto(payload.mint);
|
|
26748
|
+
}
|
|
26749
|
+
|
|
26750
|
+
let auxiliaryData;
|
|
26751
|
+
|
|
26752
|
+
if (payload.auxiliaryData) {
|
|
26753
|
+
auxiliaryData = transformAuxiliaryData(payload.auxiliaryData);
|
|
26754
|
+
}
|
|
26755
|
+
|
|
26756
|
+
let additionalWitnessRequests = [];
|
|
26757
|
+
|
|
26758
|
+
if (payload.additionalWitnessRequests) {
|
|
26759
|
+
additionalWitnessRequests = payload.additionalWitnessRequests.map(witnessRequest => validatePath(witnessRequest, 3));
|
|
26760
|
+
}
|
|
26761
|
+
|
|
26762
|
+
let collateralInputsWithPath = [];
|
|
26763
|
+
|
|
26764
|
+
if (payload.collateralInputs) {
|
|
26765
|
+
collateralInputsWithPath = payload.collateralInputs.map(transformCollateralInput);
|
|
26766
|
+
}
|
|
26767
|
+
|
|
26768
|
+
let requiredSigners = [];
|
|
26769
|
+
|
|
26770
|
+
if (payload.requiredSigners) {
|
|
26771
|
+
requiredSigners = payload.requiredSigners.map(requiredSigner => {
|
|
26772
|
+
validateParams(requiredSigner, [{
|
|
26773
|
+
name: 'keyHash',
|
|
26774
|
+
type: 'string'
|
|
26775
|
+
}]);
|
|
26776
|
+
return {
|
|
26777
|
+
key_path: requiredSigner.keyPath ? validatePath(requiredSigner.keyPath, 3) : undefined,
|
|
26778
|
+
key_hash: requiredSigner.keyHash
|
|
26779
|
+
};
|
|
26780
|
+
});
|
|
26781
|
+
}
|
|
26782
|
+
|
|
26783
|
+
const collateralReturnWithData = payload.collateralReturn ? transformOutput(payload.collateralReturn) : undefined;
|
|
26784
|
+
let referenceInputs = [];
|
|
26785
|
+
|
|
26786
|
+
if (payload.referenceInputs) {
|
|
26787
|
+
referenceInputs = payload.referenceInputs.map(transformReferenceInput);
|
|
26788
|
+
}
|
|
26789
|
+
|
|
26790
|
+
this.params = {
|
|
26791
|
+
signingMode: payload.signingMode,
|
|
26792
|
+
inputsWithPath,
|
|
26793
|
+
outputsWithData,
|
|
26794
|
+
fee: payload.fee,
|
|
26795
|
+
ttl: payload.ttl,
|
|
26796
|
+
certificatesWithPoolOwnersAndRelays,
|
|
26797
|
+
withdrawals,
|
|
26798
|
+
mint,
|
|
26799
|
+
auxiliaryData,
|
|
26800
|
+
validityIntervalStart: payload.validityIntervalStart,
|
|
26801
|
+
scriptDataHash: payload.scriptDataHash,
|
|
26802
|
+
collateralInputsWithPath,
|
|
26803
|
+
requiredSigners,
|
|
26804
|
+
collateralReturnWithData,
|
|
26805
|
+
totalCollateral: payload.totalCollateral,
|
|
26806
|
+
referenceInputs,
|
|
26807
|
+
protocolMagic: payload.protocolMagic,
|
|
26808
|
+
networkId: payload.networkId,
|
|
26809
|
+
witnessPaths: gatherWitnessPaths(inputsWithPath, certificatesWithPoolOwnersAndRelays, withdrawals, collateralInputsWithPath, requiredSigners, additionalWitnessRequests, payload.signingMode),
|
|
26810
|
+
additionalWitnessRequests,
|
|
26811
|
+
derivationType: typeof payload.derivationType !== 'undefined' ? payload.derivationType : hdTransport.Messages.CardanoDerivationType.ICARUS_TREZOR,
|
|
26812
|
+
includeNetworkId: payload.includeNetworkId
|
|
26813
|
+
};
|
|
26814
|
+
}
|
|
26815
|
+
|
|
26816
|
+
signTx() {
|
|
26817
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26818
|
+
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
26819
|
+
const hasAuxiliaryData = !!this.params.auxiliaryData;
|
|
26820
|
+
const signTxInitMessage = {
|
|
26821
|
+
signing_mode: this.params.signingMode,
|
|
26822
|
+
protocol_magic: this.params.protocolMagic,
|
|
26823
|
+
network_id: this.params.networkId,
|
|
26824
|
+
inputs_count: this.params.inputsWithPath.length,
|
|
26825
|
+
outputs_count: this.params.outputsWithData.length,
|
|
26826
|
+
fee: this.params.fee,
|
|
26827
|
+
ttl: this.params.ttl,
|
|
26828
|
+
certificates_count: this.params.certificatesWithPoolOwnersAndRelays.length,
|
|
26829
|
+
withdrawals_count: this.params.withdrawals.length,
|
|
26830
|
+
has_auxiliary_data: hasAuxiliaryData,
|
|
26831
|
+
validity_interval_start: this.params.validityIntervalStart,
|
|
26832
|
+
witness_requests_count: this.params.witnessPaths.length,
|
|
26833
|
+
minting_asset_groups_count: this.params.mint.length,
|
|
26834
|
+
script_data_hash: this.params.scriptDataHash,
|
|
26835
|
+
collateral_inputs_count: this.params.collateralInputsWithPath.length,
|
|
26836
|
+
required_signers_count: this.params.requiredSigners.length,
|
|
26837
|
+
has_collateral_return: this.params.collateralReturnWithData != null,
|
|
26838
|
+
total_collateral: this.params.totalCollateral,
|
|
26839
|
+
reference_inputs_count: this.params.referenceInputs.length,
|
|
26840
|
+
derivation_type: this.params.derivationType,
|
|
26841
|
+
include_network_id: this.params.includeNetworkId
|
|
26842
|
+
};
|
|
26843
|
+
yield typedCall('CardanoSignTxInit', 'CardanoTxItemAck', signTxInitMessage);
|
|
26844
|
+
|
|
26845
|
+
for (const {
|
|
26846
|
+
input
|
|
26847
|
+
} of this.params.inputsWithPath) {
|
|
26848
|
+
yield typedCall('CardanoTxInput', 'CardanoTxItemAck', input);
|
|
26849
|
+
}
|
|
26850
|
+
|
|
26851
|
+
for (const outputWithData of this.params.outputsWithData) {
|
|
26852
|
+
yield sendOutput(typedCall, outputWithData);
|
|
26853
|
+
}
|
|
26854
|
+
|
|
26855
|
+
for (const {
|
|
26856
|
+
certificate,
|
|
26857
|
+
poolOwners,
|
|
26858
|
+
poolRelays
|
|
26859
|
+
} of this.params.certificatesWithPoolOwnersAndRelays) {
|
|
26860
|
+
yield typedCall('CardanoTxCertificate', 'CardanoTxItemAck', certificate);
|
|
26861
|
+
|
|
26862
|
+
for (const poolOwner of poolOwners) {
|
|
26863
|
+
yield typedCall('CardanoPoolOwner', 'CardanoTxItemAck', poolOwner);
|
|
26864
|
+
}
|
|
26865
|
+
|
|
26866
|
+
for (const poolRelay of poolRelays) {
|
|
26867
|
+
yield typedCall('CardanoPoolRelayParameters', 'CardanoTxItemAck', poolRelay);
|
|
26868
|
+
}
|
|
26869
|
+
}
|
|
26870
|
+
|
|
26871
|
+
for (const withdrawal of this.params.withdrawals) {
|
|
26872
|
+
yield typedCall('CardanoTxWithdrawal', 'CardanoTxItemAck', withdrawal);
|
|
26873
|
+
}
|
|
26874
|
+
|
|
26875
|
+
let auxiliaryDataSupplement;
|
|
26876
|
+
|
|
26877
|
+
if (this.params.auxiliaryData) {
|
|
26878
|
+
const {
|
|
26879
|
+
catalyst_registration_parameters
|
|
26880
|
+
} = this.params.auxiliaryData;
|
|
26881
|
+
|
|
26882
|
+
if (catalyst_registration_parameters) {
|
|
26883
|
+
this.params.auxiliaryData = modifyAuxiliaryDataForBackwardsCompatibility(this.params.auxiliaryData);
|
|
26884
|
+
}
|
|
26885
|
+
|
|
26886
|
+
const {
|
|
26887
|
+
message
|
|
26888
|
+
} = yield typedCall('CardanoTxAuxiliaryData', 'CardanoTxAuxiliaryDataSupplement', this.params.auxiliaryData);
|
|
26889
|
+
const auxiliaryDataType = hdTransport.Messages.CardanoTxAuxiliaryDataSupplementType[message.type];
|
|
26890
|
+
|
|
26891
|
+
if (auxiliaryDataType !== hdTransport.Messages.CardanoTxAuxiliaryDataSupplementType.NONE) {
|
|
26892
|
+
auxiliaryDataSupplement = {
|
|
26893
|
+
type: auxiliaryDataType,
|
|
26894
|
+
auxiliaryDataHash: message.auxiliary_data_hash,
|
|
26895
|
+
catalystSignature: message.catalyst_signature
|
|
26896
|
+
};
|
|
26897
|
+
}
|
|
26898
|
+
|
|
26899
|
+
yield typedCall('CardanoTxHostAck', 'CardanoTxItemAck');
|
|
26900
|
+
}
|
|
26901
|
+
|
|
26902
|
+
if (this.params.mint.length > 0) {
|
|
26903
|
+
yield typedCall('CardanoTxMint', 'CardanoTxItemAck', {
|
|
26904
|
+
asset_groups_count: this.params.mint.length
|
|
26905
|
+
});
|
|
26906
|
+
|
|
26907
|
+
for (const assetGroup of this.params.mint) {
|
|
26908
|
+
yield typedCall('CardanoAssetGroup', 'CardanoTxItemAck', {
|
|
26909
|
+
policy_id: assetGroup.policyId,
|
|
26910
|
+
tokens_count: assetGroup.tokens.length
|
|
26911
|
+
});
|
|
26912
|
+
|
|
26913
|
+
for (const token of assetGroup.tokens) {
|
|
26914
|
+
yield typedCall('CardanoToken', 'CardanoTxItemAck', token);
|
|
26915
|
+
}
|
|
26916
|
+
}
|
|
26917
|
+
}
|
|
26918
|
+
|
|
26919
|
+
for (const {
|
|
26920
|
+
collateralInput
|
|
26921
|
+
} of this.params.collateralInputsWithPath) {
|
|
26922
|
+
yield typedCall('CardanoTxCollateralInput', 'CardanoTxItemAck', collateralInput);
|
|
26923
|
+
}
|
|
26924
|
+
|
|
26925
|
+
for (const requiredSigner of this.params.requiredSigners) {
|
|
26926
|
+
yield typedCall('CardanoTxRequiredSigner', 'CardanoTxItemAck', requiredSigner);
|
|
26927
|
+
}
|
|
26928
|
+
|
|
26929
|
+
if (this.params.collateralReturnWithData) {
|
|
26930
|
+
yield sendOutput(typedCall, this.params.collateralReturnWithData);
|
|
26931
|
+
}
|
|
26932
|
+
|
|
26933
|
+
for (const referenceInput of this.params.referenceInputs) {
|
|
26934
|
+
yield typedCall('CardanoTxReferenceInput', 'CardanoTxItemAck', referenceInput);
|
|
26935
|
+
}
|
|
26936
|
+
|
|
26937
|
+
const witnesses = [];
|
|
26938
|
+
|
|
26939
|
+
for (const path of this.params.witnessPaths) {
|
|
26940
|
+
const {
|
|
26941
|
+
message
|
|
26942
|
+
} = yield typedCall('CardanoTxWitnessRequest', 'CardanoTxWitnessResponse', {
|
|
26943
|
+
path
|
|
26944
|
+
});
|
|
26945
|
+
witnesses.push({
|
|
26946
|
+
type: hdTransport.Messages.CardanoTxWitnessType[message.type],
|
|
26947
|
+
pubKey: message.pub_key,
|
|
26948
|
+
signature: message.signature,
|
|
26949
|
+
chainCode: message.chain_code
|
|
26950
|
+
});
|
|
26951
|
+
}
|
|
26952
|
+
|
|
26953
|
+
const {
|
|
26954
|
+
message: txBodyHashMessage
|
|
26955
|
+
} = yield typedCall('CardanoTxHostAck', 'CardanoTxBodyHash');
|
|
26956
|
+
yield typedCall('CardanoTxHostAck', 'CardanoSignTxFinished');
|
|
26957
|
+
return {
|
|
26958
|
+
hash: txBodyHashMessage.tx_hash,
|
|
26959
|
+
witnesses,
|
|
26960
|
+
auxiliaryDataSupplement
|
|
26961
|
+
};
|
|
26962
|
+
});
|
|
26963
|
+
}
|
|
26964
|
+
|
|
26965
|
+
run() {
|
|
26966
|
+
return this.signTx();
|
|
26967
|
+
}
|
|
26968
|
+
|
|
26969
|
+
}
|
|
26970
|
+
|
|
25406
26971
|
var ApiMethods = /*#__PURE__*/Object.freeze({
|
|
25407
26972
|
__proto__: null,
|
|
25408
26973
|
searchDevices: SearchDevices,
|
|
@@ -25472,7 +27037,13 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
|
|
|
25472
27037
|
cosmosGetPublicKey: CosmosGetPublicKey,
|
|
25473
27038
|
cosmosSignTransaction: CosmosSignTransaction,
|
|
25474
27039
|
xrpGetAddress: XrpGetAddress$1,
|
|
25475
|
-
xrpSignTransaction: XrpGetAddress
|
|
27040
|
+
xrpSignTransaction: XrpGetAddress,
|
|
27041
|
+
suiGetAddress: SuiGetAddress,
|
|
27042
|
+
suiGetPublicKey: SuiGetPublicKey,
|
|
27043
|
+
suiSignTransaction: SuiSignTransaction,
|
|
27044
|
+
cardanoGetAddress: CardanoGetAddress,
|
|
27045
|
+
cardanoGetPublicKey: CardanoGetPublicKey,
|
|
27046
|
+
cardanoSignTransaction: CardanoSignTransaction
|
|
25476
27047
|
});
|
|
25477
27048
|
|
|
25478
27049
|
function findMethod(message) {
|
|
@@ -25493,18 +27064,6 @@ function findMethod(message) {
|
|
|
25493
27064
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Method ${method} is not set`);
|
|
25494
27065
|
}
|
|
25495
27066
|
|
|
25496
|
-
const safeThrowError = error => {
|
|
25497
|
-
if (error instanceof hdShared.HardwareError) {
|
|
25498
|
-
throw error;
|
|
25499
|
-
} else if (error.code === 'ERR_NETWORK') {
|
|
25500
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeNotInstalled);
|
|
25501
|
-
} else if (error.code === 'ECONNABORTED') {
|
|
25502
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError);
|
|
25503
|
-
} else {
|
|
25504
|
-
throw hdShared.ERRORS.TypedError(error);
|
|
25505
|
-
}
|
|
25506
|
-
};
|
|
25507
|
-
|
|
25508
27067
|
const resolveAfter = (msec, value) => new Promise(resolve => {
|
|
25509
27068
|
setTimeout(resolve, msec, value);
|
|
25510
27069
|
});
|
|
@@ -25624,7 +27183,8 @@ const Log = getLogger(exports.d0.Core);
|
|
|
25624
27183
|
const parseInitOptions = method => ({
|
|
25625
27184
|
initSession: method === null || method === void 0 ? void 0 : method.payload.initSession,
|
|
25626
27185
|
passphraseState: method === null || method === void 0 ? void 0 : method.payload.passphraseState,
|
|
25627
|
-
deviceId: method === null || method === void 0 ? void 0 : method.payload.deviceId
|
|
27186
|
+
deviceId: method === null || method === void 0 ? void 0 : method.payload.deviceId,
|
|
27187
|
+
deriveCardano: method === null || method === void 0 ? void 0 : method.name.startsWith('cardano')
|
|
25628
27188
|
});
|
|
25629
27189
|
|
|
25630
27190
|
let _core;
|
|
@@ -71843,7 +73403,7 @@ module.exports = {"i8":"6.5.4"};
|
|
|
71843
73403
|
/***/ ((module) => {
|
|
71844
73404
|
|
|
71845
73405
|
"use strict";
|
|
71846
|
-
module.exports = JSON.parse('{"name":"@onekeyfe/hd-core","version":"0.2.
|
|
73406
|
+
module.exports = JSON.parse('{"name":"@onekeyfe/hd-core","version":"0.2.9","description":"> TODO: description","author":"OneKey","homepage":"https://github.com/OneKeyHQ/hardware-js-sdk#readme","license":"ISC","main":"dist/index.js","types":"dist/index.d.ts","repository":{"type":"git","url":"git+https://github.com/OneKeyHQ/hardware-js-sdk.git"},"publishConfig":{"access":"public"},"scripts":{"dev":"rimraf dist && rollup -c ../../build/rollup.config.js -w","build":"rimraf dist && rollup -c ../../build/rollup.config.js","lint":"eslint .","lint:fix":"eslint . --fix"},"bugs":{"url":"https://github.com/OneKeyHQ/hardware-js-sdk/issues"},"dependencies":{"@onekeyfe/hd-shared":"^0.2.9","@onekeyfe/hd-transport":"^0.2.9","axios":"^0.27.2","bignumber.js":"^9.0.2","jszip":"^3.10.1","parse-uri":"^1.0.7","semver":"^7.3.7"},"peerDependencies":{"@noble/hashes":"^1.1.3","ripple-keypairs":"^1.1.4"},"devDependencies":{"@noble/hashes":"^1.1.3","@types/parse-uri":"^1.0.0","@types/semver":"^7.3.9","ripple-keypairs":"^1.1.4"}}');
|
|
71847
73407
|
|
|
71848
73408
|
/***/ })
|
|
71849
73409
|
|
|
@@ -74382,7 +75942,7 @@ const src_init = async settings => {
|
|
|
74382
75942
|
|
|
74383
75943
|
try {
|
|
74384
75944
|
await init({ ..._settings,
|
|
74385
|
-
version: "0.2.
|
|
75945
|
+
version: "0.2.9"
|
|
74386
75946
|
});
|
|
74387
75947
|
return true;
|
|
74388
75948
|
} catch (e) {
|