-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathCardanoSignMessage.ts
More file actions
74 lines (62 loc) · 1.98 KB
/
Copy pathCardanoSignMessage.ts
File metadata and controls
74 lines (62 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { BaseMethod } from '../BaseMethod';
import { PROTO } from '../../constants';
import { UI_REQUEST } from '../../constants/ui-request';
import { validateParams } from '../helpers/paramsValidator';
import { validatePath } from '../helpers/pathUtils';
import type { CardanoSignMessageParams } from '../../types/api/cardanoSignMessage';
export default class CardanoSignMessage extends BaseMethod<CardanoSignMessageParams> {
hasBundle?: boolean;
isCheck?: boolean;
init() {
this.checkDeviceId = true;
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
this.allowUsePreInitialize = false;
const { payload } = this;
validateParams(payload, [
{ name: 'path', type: 'string', required: true },
{ name: 'message', type: 'string', required: true },
{ name: 'derivationType', type: 'number' },
{ name: 'networkId', type: 'number', required: true },
{ name: 'addressType', type: 'number' },
{ name: 'protocolMagic', type: 'number' },
]);
const addressN = validatePath(payload.path, 3);
this.params = {
address_n: addressN,
message: payload.message,
derivation_type:
typeof payload.derivationType !== 'undefined'
? payload.derivationType
: PROTO.CardanoDerivationType.ICARUS,
network_id: payload.networkId,
address_type: payload.addressType,
protocol_magic: payload.protocolMagic,
};
}
getVersionRange() {
return {
model_touch: {
min: '4.10.0',
},
};
}
getAddressTypeVersionRange() {
return {
pro: {
min: '4.9.3',
},
};
}
async run() {
this.checkFeatureVersionLimit(
() => this.params.address_type !== null && this.params.address_type !== undefined,
() => this.getAddressTypeVersionRange()
);
const res = await this.device.commands.typedCall(
'CardanoSignMessage',
'CardanoMessageSignature',
this.params
);
return res.message;
}
}