@onekeyfe/hd-core 0.2.8 → 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/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/cardano/CardanoGetAddress.d.ts +8 -0
- package/dist/api/cardano/CardanoGetAddress.d.ts.map +1 -0
- package/dist/api/cardano/CardanoGetPublicKey.d.ts +8 -0
- package/dist/api/cardano/CardanoGetPublicKey.d.ts.map +1 -0
- package/dist/api/cardano/CardanoSignTransaction.d.ts +9 -0
- package/dist/api/cardano/CardanoSignTransaction.d.ts.map +1 -0
- package/dist/api/cardano/helper/addressParameters.d.ts +7 -0
- package/dist/api/cardano/helper/addressParameters.d.ts.map +1 -0
- package/dist/api/cardano/helper/auxiliaryData.d.ts +5 -0
- package/dist/api/cardano/helper/auxiliaryData.d.ts.map +1 -0
- package/dist/api/cardano/helper/cardanoInputs.d.ts +14 -0
- package/dist/api/cardano/helper/cardanoInputs.d.ts.map +1 -0
- package/dist/api/cardano/helper/cardanoOutputs.d.ts +11 -0
- package/dist/api/cardano/helper/cardanoOutputs.d.ts.map +1 -0
- package/dist/api/cardano/helper/certificate.d.ts +9 -0
- package/dist/api/cardano/helper/certificate.d.ts.map +1 -0
- package/dist/api/cardano/helper/token.d.ts +3 -0
- package/dist/api/cardano/helper/token.d.ts.map +1 -0
- package/dist/api/cardano/helper/utils.d.ts +3 -0
- package/dist/api/cardano/helper/utils.d.ts.map +1 -0
- package/dist/api/cardano/helper/witnesses.d.ts +5 -0
- package/dist/api/cardano/helper/witnesses.d.ts.map +1 -0
- package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
- package/dist/api/helpers/paramsValidator.d.ts +2 -1
- package/dist/api/helpers/paramsValidator.d.ts.map +1 -1
- package/dist/api/index.d.ts +3 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts +1 -0
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/index.d.ts +192 -0
- package/dist/index.js +850 -18
- package/dist/inject.d.ts.map +1 -1
- package/dist/types/api/cardano.d.ts +158 -0
- package/dist/types/api/cardano.d.ts.map +1 -0
- package/dist/types/api/cardanoGetAddress.d.ts +33 -0
- package/dist/types/api/cardanoGetAddress.d.ts.map +1 -0
- package/dist/types/api/cardanoGetPublicKey.d.ts +23 -0
- package/dist/types/api/cardanoGetPublicKey.d.ts.map +1 -0
- package/dist/types/api/cardanoSignTransaction.d.ts +4 -0
- package/dist/types/api/cardanoSignTransaction.d.ts.map +1 -0
- package/dist/types/api/index.d.ts +6 -0
- package/dist/types/api/index.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +7 -1
- package/src/api/btc/helpers/signtxLegacy.ts +1 -1
- package/src/api/cardano/CardanoGetAddress.ts +87 -0
- package/src/api/cardano/CardanoGetPublicKey.ts +55 -0
- package/src/api/cardano/CardanoSignTransaction.ts +309 -0
- package/src/api/cardano/helper/addressParameters.ts +118 -0
- package/src/api/cardano/helper/auxiliaryData.ts +74 -0
- package/src/api/cardano/helper/cardanoInputs.ts +56 -0
- package/src/api/cardano/helper/cardanoOutputs.ts +89 -0
- package/src/api/cardano/helper/certificate.ts +199 -0
- package/src/api/cardano/helper/token.ts +43 -0
- package/src/api/cardano/helper/utils.ts +17 -0
- package/src/api/cardano/helper/witnesses.ts +63 -0
- package/src/api/firmware/uploadFirmware.ts +1 -3
- package/src/api/helpers/paramsValidator.ts +19 -1
- package/src/api/index.ts +4 -0
- package/src/core/index.ts +1 -0
- package/src/data/messages/messages.json +107 -68
- package/src/device/Device.ts +5 -0
- package/src/inject.ts +7 -0
- package/src/types/api/cardano.ts +186 -0
- package/src/types/api/cardanoGetAddress.ts +47 -0
- package/src/types/api/cardanoGetPublicKey.ts +33 -0
- package/src/types/api/cardanoSignTransaction.ts +8 -0
- package/src/types/api/index.ts +11 -0
package/dist/index.js
CHANGED
|
@@ -108,6 +108,9 @@ const inject = ({ call, cancel, dispose, eventEmitter, init, uiResponse, }) => {
|
|
|
108
108
|
suiGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'suiGetAddress' })),
|
|
109
109
|
suiGetPublicKey: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'suiGetPublicKey' })),
|
|
110
110
|
suiSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'suiSignTransaction' })),
|
|
111
|
+
cardanoGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'cardanoGetAddress' })),
|
|
112
|
+
cardanoGetPublicKey: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'cardanoGetPublicKey' })),
|
|
113
|
+
cardanoSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), { connectId, deviceId, method: 'cardanoSignTransaction' })),
|
|
111
114
|
};
|
|
112
115
|
return api;
|
|
113
116
|
};
|
|
@@ -2833,6 +2836,45 @@ var nested = {
|
|
|
2833
2836
|
rule: "required",
|
|
2834
2837
|
type: "CardanoDerivationType",
|
|
2835
2838
|
id: 14
|
|
2839
|
+
},
|
|
2840
|
+
include_network_id: {
|
|
2841
|
+
type: "bool",
|
|
2842
|
+
id: 15,
|
|
2843
|
+
options: {
|
|
2844
|
+
"default": false
|
|
2845
|
+
}
|
|
2846
|
+
},
|
|
2847
|
+
script_data_hash: {
|
|
2848
|
+
type: "bytes",
|
|
2849
|
+
id: 16
|
|
2850
|
+
},
|
|
2851
|
+
collateral_inputs_count: {
|
|
2852
|
+
rule: "required",
|
|
2853
|
+
type: "uint32",
|
|
2854
|
+
id: 17
|
|
2855
|
+
},
|
|
2856
|
+
required_signers_count: {
|
|
2857
|
+
rule: "required",
|
|
2858
|
+
type: "uint32",
|
|
2859
|
+
id: 18
|
|
2860
|
+
},
|
|
2861
|
+
has_collateral_return: {
|
|
2862
|
+
type: "bool",
|
|
2863
|
+
id: 19,
|
|
2864
|
+
options: {
|
|
2865
|
+
"default": false
|
|
2866
|
+
}
|
|
2867
|
+
},
|
|
2868
|
+
total_collateral: {
|
|
2869
|
+
type: "uint64",
|
|
2870
|
+
id: 20
|
|
2871
|
+
},
|
|
2872
|
+
reference_inputs_count: {
|
|
2873
|
+
type: "uint32",
|
|
2874
|
+
id: 21,
|
|
2875
|
+
options: {
|
|
2876
|
+
"default": 0
|
|
2877
|
+
}
|
|
2836
2878
|
}
|
|
2837
2879
|
}
|
|
2838
2880
|
},
|
|
@@ -11839,6 +11881,9 @@ class Device extends events.exports {
|
|
|
11839
11881
|
if (internalState) {
|
|
11840
11882
|
payload.session_id = internalState;
|
|
11841
11883
|
}
|
|
11884
|
+
if (options === null || options === void 0 ? void 0 : options.deriveCardano) {
|
|
11885
|
+
payload.derive_cardano = true;
|
|
11886
|
+
}
|
|
11842
11887
|
Log$5.debug('initialize payload:', payload);
|
|
11843
11888
|
const { message } = yield this.commands.typedCall('Initialize', 'Features', payload);
|
|
11844
11889
|
this._updateFeatures(message, options === null || options === void 0 ? void 0 : options.initSession);
|
|
@@ -12135,8 +12180,10 @@ class BaseMethod {
|
|
|
12135
12180
|
if (!this.device || !this.device.features)
|
|
12136
12181
|
return;
|
|
12137
12182
|
const inputPinOnSoftware = supportInputPinOnSoftware(this.device.features);
|
|
12183
|
+
const modifyHomescreen = supportModifyHomescreen(this.device.features);
|
|
12138
12184
|
this.postMessage(createDeviceMessage(DEVICE.SUPPORT_FEATURES, {
|
|
12139
12185
|
inputPinOnSoftware,
|
|
12186
|
+
modifyHomescreen,
|
|
12140
12187
|
device: this.device.toMessageObject(),
|
|
12141
12188
|
}));
|
|
12142
12189
|
}
|
|
@@ -12403,6 +12450,15 @@ const validateParams = (values, fields) => {
|
|
|
12403
12450
|
throw invalidParameter(`Parameter "${field.name}" is empty.`);
|
|
12404
12451
|
}
|
|
12405
12452
|
break;
|
|
12453
|
+
case 'uint':
|
|
12454
|
+
if (typeof value !== 'string' && typeof value !== 'number') {
|
|
12455
|
+
throw invalidParameter(`Parameter [${field.name}] has invalid type. "string|number" expected.`);
|
|
12456
|
+
}
|
|
12457
|
+
if ((typeof value === 'number' && !Number.isSafeInteger(value)) ||
|
|
12458
|
+
!/^(?:[1-9]\d*|\d)$/.test(value.toString().replace(/^-/, field.allowNegative ? '' : '-'))) {
|
|
12459
|
+
throw invalidParameter(`Parameter [${field.name}] has invalid value "${value}". Integer representation expected.`);
|
|
12460
|
+
}
|
|
12461
|
+
break;
|
|
12406
12462
|
case 'bigNumber':
|
|
12407
12463
|
if (typeof value !== 'string') {
|
|
12408
12464
|
throw invalidParameter(`Parameter [${field.name}] is of type invalid and should be [string].`);
|
|
@@ -12791,7 +12847,6 @@ const getInfo = ({ features, updateType }) => {
|
|
|
12791
12847
|
return findLatestRelease(releaseInfo);
|
|
12792
12848
|
};
|
|
12793
12849
|
|
|
12794
|
-
getLogger(exports.LoggerNames.Device);
|
|
12795
12850
|
const postConfirmationMessage = (device) => {
|
|
12796
12851
|
var _a;
|
|
12797
12852
|
if ((_a = device.features) === null || _a === void 0 ? void 0 : _a.firmware_present) {
|
|
@@ -13848,7 +13903,7 @@ const saveTxSignatures = (serializedTx, signatures, txRequest) => {
|
|
|
13848
13903
|
}
|
|
13849
13904
|
if (typeof signature_index === 'number') {
|
|
13850
13905
|
if (!signature) {
|
|
13851
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'saveTxSignatures: Unexpected null in
|
|
13906
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'saveTxSignatures: Unexpected null in oneKey:TxRequestSerialized signature.');
|
|
13852
13907
|
}
|
|
13853
13908
|
signatures[signature_index] = signature;
|
|
13854
13909
|
}
|
|
@@ -16441,6 +16496,794 @@ class SuiSignTransaction extends BaseMethod {
|
|
|
16441
16496
|
}
|
|
16442
16497
|
}
|
|
16443
16498
|
|
|
16499
|
+
const safeThrowError = (error) => {
|
|
16500
|
+
if (error instanceof hdShared.HardwareError) {
|
|
16501
|
+
throw error;
|
|
16502
|
+
}
|
|
16503
|
+
else if (error.code === 'ERR_NETWORK') {
|
|
16504
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeNotInstalled);
|
|
16505
|
+
}
|
|
16506
|
+
else if (error.code === 'ECONNABORTED') {
|
|
16507
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError);
|
|
16508
|
+
}
|
|
16509
|
+
else {
|
|
16510
|
+
throw hdShared.ERRORS.TypedError(error);
|
|
16511
|
+
}
|
|
16512
|
+
};
|
|
16513
|
+
|
|
16514
|
+
const validateAddressParameters = (addressParameters) => {
|
|
16515
|
+
validateParams(addressParameters, [
|
|
16516
|
+
{ name: 'addressType', type: 'number', required: true },
|
|
16517
|
+
{ name: 'stakingKeyHash', type: 'string' },
|
|
16518
|
+
{ name: 'paymentScriptHash', type: 'string' },
|
|
16519
|
+
{ name: 'stakingScriptHash', type: 'string' },
|
|
16520
|
+
]);
|
|
16521
|
+
if (addressParameters.path) {
|
|
16522
|
+
validatePath(addressParameters.path);
|
|
16523
|
+
}
|
|
16524
|
+
if (addressParameters.stakingPath) {
|
|
16525
|
+
validatePath(addressParameters.stakingPath);
|
|
16526
|
+
}
|
|
16527
|
+
if (addressParameters.certificatePointer) {
|
|
16528
|
+
validateParams(addressParameters.certificatePointer, [
|
|
16529
|
+
{ name: 'blockIndex', type: 'number', required: true },
|
|
16530
|
+
{ name: 'txIndex', type: 'number', required: true },
|
|
16531
|
+
{ name: 'certificateIndex', type: 'number', required: true },
|
|
16532
|
+
]);
|
|
16533
|
+
}
|
|
16534
|
+
};
|
|
16535
|
+
const addressParametersToProto = (addressParameters) => {
|
|
16536
|
+
let path = [];
|
|
16537
|
+
if (addressParameters.path) {
|
|
16538
|
+
path = validatePath(addressParameters.path, 3);
|
|
16539
|
+
}
|
|
16540
|
+
let stakingPath = [];
|
|
16541
|
+
if (addressParameters.stakingPath) {
|
|
16542
|
+
stakingPath = validatePath(addressParameters.stakingPath, 3);
|
|
16543
|
+
}
|
|
16544
|
+
let certificatePointer;
|
|
16545
|
+
if (addressParameters.certificatePointer) {
|
|
16546
|
+
certificatePointer = {
|
|
16547
|
+
block_index: addressParameters.certificatePointer.blockIndex,
|
|
16548
|
+
tx_index: addressParameters.certificatePointer.txIndex,
|
|
16549
|
+
certificate_index: addressParameters.certificatePointer.certificateIndex,
|
|
16550
|
+
};
|
|
16551
|
+
}
|
|
16552
|
+
return {
|
|
16553
|
+
address_type: addressParameters.addressType,
|
|
16554
|
+
address_n: path,
|
|
16555
|
+
address_n_staking: stakingPath,
|
|
16556
|
+
staking_key_hash: addressParameters.stakingKeyHash,
|
|
16557
|
+
certificate_pointer: certificatePointer,
|
|
16558
|
+
script_payment_hash: addressParameters.paymentScriptHash,
|
|
16559
|
+
script_staking_hash: addressParameters.stakingScriptHash,
|
|
16560
|
+
};
|
|
16561
|
+
};
|
|
16562
|
+
const addressParametersFromProto = (addressParameters) => {
|
|
16563
|
+
let certificatePointer;
|
|
16564
|
+
if (addressParameters.certificate_pointer) {
|
|
16565
|
+
certificatePointer = {
|
|
16566
|
+
blockIndex: addressParameters.certificate_pointer.block_index,
|
|
16567
|
+
txIndex: addressParameters.certificate_pointer.tx_index,
|
|
16568
|
+
certificateIndex: addressParameters.certificate_pointer.certificate_index,
|
|
16569
|
+
};
|
|
16570
|
+
}
|
|
16571
|
+
return {
|
|
16572
|
+
addressType: addressParameters.address_type,
|
|
16573
|
+
path: addressParameters.address_n,
|
|
16574
|
+
stakingPath: addressParameters.address_n_staking,
|
|
16575
|
+
stakingKeyHash: addressParameters.staking_key_hash,
|
|
16576
|
+
certificatePointer,
|
|
16577
|
+
};
|
|
16578
|
+
};
|
|
16579
|
+
const modifyAddressParametersForBackwardsCompatibility = (address_parameters) => {
|
|
16580
|
+
if (address_parameters.address_type === hdTransport.Messages.CardanoAddressType.REWARD) {
|
|
16581
|
+
let { address_n, address_n_staking } = address_parameters;
|
|
16582
|
+
if (address_n.length > 0 && address_n_staking.length > 0) {
|
|
16583
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Only stakingPath is allowed for CardanoAddressType.REWARD`);
|
|
16584
|
+
}
|
|
16585
|
+
if (address_n.length > 0) {
|
|
16586
|
+
address_n_staking = address_n;
|
|
16587
|
+
address_n = [];
|
|
16588
|
+
}
|
|
16589
|
+
return Object.assign(Object.assign({}, address_parameters), { address_n,
|
|
16590
|
+
address_n_staking });
|
|
16591
|
+
}
|
|
16592
|
+
return address_parameters;
|
|
16593
|
+
};
|
|
16594
|
+
|
|
16595
|
+
class CardanoGetAddress extends BaseMethod {
|
|
16596
|
+
init() {
|
|
16597
|
+
var _a;
|
|
16598
|
+
this.checkDeviceId = true;
|
|
16599
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
16600
|
+
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
16601
|
+
const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
|
|
16602
|
+
this.params = payload.bundle.map((batch) => {
|
|
16603
|
+
validateParams(batch, [
|
|
16604
|
+
{ name: 'addressParameters', type: 'object', required: true },
|
|
16605
|
+
{ name: 'networkId', type: 'number', required: true },
|
|
16606
|
+
{ name: 'protocolMagic', type: 'number', required: true },
|
|
16607
|
+
{ name: 'derivationType', type: 'number' },
|
|
16608
|
+
{ name: 'address', type: 'string' },
|
|
16609
|
+
{ name: 'showOnTrezor', type: 'boolean' },
|
|
16610
|
+
]);
|
|
16611
|
+
validateAddressParameters(batch.addressParameters);
|
|
16612
|
+
return {
|
|
16613
|
+
address_parameters: addressParametersToProto(batch.addressParameters),
|
|
16614
|
+
address: batch.address,
|
|
16615
|
+
protocol_magic: batch.protocolMagic,
|
|
16616
|
+
network_id: batch.networkId,
|
|
16617
|
+
derivation_type: typeof batch.derivationType !== 'undefined'
|
|
16618
|
+
? batch.derivationType
|
|
16619
|
+
: hdTransport.Messages.CardanoDerivationType.ICARUS_TREZOR,
|
|
16620
|
+
show_display: typeof batch.showOnOneKey === 'boolean' ? !!batch.showOneKey : true,
|
|
16621
|
+
};
|
|
16622
|
+
});
|
|
16623
|
+
}
|
|
16624
|
+
run() {
|
|
16625
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16626
|
+
const responses = [];
|
|
16627
|
+
for (const batch of this.params) {
|
|
16628
|
+
const { address_parameters, protocol_magic, network_id, derivation_type, show_display } = batch;
|
|
16629
|
+
const response = yield this.device.commands.typedCall('CardanoGetAddress', 'CardanoAddress', {
|
|
16630
|
+
address_parameters,
|
|
16631
|
+
protocol_magic,
|
|
16632
|
+
network_id,
|
|
16633
|
+
derivation_type,
|
|
16634
|
+
show_display,
|
|
16635
|
+
});
|
|
16636
|
+
const publicKeyRes = yield this.device.commands.typedCall('CardanoGetPublicKey', 'CardanoPublicKey', {
|
|
16637
|
+
address_n: address_parameters.address_n.slice(0, 3),
|
|
16638
|
+
derivation_type,
|
|
16639
|
+
show_display,
|
|
16640
|
+
});
|
|
16641
|
+
responses.push({
|
|
16642
|
+
addressParameters: addressParametersFromProto(batch.address_parameters),
|
|
16643
|
+
protocolMagic: batch.protocol_magic,
|
|
16644
|
+
networkId: batch.network_id,
|
|
16645
|
+
serializedPath: serializedPath(batch.address_parameters.address_n),
|
|
16646
|
+
serializedStakingPath: serializedPath(batch.address_parameters.address_n_staking),
|
|
16647
|
+
address: response.message.address,
|
|
16648
|
+
xpub: publicKeyRes.message.xpub,
|
|
16649
|
+
});
|
|
16650
|
+
}
|
|
16651
|
+
return this.hasBundle ? responses : responses[0];
|
|
16652
|
+
});
|
|
16653
|
+
}
|
|
16654
|
+
}
|
|
16655
|
+
|
|
16656
|
+
class CardanoGetPublicKey extends BaseMethod {
|
|
16657
|
+
init() {
|
|
16658
|
+
var _a;
|
|
16659
|
+
this.checkDeviceId = true;
|
|
16660
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
16661
|
+
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
16662
|
+
const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
|
|
16663
|
+
validateParams(payload, [{ name: 'bundle', type: 'array' }]);
|
|
16664
|
+
this.params = payload.bundle.map((batch) => {
|
|
16665
|
+
validateParams(batch, [
|
|
16666
|
+
{ name: 'path', required: true },
|
|
16667
|
+
{ name: 'derivationType', type: 'number' },
|
|
16668
|
+
{ name: 'showOnTrezor', type: 'boolean' },
|
|
16669
|
+
]);
|
|
16670
|
+
const path = validatePath(batch.path, 3);
|
|
16671
|
+
return {
|
|
16672
|
+
address_n: path,
|
|
16673
|
+
derivation_type: typeof batch.derivationType !== 'undefined'
|
|
16674
|
+
? batch.derivationType
|
|
16675
|
+
: hdTransport.Messages.CardanoDerivationType.ICARUS_TREZOR,
|
|
16676
|
+
show_display: typeof batch.showOnOneKey === 'boolean' ? batch.showOnOneKey : false,
|
|
16677
|
+
};
|
|
16678
|
+
});
|
|
16679
|
+
}
|
|
16680
|
+
run() {
|
|
16681
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16682
|
+
const responses = [];
|
|
16683
|
+
const cmd = this.device.getCommands();
|
|
16684
|
+
for (let i = 0; i < this.params.length; i++) {
|
|
16685
|
+
const batch = this.params[i];
|
|
16686
|
+
const { message } = yield cmd.typedCall('CardanoGetPublicKey', 'CardanoPublicKey', batch);
|
|
16687
|
+
responses.push({
|
|
16688
|
+
path: batch.address_n,
|
|
16689
|
+
serializedPath: serializedPath(batch.address_n),
|
|
16690
|
+
publicKey: message.xpub,
|
|
16691
|
+
node: message.node,
|
|
16692
|
+
});
|
|
16693
|
+
}
|
|
16694
|
+
return this.hasBundle ? responses : responses[0];
|
|
16695
|
+
});
|
|
16696
|
+
}
|
|
16697
|
+
}
|
|
16698
|
+
|
|
16699
|
+
const transformInput = (input) => {
|
|
16700
|
+
validateParams(input, [
|
|
16701
|
+
{ name: 'prev_hash', type: 'string', required: true },
|
|
16702
|
+
{ name: 'prev_index', type: 'number', required: true },
|
|
16703
|
+
]);
|
|
16704
|
+
return {
|
|
16705
|
+
input: {
|
|
16706
|
+
prev_hash: input.prev_hash,
|
|
16707
|
+
prev_index: input.prev_index,
|
|
16708
|
+
},
|
|
16709
|
+
path: input.path ? validatePath(input.path, 5) : undefined,
|
|
16710
|
+
};
|
|
16711
|
+
};
|
|
16712
|
+
const transformCollateralInput = (collateralInput) => {
|
|
16713
|
+
validateParams(collateralInput, [
|
|
16714
|
+
{ name: 'prev_hash', type: 'string', required: true },
|
|
16715
|
+
{ name: 'prev_index', type: 'number', required: true },
|
|
16716
|
+
]);
|
|
16717
|
+
return {
|
|
16718
|
+
collateralInput: {
|
|
16719
|
+
prev_hash: collateralInput.prev_hash,
|
|
16720
|
+
prev_index: collateralInput.prev_index,
|
|
16721
|
+
},
|
|
16722
|
+
path: collateralInput.path ? validatePath(collateralInput.path, 5) : undefined,
|
|
16723
|
+
};
|
|
16724
|
+
};
|
|
16725
|
+
const transformReferenceInput = (referenceInput) => {
|
|
16726
|
+
validateParams(referenceInput, [
|
|
16727
|
+
{ name: 'prev_hash', type: 'string', required: true },
|
|
16728
|
+
{ name: 'prev_index', type: 'number', required: true },
|
|
16729
|
+
]);
|
|
16730
|
+
return {
|
|
16731
|
+
prev_hash: referenceInput.prev_hash,
|
|
16732
|
+
prev_index: referenceInput.prev_index,
|
|
16733
|
+
};
|
|
16734
|
+
};
|
|
16735
|
+
|
|
16736
|
+
const validateTokens = (tokenAmounts) => {
|
|
16737
|
+
tokenAmounts.forEach(tokenAmount => {
|
|
16738
|
+
validateParams(tokenAmount, [
|
|
16739
|
+
{ name: 'assetNameBytes', type: 'string', required: true },
|
|
16740
|
+
{ name: 'amount', type: 'uint' },
|
|
16741
|
+
{ name: 'mintAmount', type: 'uint', allowNegative: true },
|
|
16742
|
+
]);
|
|
16743
|
+
});
|
|
16744
|
+
};
|
|
16745
|
+
const validateTokenBundle = (tokenBundle) => {
|
|
16746
|
+
tokenBundle.forEach(tokenGroup => {
|
|
16747
|
+
validateParams(tokenGroup, [
|
|
16748
|
+
{ name: 'policyId', type: 'string', required: true },
|
|
16749
|
+
{ name: 'tokenAmounts', type: 'array', required: true },
|
|
16750
|
+
]);
|
|
16751
|
+
validateTokens(tokenGroup.tokenAmounts);
|
|
16752
|
+
});
|
|
16753
|
+
};
|
|
16754
|
+
const tokenBundleToProto = (tokenBundle) => {
|
|
16755
|
+
validateTokenBundle(tokenBundle);
|
|
16756
|
+
return tokenBundle.map(tokenGroup => ({
|
|
16757
|
+
policyId: tokenGroup.policyId,
|
|
16758
|
+
tokens: tokenAmountsToProto(tokenGroup.tokenAmounts),
|
|
16759
|
+
}));
|
|
16760
|
+
};
|
|
16761
|
+
const tokenAmountsToProto = (tokenAmounts) => tokenAmounts.map(tokenAmount => ({
|
|
16762
|
+
asset_name_bytes: tokenAmount.assetNameBytes,
|
|
16763
|
+
amount: tokenAmount.amount,
|
|
16764
|
+
mint_amount: tokenAmount.mintAmount,
|
|
16765
|
+
}));
|
|
16766
|
+
|
|
16767
|
+
const hexStringByteLength = (s) => s.length / 2;
|
|
16768
|
+
const sendChunkedHexString = (typedCall, data, chunkSize, messageType) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16769
|
+
let processedSize = 0;
|
|
16770
|
+
while (processedSize < data.length) {
|
|
16771
|
+
const chunk = data.slice(processedSize, processedSize + chunkSize);
|
|
16772
|
+
yield typedCall(messageType, 'CardanoTxItemAck', {
|
|
16773
|
+
data: chunk,
|
|
16774
|
+
});
|
|
16775
|
+
processedSize += chunkSize;
|
|
16776
|
+
}
|
|
16777
|
+
});
|
|
16778
|
+
|
|
16779
|
+
const transformOutput = (output) => {
|
|
16780
|
+
validateParams(output, [
|
|
16781
|
+
{ name: 'address', type: 'string' },
|
|
16782
|
+
{ name: 'amount', type: 'uint', required: true },
|
|
16783
|
+
{ name: 'tokenBundle', type: 'array', allowEmpty: true },
|
|
16784
|
+
{ name: 'datumHash', type: 'string' },
|
|
16785
|
+
{ name: 'format', type: 'number' },
|
|
16786
|
+
{ name: 'inlineDatum', type: 'string' },
|
|
16787
|
+
{ name: 'referenceScript', type: 'string' },
|
|
16788
|
+
]);
|
|
16789
|
+
const result = {
|
|
16790
|
+
output: {
|
|
16791
|
+
amount: output.amount,
|
|
16792
|
+
asset_groups_count: 0,
|
|
16793
|
+
datum_hash: output.datumHash,
|
|
16794
|
+
format: output.format,
|
|
16795
|
+
inline_datum_size: output.inlineDatum ? hexStringByteLength(output.inlineDatum) : undefined,
|
|
16796
|
+
reference_script_size: output.referenceScript
|
|
16797
|
+
? hexStringByteLength(output.referenceScript)
|
|
16798
|
+
: undefined,
|
|
16799
|
+
},
|
|
16800
|
+
inlineDatum: output.inlineDatum,
|
|
16801
|
+
referenceScript: output.referenceScript,
|
|
16802
|
+
};
|
|
16803
|
+
if (output.addressParameters) {
|
|
16804
|
+
validateAddressParameters(output.addressParameters);
|
|
16805
|
+
result.output.address_parameters = addressParametersToProto(output.addressParameters);
|
|
16806
|
+
}
|
|
16807
|
+
else {
|
|
16808
|
+
result.output.address = output.address;
|
|
16809
|
+
}
|
|
16810
|
+
if (output.tokenBundle) {
|
|
16811
|
+
result.tokenBundle = tokenBundleToProto(output.tokenBundle);
|
|
16812
|
+
result.output.asset_groups_count = result.tokenBundle.length;
|
|
16813
|
+
}
|
|
16814
|
+
else {
|
|
16815
|
+
result.output.asset_groups_count = 0;
|
|
16816
|
+
}
|
|
16817
|
+
return result;
|
|
16818
|
+
};
|
|
16819
|
+
const sendOutput = (typedCall, outputWithData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16820
|
+
const MAX_CHUNK_SIZE = 1024 * 2;
|
|
16821
|
+
const { output, tokenBundle, inlineDatum, referenceScript } = outputWithData;
|
|
16822
|
+
yield typedCall('CardanoTxOutput', 'CardanoTxItemAck', output);
|
|
16823
|
+
if (tokenBundle) {
|
|
16824
|
+
for (const assetGroup of tokenBundle) {
|
|
16825
|
+
yield typedCall('CardanoAssetGroup', 'CardanoTxItemAck', {
|
|
16826
|
+
policy_id: assetGroup.policyId,
|
|
16827
|
+
tokens_count: assetGroup.tokens.length,
|
|
16828
|
+
});
|
|
16829
|
+
for (const token of assetGroup.tokens) {
|
|
16830
|
+
yield typedCall('CardanoToken', 'CardanoTxItemAck', token);
|
|
16831
|
+
}
|
|
16832
|
+
}
|
|
16833
|
+
}
|
|
16834
|
+
if (inlineDatum) {
|
|
16835
|
+
yield sendChunkedHexString(typedCall, inlineDatum, MAX_CHUNK_SIZE, 'CardanoTxInlineDatumChunk');
|
|
16836
|
+
}
|
|
16837
|
+
if (referenceScript) {
|
|
16838
|
+
yield sendChunkedHexString(typedCall, referenceScript, MAX_CHUNK_SIZE, 'CardanoTxReferenceScriptChunk');
|
|
16839
|
+
}
|
|
16840
|
+
});
|
|
16841
|
+
|
|
16842
|
+
const ipv4AddressToHex = (ipv4Address) => Buffer.from(ipv4Address.split('.').map(ipPart => parseInt(ipPart, 10))).toString('hex');
|
|
16843
|
+
const ipv6AddressToHex = (ipv6Address) => ipv6Address.split(':').join('');
|
|
16844
|
+
const validatePoolMargin = (margin) => {
|
|
16845
|
+
validateParams(margin, [
|
|
16846
|
+
{ name: 'numerator', type: 'string', required: true },
|
|
16847
|
+
{ name: 'denominator', type: 'string', required: true },
|
|
16848
|
+
]);
|
|
16849
|
+
};
|
|
16850
|
+
const validatePoolMetadata = (metadata) => {
|
|
16851
|
+
validateParams(metadata, [
|
|
16852
|
+
{ name: 'url', type: 'string', required: true },
|
|
16853
|
+
{ name: 'hash', type: 'string', required: true },
|
|
16854
|
+
]);
|
|
16855
|
+
};
|
|
16856
|
+
const validatePoolRelay = (relay) => {
|
|
16857
|
+
validateParams(relay, [{ name: 'type', type: 'number', required: true }]);
|
|
16858
|
+
if (relay.type === hdTransport.Messages.CardanoPoolRelayType.SINGLE_HOST_IP) {
|
|
16859
|
+
const paramsToValidate = [
|
|
16860
|
+
{ name: 'port', type: 'number', required: true },
|
|
16861
|
+
];
|
|
16862
|
+
if (relay.ipv4Address) {
|
|
16863
|
+
paramsToValidate.push({ name: 'ipv4Address', type: 'string', required: false });
|
|
16864
|
+
}
|
|
16865
|
+
if (relay.ipv6Address) {
|
|
16866
|
+
paramsToValidate.push({ name: 'ipv6Address', type: 'string', required: false });
|
|
16867
|
+
}
|
|
16868
|
+
validateParams(relay, paramsToValidate);
|
|
16869
|
+
if (!relay.ipv4Address && !relay.ipv6Address) {
|
|
16870
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Either ipv4Address or ipv6Address must be supplied');
|
|
16871
|
+
}
|
|
16872
|
+
}
|
|
16873
|
+
else if (relay.type === hdTransport.Messages.CardanoPoolRelayType.SINGLE_HOST_NAME) {
|
|
16874
|
+
validateParams(relay, [
|
|
16875
|
+
{ name: 'hostName', type: 'string', required: true },
|
|
16876
|
+
{ name: 'port', type: 'number', required: true },
|
|
16877
|
+
]);
|
|
16878
|
+
}
|
|
16879
|
+
else if (relay.type === hdTransport.Messages.CardanoPoolRelayType.MULTIPLE_HOST_NAME) {
|
|
16880
|
+
validateParams(relay, [{ name: 'hostName', type: 'string', required: true }]);
|
|
16881
|
+
}
|
|
16882
|
+
};
|
|
16883
|
+
const validatePoolOwners = (owners) => {
|
|
16884
|
+
owners.forEach(owner => {
|
|
16885
|
+
if (owner.stakingKeyHash) {
|
|
16886
|
+
validateParams(owner, [
|
|
16887
|
+
{ name: 'stakingKeyHash', type: 'string', required: !owner.stakingKeyPath },
|
|
16888
|
+
]);
|
|
16889
|
+
}
|
|
16890
|
+
if (owner.stakingKeyPath) {
|
|
16891
|
+
validatePath(owner.stakingKeyPath, 5);
|
|
16892
|
+
}
|
|
16893
|
+
if (!owner.stakingKeyHash && !owner.stakingKeyPath) {
|
|
16894
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Either stakingKeyHash or stakingKeyPath must be supplied');
|
|
16895
|
+
}
|
|
16896
|
+
});
|
|
16897
|
+
const ownersAsPathCount = owners.filter(owner => !!owner.stakingKeyPath).length;
|
|
16898
|
+
if (ownersAsPathCount !== 1) {
|
|
16899
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Exactly one pool owner must be given as a path');
|
|
16900
|
+
}
|
|
16901
|
+
};
|
|
16902
|
+
const validatePoolParameters = (poolParameters) => {
|
|
16903
|
+
validateParams(poolParameters, [
|
|
16904
|
+
{ name: 'poolId', type: 'string', required: true },
|
|
16905
|
+
{ name: 'vrfKeyHash', type: 'string', required: true },
|
|
16906
|
+
{ name: 'pledge', type: 'string', required: true },
|
|
16907
|
+
{ name: 'cost', type: 'string', required: true },
|
|
16908
|
+
{ name: 'margin', type: 'object', required: true },
|
|
16909
|
+
{ name: 'rewardAccount', type: 'string', required: true },
|
|
16910
|
+
{ name: 'owners', type: 'array', required: true },
|
|
16911
|
+
{ name: 'relays', type: 'array', required: true, allowEmpty: true },
|
|
16912
|
+
{ name: 'metadata', type: 'object' },
|
|
16913
|
+
]);
|
|
16914
|
+
validatePoolMargin(poolParameters.margin);
|
|
16915
|
+
validatePoolOwners(poolParameters.owners);
|
|
16916
|
+
poolParameters.relays.forEach(validatePoolRelay);
|
|
16917
|
+
if (poolParameters.metadata) {
|
|
16918
|
+
validatePoolMetadata(poolParameters.metadata);
|
|
16919
|
+
}
|
|
16920
|
+
};
|
|
16921
|
+
const transformPoolParameters = (poolParameters) => {
|
|
16922
|
+
if (!poolParameters) {
|
|
16923
|
+
return { poolParameters: undefined, poolOwners: [], poolRelays: [] };
|
|
16924
|
+
}
|
|
16925
|
+
validatePoolParameters(poolParameters);
|
|
16926
|
+
return {
|
|
16927
|
+
poolParameters: {
|
|
16928
|
+
pool_id: poolParameters.poolId,
|
|
16929
|
+
vrf_key_hash: poolParameters.vrfKeyHash,
|
|
16930
|
+
pledge: poolParameters.pledge,
|
|
16931
|
+
cost: poolParameters.cost,
|
|
16932
|
+
margin_numerator: poolParameters.margin.numerator,
|
|
16933
|
+
margin_denominator: poolParameters.margin.denominator,
|
|
16934
|
+
reward_account: poolParameters.rewardAccount,
|
|
16935
|
+
metadata: poolParameters.metadata,
|
|
16936
|
+
owners_count: poolParameters.owners.length,
|
|
16937
|
+
relays_count: poolParameters.relays.length,
|
|
16938
|
+
},
|
|
16939
|
+
poolOwners: poolParameters.owners.map(owner => ({
|
|
16940
|
+
staking_key_hash: owner.stakingKeyHash,
|
|
16941
|
+
staking_key_path: owner.stakingKeyPath ? validatePath(owner.stakingKeyPath, 5) : undefined,
|
|
16942
|
+
})),
|
|
16943
|
+
poolRelays: poolParameters.relays.map(relay => ({
|
|
16944
|
+
type: relay.type,
|
|
16945
|
+
ipv4_address: relay.ipv4Address ? ipv4AddressToHex(relay.ipv4Address) : undefined,
|
|
16946
|
+
ipv6_address: relay.ipv6Address ? ipv6AddressToHex(relay.ipv6Address) : undefined,
|
|
16947
|
+
host_name: relay.hostName,
|
|
16948
|
+
port: relay.port,
|
|
16949
|
+
})),
|
|
16950
|
+
};
|
|
16951
|
+
};
|
|
16952
|
+
const transformCertificate = (certificate) => {
|
|
16953
|
+
const paramsToValidate = [
|
|
16954
|
+
{ name: 'type', type: 'number', required: true },
|
|
16955
|
+
];
|
|
16956
|
+
if (certificate.type !== hdTransport.Messages.CardanoCertificateType.STAKE_POOL_REGISTRATION) {
|
|
16957
|
+
paramsToValidate.push({ name: 'scriptHash', type: 'string' });
|
|
16958
|
+
paramsToValidate.push({ name: 'keyHash', type: 'string' });
|
|
16959
|
+
}
|
|
16960
|
+
if (certificate.type === hdTransport.Messages.CardanoCertificateType.STAKE_DELEGATION) {
|
|
16961
|
+
paramsToValidate.push({ name: 'pool', type: 'string', required: true });
|
|
16962
|
+
}
|
|
16963
|
+
if (certificate.type === hdTransport.Messages.CardanoCertificateType.STAKE_POOL_REGISTRATION) {
|
|
16964
|
+
paramsToValidate.push({ name: 'poolParameters', type: 'object', required: true });
|
|
16965
|
+
}
|
|
16966
|
+
validateParams(certificate, paramsToValidate);
|
|
16967
|
+
const { poolParameters, poolOwners, poolRelays } = transformPoolParameters(certificate.poolParameters);
|
|
16968
|
+
return {
|
|
16969
|
+
certificate: {
|
|
16970
|
+
type: certificate.type,
|
|
16971
|
+
path: certificate.path ? validatePath(certificate.path, 5) : undefined,
|
|
16972
|
+
script_hash: certificate.scriptHash,
|
|
16973
|
+
key_hash: certificate.keyHash,
|
|
16974
|
+
pool: certificate.pool,
|
|
16975
|
+
pool_parameters: poolParameters,
|
|
16976
|
+
},
|
|
16977
|
+
poolOwners,
|
|
16978
|
+
poolRelays,
|
|
16979
|
+
};
|
|
16980
|
+
};
|
|
16981
|
+
|
|
16982
|
+
const transformCatalystRegistrationParameters = (catalystRegistrationParameters) => {
|
|
16983
|
+
validateParams(catalystRegistrationParameters, [
|
|
16984
|
+
{ name: 'votingPublicKey', type: 'string', required: true },
|
|
16985
|
+
{ name: 'stakingPath', required: true },
|
|
16986
|
+
{ name: 'nonce', type: 'uint', required: true },
|
|
16987
|
+
]);
|
|
16988
|
+
validateAddressParameters(catalystRegistrationParameters.rewardAddressParameters);
|
|
16989
|
+
return {
|
|
16990
|
+
voting_public_key: catalystRegistrationParameters.votingPublicKey,
|
|
16991
|
+
staking_path: validatePath(catalystRegistrationParameters.stakingPath, 3),
|
|
16992
|
+
reward_address_parameters: addressParametersToProto(catalystRegistrationParameters.rewardAddressParameters),
|
|
16993
|
+
nonce: catalystRegistrationParameters.nonce,
|
|
16994
|
+
};
|
|
16995
|
+
};
|
|
16996
|
+
const transformAuxiliaryData = (auxiliaryData) => {
|
|
16997
|
+
validateParams(auxiliaryData, [
|
|
16998
|
+
{
|
|
16999
|
+
name: 'hash',
|
|
17000
|
+
type: 'string',
|
|
17001
|
+
},
|
|
17002
|
+
]);
|
|
17003
|
+
let catalystRegistrationParameters;
|
|
17004
|
+
if (auxiliaryData.catalystRegistrationParameters) {
|
|
17005
|
+
catalystRegistrationParameters = transformCatalystRegistrationParameters(auxiliaryData.catalystRegistrationParameters);
|
|
17006
|
+
}
|
|
17007
|
+
return {
|
|
17008
|
+
hash: auxiliaryData.hash,
|
|
17009
|
+
catalyst_registration_parameters: catalystRegistrationParameters,
|
|
17010
|
+
};
|
|
17011
|
+
};
|
|
17012
|
+
const modifyAuxiliaryDataForBackwardsCompatibility = (auxiliary_data) => {
|
|
17013
|
+
const { catalyst_registration_parameters } = auxiliary_data;
|
|
17014
|
+
if (catalyst_registration_parameters) {
|
|
17015
|
+
catalyst_registration_parameters.reward_address_parameters =
|
|
17016
|
+
modifyAddressParametersForBackwardsCompatibility(catalyst_registration_parameters.reward_address_parameters);
|
|
17017
|
+
return Object.assign(Object.assign({}, auxiliary_data), { catalyst_registration_parameters });
|
|
17018
|
+
}
|
|
17019
|
+
return auxiliary_data;
|
|
17020
|
+
};
|
|
17021
|
+
|
|
17022
|
+
const gatherWitnessPaths = (inputsWithPath, certificatesWithPoolOwnersAndRelays, withdrawals, collateralInputsWithPath, requiredSigners, additionalWitnessRequests, signingMode) => {
|
|
17023
|
+
const witnessPaths = new Map();
|
|
17024
|
+
function _insert(path) {
|
|
17025
|
+
const pathKey = JSON.stringify(path);
|
|
17026
|
+
witnessPaths.set(pathKey, path);
|
|
17027
|
+
}
|
|
17028
|
+
if (signingMode !== hdTransport.Messages.CardanoTxSigningMode.MULTISIG_TRANSACTION) {
|
|
17029
|
+
inputsWithPath.forEach(({ path }) => {
|
|
17030
|
+
if (path)
|
|
17031
|
+
_insert(path);
|
|
17032
|
+
});
|
|
17033
|
+
certificatesWithPoolOwnersAndRelays.forEach(({ certificate, poolOwners }) => {
|
|
17034
|
+
if (certificate.path &&
|
|
17035
|
+
(certificate.type === hdTransport.Messages.CardanoCertificateType.STAKE_DELEGATION ||
|
|
17036
|
+
certificate.type === hdTransport.Messages.CardanoCertificateType.STAKE_DEREGISTRATION)) {
|
|
17037
|
+
_insert(certificate.path);
|
|
17038
|
+
}
|
|
17039
|
+
poolOwners.forEach(poolOwner => {
|
|
17040
|
+
if (poolOwner.staking_key_path)
|
|
17041
|
+
_insert(poolOwner.staking_key_path);
|
|
17042
|
+
});
|
|
17043
|
+
});
|
|
17044
|
+
withdrawals.forEach(({ path }) => {
|
|
17045
|
+
if (path)
|
|
17046
|
+
_insert(path);
|
|
17047
|
+
});
|
|
17048
|
+
}
|
|
17049
|
+
if (signingMode === hdTransport.Messages.CardanoTxSigningMode.PLUTUS_TRANSACTION) {
|
|
17050
|
+
collateralInputsWithPath.forEach(({ path }) => {
|
|
17051
|
+
if (path)
|
|
17052
|
+
_insert(path);
|
|
17053
|
+
});
|
|
17054
|
+
}
|
|
17055
|
+
requiredSigners.forEach(({ key_path }) => {
|
|
17056
|
+
if (key_path)
|
|
17057
|
+
_insert(key_path);
|
|
17058
|
+
});
|
|
17059
|
+
additionalWitnessRequests.forEach(path => {
|
|
17060
|
+
_insert(path);
|
|
17061
|
+
});
|
|
17062
|
+
return Array.from(witnessPaths.values());
|
|
17063
|
+
};
|
|
17064
|
+
|
|
17065
|
+
class CardanoSignTransaction extends BaseMethod {
|
|
17066
|
+
init() {
|
|
17067
|
+
var _a;
|
|
17068
|
+
this.checkDeviceId = true;
|
|
17069
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
17070
|
+
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
17071
|
+
const { payload } = this;
|
|
17072
|
+
validateParams(payload, [
|
|
17073
|
+
{ name: 'signingMode', type: 'number', required: true },
|
|
17074
|
+
{ name: 'inputs', type: 'array', required: true },
|
|
17075
|
+
{ name: 'outputs', type: 'array', required: true, allowEmpty: true },
|
|
17076
|
+
{ name: 'fee', type: 'uint', required: true },
|
|
17077
|
+
{ name: 'ttl', type: 'uint' },
|
|
17078
|
+
{ name: 'certificates', type: 'array', allowEmpty: true },
|
|
17079
|
+
{ name: 'withdrawals', type: 'array', allowEmpty: true },
|
|
17080
|
+
{ name: 'mint', type: 'array', allowEmpty: true },
|
|
17081
|
+
{ name: 'validityIntervalStart', type: 'uint' },
|
|
17082
|
+
{ name: 'scriptDataHash', type: 'string' },
|
|
17083
|
+
{ name: 'collateralInputs', type: 'array', allowEmpty: true },
|
|
17084
|
+
{ name: 'requiredSigners', type: 'array', allowEmpty: true },
|
|
17085
|
+
{ name: 'totalCollateral', type: 'uint' },
|
|
17086
|
+
{ name: 'referenceInputs', type: 'array', allowEmpty: true },
|
|
17087
|
+
{ name: 'protocolMagic', type: 'number', required: true },
|
|
17088
|
+
{ name: 'networkId', type: 'number', required: true },
|
|
17089
|
+
{ name: 'additionalWitnessRequests', type: 'array', allowEmpty: true },
|
|
17090
|
+
{ name: 'derivationType', type: 'number' },
|
|
17091
|
+
{ name: 'includeNetworkId', type: 'boolean' },
|
|
17092
|
+
]);
|
|
17093
|
+
const inputsWithPath = payload.inputs.map(transformInput);
|
|
17094
|
+
const outputsWithData = payload.outputs.map(transformOutput);
|
|
17095
|
+
let certificatesWithPoolOwnersAndRelays = [];
|
|
17096
|
+
if (payload.certificates) {
|
|
17097
|
+
certificatesWithPoolOwnersAndRelays = payload.certificates.map(transformCertificate);
|
|
17098
|
+
}
|
|
17099
|
+
let withdrawals = [];
|
|
17100
|
+
if (payload.withdrawals) {
|
|
17101
|
+
withdrawals = payload.withdrawals.map((withdrawal) => {
|
|
17102
|
+
validateParams(withdrawal, [
|
|
17103
|
+
{ name: 'amount', type: 'uint', required: true },
|
|
17104
|
+
{ name: 'scriptHash', type: 'string' },
|
|
17105
|
+
{ name: 'keyHash', type: 'string' },
|
|
17106
|
+
]);
|
|
17107
|
+
return {
|
|
17108
|
+
path: withdrawal.path ? validatePath(withdrawal.path, 5) : undefined,
|
|
17109
|
+
amount: withdrawal.amount,
|
|
17110
|
+
script_hash: withdrawal.scriptHash,
|
|
17111
|
+
key_hash: withdrawal.keyHash,
|
|
17112
|
+
};
|
|
17113
|
+
});
|
|
17114
|
+
}
|
|
17115
|
+
let mint = [];
|
|
17116
|
+
if (payload.mint) {
|
|
17117
|
+
mint = tokenBundleToProto(payload.mint);
|
|
17118
|
+
}
|
|
17119
|
+
let auxiliaryData;
|
|
17120
|
+
if (payload.auxiliaryData) {
|
|
17121
|
+
auxiliaryData = transformAuxiliaryData(payload.auxiliaryData);
|
|
17122
|
+
}
|
|
17123
|
+
let additionalWitnessRequests = [];
|
|
17124
|
+
if (payload.additionalWitnessRequests) {
|
|
17125
|
+
additionalWitnessRequests = payload.additionalWitnessRequests.map((witnessRequest) => validatePath(witnessRequest, 3));
|
|
17126
|
+
}
|
|
17127
|
+
let collateralInputsWithPath = [];
|
|
17128
|
+
if (payload.collateralInputs) {
|
|
17129
|
+
collateralInputsWithPath = payload.collateralInputs.map(transformCollateralInput);
|
|
17130
|
+
}
|
|
17131
|
+
let requiredSigners = [];
|
|
17132
|
+
if (payload.requiredSigners) {
|
|
17133
|
+
requiredSigners = payload.requiredSigners.map((requiredSigner) => {
|
|
17134
|
+
validateParams(requiredSigner, [{ name: 'keyHash', type: 'string' }]);
|
|
17135
|
+
return {
|
|
17136
|
+
key_path: requiredSigner.keyPath ? validatePath(requiredSigner.keyPath, 3) : undefined,
|
|
17137
|
+
key_hash: requiredSigner.keyHash,
|
|
17138
|
+
};
|
|
17139
|
+
});
|
|
17140
|
+
}
|
|
17141
|
+
const collateralReturnWithData = payload.collateralReturn
|
|
17142
|
+
? transformOutput(payload.collateralReturn)
|
|
17143
|
+
: undefined;
|
|
17144
|
+
let referenceInputs = [];
|
|
17145
|
+
if (payload.referenceInputs) {
|
|
17146
|
+
referenceInputs = payload.referenceInputs.map(transformReferenceInput);
|
|
17147
|
+
}
|
|
17148
|
+
this.params = {
|
|
17149
|
+
signingMode: payload.signingMode,
|
|
17150
|
+
inputsWithPath,
|
|
17151
|
+
outputsWithData,
|
|
17152
|
+
fee: payload.fee,
|
|
17153
|
+
ttl: payload.ttl,
|
|
17154
|
+
certificatesWithPoolOwnersAndRelays,
|
|
17155
|
+
withdrawals,
|
|
17156
|
+
mint,
|
|
17157
|
+
auxiliaryData,
|
|
17158
|
+
validityIntervalStart: payload.validityIntervalStart,
|
|
17159
|
+
scriptDataHash: payload.scriptDataHash,
|
|
17160
|
+
collateralInputsWithPath,
|
|
17161
|
+
requiredSigners,
|
|
17162
|
+
collateralReturnWithData,
|
|
17163
|
+
totalCollateral: payload.totalCollateral,
|
|
17164
|
+
referenceInputs,
|
|
17165
|
+
protocolMagic: payload.protocolMagic,
|
|
17166
|
+
networkId: payload.networkId,
|
|
17167
|
+
witnessPaths: gatherWitnessPaths(inputsWithPath, certificatesWithPoolOwnersAndRelays, withdrawals, collateralInputsWithPath, requiredSigners, additionalWitnessRequests, payload.signingMode),
|
|
17168
|
+
additionalWitnessRequests,
|
|
17169
|
+
derivationType: typeof payload.derivationType !== 'undefined'
|
|
17170
|
+
? payload.derivationType
|
|
17171
|
+
: hdTransport.Messages.CardanoDerivationType.ICARUS_TREZOR,
|
|
17172
|
+
includeNetworkId: payload.includeNetworkId,
|
|
17173
|
+
};
|
|
17174
|
+
}
|
|
17175
|
+
signTx() {
|
|
17176
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17177
|
+
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
17178
|
+
const hasAuxiliaryData = !!this.params.auxiliaryData;
|
|
17179
|
+
const signTxInitMessage = {
|
|
17180
|
+
signing_mode: this.params.signingMode,
|
|
17181
|
+
protocol_magic: this.params.protocolMagic,
|
|
17182
|
+
network_id: this.params.networkId,
|
|
17183
|
+
inputs_count: this.params.inputsWithPath.length,
|
|
17184
|
+
outputs_count: this.params.outputsWithData.length,
|
|
17185
|
+
fee: this.params.fee,
|
|
17186
|
+
ttl: this.params.ttl,
|
|
17187
|
+
certificates_count: this.params.certificatesWithPoolOwnersAndRelays.length,
|
|
17188
|
+
withdrawals_count: this.params.withdrawals.length,
|
|
17189
|
+
has_auxiliary_data: hasAuxiliaryData,
|
|
17190
|
+
validity_interval_start: this.params.validityIntervalStart,
|
|
17191
|
+
witness_requests_count: this.params.witnessPaths.length,
|
|
17192
|
+
minting_asset_groups_count: this.params.mint.length,
|
|
17193
|
+
script_data_hash: this.params.scriptDataHash,
|
|
17194
|
+
collateral_inputs_count: this.params.collateralInputsWithPath.length,
|
|
17195
|
+
required_signers_count: this.params.requiredSigners.length,
|
|
17196
|
+
has_collateral_return: this.params.collateralReturnWithData != null,
|
|
17197
|
+
total_collateral: this.params.totalCollateral,
|
|
17198
|
+
reference_inputs_count: this.params.referenceInputs.length,
|
|
17199
|
+
derivation_type: this.params.derivationType,
|
|
17200
|
+
include_network_id: this.params.includeNetworkId,
|
|
17201
|
+
};
|
|
17202
|
+
yield typedCall('CardanoSignTxInit', 'CardanoTxItemAck', signTxInitMessage);
|
|
17203
|
+
for (const { input } of this.params.inputsWithPath) {
|
|
17204
|
+
yield typedCall('CardanoTxInput', 'CardanoTxItemAck', input);
|
|
17205
|
+
}
|
|
17206
|
+
for (const outputWithData of this.params.outputsWithData) {
|
|
17207
|
+
yield sendOutput(typedCall, outputWithData);
|
|
17208
|
+
}
|
|
17209
|
+
for (const { certificate, poolOwners, poolRelays } of this.params
|
|
17210
|
+
.certificatesWithPoolOwnersAndRelays) {
|
|
17211
|
+
yield typedCall('CardanoTxCertificate', 'CardanoTxItemAck', certificate);
|
|
17212
|
+
for (const poolOwner of poolOwners) {
|
|
17213
|
+
yield typedCall('CardanoPoolOwner', 'CardanoTxItemAck', poolOwner);
|
|
17214
|
+
}
|
|
17215
|
+
for (const poolRelay of poolRelays) {
|
|
17216
|
+
yield typedCall('CardanoPoolRelayParameters', 'CardanoTxItemAck', poolRelay);
|
|
17217
|
+
}
|
|
17218
|
+
}
|
|
17219
|
+
for (const withdrawal of this.params.withdrawals) {
|
|
17220
|
+
yield typedCall('CardanoTxWithdrawal', 'CardanoTxItemAck', withdrawal);
|
|
17221
|
+
}
|
|
17222
|
+
let auxiliaryDataSupplement;
|
|
17223
|
+
if (this.params.auxiliaryData) {
|
|
17224
|
+
const { catalyst_registration_parameters } = this.params.auxiliaryData;
|
|
17225
|
+
if (catalyst_registration_parameters) {
|
|
17226
|
+
this.params.auxiliaryData = modifyAuxiliaryDataForBackwardsCompatibility(this.params.auxiliaryData);
|
|
17227
|
+
}
|
|
17228
|
+
const { message } = yield typedCall('CardanoTxAuxiliaryData', 'CardanoTxAuxiliaryDataSupplement', this.params.auxiliaryData);
|
|
17229
|
+
const auxiliaryDataType = hdTransport.Messages.CardanoTxAuxiliaryDataSupplementType[message.type];
|
|
17230
|
+
if (auxiliaryDataType !== hdTransport.Messages.CardanoTxAuxiliaryDataSupplementType.NONE) {
|
|
17231
|
+
auxiliaryDataSupplement = {
|
|
17232
|
+
type: auxiliaryDataType,
|
|
17233
|
+
auxiliaryDataHash: message.auxiliary_data_hash,
|
|
17234
|
+
catalystSignature: message.catalyst_signature,
|
|
17235
|
+
};
|
|
17236
|
+
}
|
|
17237
|
+
yield typedCall('CardanoTxHostAck', 'CardanoTxItemAck');
|
|
17238
|
+
}
|
|
17239
|
+
if (this.params.mint.length > 0) {
|
|
17240
|
+
yield typedCall('CardanoTxMint', 'CardanoTxItemAck', {
|
|
17241
|
+
asset_groups_count: this.params.mint.length,
|
|
17242
|
+
});
|
|
17243
|
+
for (const assetGroup of this.params.mint) {
|
|
17244
|
+
yield typedCall('CardanoAssetGroup', 'CardanoTxItemAck', {
|
|
17245
|
+
policy_id: assetGroup.policyId,
|
|
17246
|
+
tokens_count: assetGroup.tokens.length,
|
|
17247
|
+
});
|
|
17248
|
+
for (const token of assetGroup.tokens) {
|
|
17249
|
+
yield typedCall('CardanoToken', 'CardanoTxItemAck', token);
|
|
17250
|
+
}
|
|
17251
|
+
}
|
|
17252
|
+
}
|
|
17253
|
+
for (const { collateralInput } of this.params.collateralInputsWithPath) {
|
|
17254
|
+
yield typedCall('CardanoTxCollateralInput', 'CardanoTxItemAck', collateralInput);
|
|
17255
|
+
}
|
|
17256
|
+
for (const requiredSigner of this.params.requiredSigners) {
|
|
17257
|
+
yield typedCall('CardanoTxRequiredSigner', 'CardanoTxItemAck', requiredSigner);
|
|
17258
|
+
}
|
|
17259
|
+
if (this.params.collateralReturnWithData) {
|
|
17260
|
+
yield sendOutput(typedCall, this.params.collateralReturnWithData);
|
|
17261
|
+
}
|
|
17262
|
+
for (const referenceInput of this.params.referenceInputs) {
|
|
17263
|
+
yield typedCall('CardanoTxReferenceInput', 'CardanoTxItemAck', referenceInput);
|
|
17264
|
+
}
|
|
17265
|
+
const witnesses = [];
|
|
17266
|
+
for (const path of this.params.witnessPaths) {
|
|
17267
|
+
const { message } = yield typedCall('CardanoTxWitnessRequest', 'CardanoTxWitnessResponse', {
|
|
17268
|
+
path,
|
|
17269
|
+
});
|
|
17270
|
+
witnesses.push({
|
|
17271
|
+
type: hdTransport.Messages.CardanoTxWitnessType[message.type],
|
|
17272
|
+
pubKey: message.pub_key,
|
|
17273
|
+
signature: message.signature,
|
|
17274
|
+
chainCode: message.chain_code,
|
|
17275
|
+
});
|
|
17276
|
+
}
|
|
17277
|
+
const { message: txBodyHashMessage } = yield typedCall('CardanoTxHostAck', 'CardanoTxBodyHash');
|
|
17278
|
+
yield typedCall('CardanoTxHostAck', 'CardanoSignTxFinished');
|
|
17279
|
+
return { hash: txBodyHashMessage.tx_hash, witnesses, auxiliaryDataSupplement };
|
|
17280
|
+
});
|
|
17281
|
+
}
|
|
17282
|
+
run() {
|
|
17283
|
+
return this.signTx();
|
|
17284
|
+
}
|
|
17285
|
+
}
|
|
17286
|
+
|
|
16444
17287
|
var ApiMethods = /*#__PURE__*/Object.freeze({
|
|
16445
17288
|
__proto__: null,
|
|
16446
17289
|
searchDevices: SearchDevices,
|
|
@@ -16513,7 +17356,10 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
|
|
|
16513
17356
|
xrpSignTransaction: XrpGetAddress,
|
|
16514
17357
|
suiGetAddress: SuiGetAddress,
|
|
16515
17358
|
suiGetPublicKey: SuiGetPublicKey,
|
|
16516
|
-
suiSignTransaction: SuiSignTransaction
|
|
17359
|
+
suiSignTransaction: SuiSignTransaction,
|
|
17360
|
+
cardanoGetAddress: CardanoGetAddress,
|
|
17361
|
+
cardanoGetPublicKey: CardanoGetPublicKey,
|
|
17362
|
+
cardanoSignTransaction: CardanoSignTransaction
|
|
16517
17363
|
});
|
|
16518
17364
|
|
|
16519
17365
|
function findMethod(message) {
|
|
@@ -16528,21 +17374,6 @@ function findMethod(message) {
|
|
|
16528
17374
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Method ${method} is not set`);
|
|
16529
17375
|
}
|
|
16530
17376
|
|
|
16531
|
-
const safeThrowError = (error) => {
|
|
16532
|
-
if (error instanceof hdShared.HardwareError) {
|
|
16533
|
-
throw error;
|
|
16534
|
-
}
|
|
16535
|
-
else if (error.code === 'ERR_NETWORK') {
|
|
16536
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeNotInstalled);
|
|
16537
|
-
}
|
|
16538
|
-
else if (error.code === 'ECONNABORTED') {
|
|
16539
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError);
|
|
16540
|
-
}
|
|
16541
|
-
else {
|
|
16542
|
-
throw hdShared.ERRORS.TypedError(error);
|
|
16543
|
-
}
|
|
16544
|
-
};
|
|
16545
|
-
|
|
16546
17377
|
const resolveAfter = (msec, value) => new Promise(resolve => {
|
|
16547
17378
|
setTimeout(resolve, msec, value);
|
|
16548
17379
|
});
|
|
@@ -16649,6 +17480,7 @@ const parseInitOptions = (method) => ({
|
|
|
16649
17480
|
initSession: method === null || method === void 0 ? void 0 : method.payload.initSession,
|
|
16650
17481
|
passphraseState: method === null || method === void 0 ? void 0 : method.payload.passphraseState,
|
|
16651
17482
|
deviceId: method === null || method === void 0 ? void 0 : method.payload.deviceId,
|
|
17483
|
+
deriveCardano: method === null || method === void 0 ? void 0 : method.name.startsWith('cardano'),
|
|
16652
17484
|
});
|
|
16653
17485
|
let _core;
|
|
16654
17486
|
let _deviceList;
|