@onekeyfe/hd-core 1.0.20 → 1.0.21

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.
@@ -8,41 +8,65 @@ import { validateParams } from '../../helpers/paramsValidator';
8
8
  import { validatePath } from '../../helpers/pathUtils';
9
9
  import type {
10
10
  CardanoAuxiliaryData,
11
- CardanoGovernanceRegistrationDelegation,
12
- CardanoGovernanceRegistrationParameters,
11
+ CardanoCVoteRegistrationParameters,
12
+ CardanoCVoteRegistrationDelegation,
13
13
  } from '../../../types/api/cardano';
14
14
  import { PROTO } from '../../../constants';
15
15
 
16
16
  const MAX_DELEGATION_COUNT = 32;
17
17
 
18
18
  const transformDelegation = (
19
- delegation: CardanoGovernanceRegistrationDelegation
20
- ): PROTO.CardanoGovernanceRegistrationDelegation => {
19
+ delegation: CardanoCVoteRegistrationDelegation
20
+ ): PROTO.CardanoCVoteRegistrationDelegation => {
21
+ // @ts-expect-error votingPublicKey is a legacy param kept for backward compatibility (for now)
22
+ if (delegation.votingPublicKey) {
23
+ console.warn('Please use votePublicKey instead of votingPublicKey.');
24
+ // @ts-expect-error
25
+ delegation.votePublicKey = delegation.votingPublicKey;
26
+ }
27
+
21
28
  validateParams(delegation, [
22
29
  { name: 'votingPublicKey', type: 'string', required: true },
23
30
  { name: 'weight', type: 'uint', required: true },
24
31
  ]);
25
32
 
26
33
  return {
27
- voting_public_key: delegation.votingPublicKey,
34
+ vote_public_key: delegation.votePublicKey,
28
35
  weight: delegation.weight,
29
36
  };
30
37
  };
31
38
 
32
- const transformGovernanceRegistrationParameters = (
33
- governanceRegistrationParameters: CardanoGovernanceRegistrationParameters
34
- ): PROTO.CardanoGovernanceRegistrationParametersType => {
35
- validateParams(governanceRegistrationParameters, [
36
- { name: 'votingPublicKey', type: 'string' },
39
+ const transformCvoteRegistrationParameters = (
40
+ cVoteRegistrationParameters: CardanoCVoteRegistrationParameters
41
+ ): PROTO.CardanoCVoteRegistrationParametersType => {
42
+ // votingPublicKey and rewardAddressParameters are legacy params kept for backward compatibility (for now)
43
+ // @ts-expect-error
44
+ if (cVoteRegistrationParameters.votingPublicKey) {
45
+ console.warn('Please use votePublicKey instead of votingPublicKey.');
46
+ // @ts-expect-error
47
+ cVoteRegistrationParameters.votePublicKey = cVoteRegistrationParameters.votingPublicKey;
48
+ }
49
+ // @ts-expect-error
50
+ if (cVoteRegistrationParameters.rewardAddressParameters) {
51
+ console.warn('Please use paymentAddressParameters instead of rewardAddressParameters.');
52
+ cVoteRegistrationParameters.paymentAddressParameters =
53
+ // @ts-expect-error
54
+ cVoteRegistrationParameters.rewardAddressParameters;
55
+ }
56
+
57
+ validateParams(cVoteRegistrationParameters, [
58
+ { name: 'votePublicKey', type: 'string' },
37
59
  { name: 'stakingPath', required: true },
38
60
  { name: 'nonce', type: 'uint', required: true },
39
61
  { name: 'format', type: 'number' },
40
62
  { name: 'delegations', type: 'array', allowEmpty: true },
41
63
  { name: 'votingPurpose', type: 'uint' },
64
+ { name: 'paymentAddress', type: 'string' },
42
65
  ]);
43
- validateAddressParameters(governanceRegistrationParameters.rewardAddressParameters);
66
+ const { paymentAddressParameters } = cVoteRegistrationParameters;
67
+ validateAddressParameters(paymentAddressParameters);
44
68
 
45
- const { delegations } = governanceRegistrationParameters;
69
+ const { delegations } = cVoteRegistrationParameters;
46
70
  if (delegations && delegations.length > MAX_DELEGATION_COUNT) {
47
71
  throw ERRORS.TypedError(
48
72
  HardwareErrorCode.CallMethodInvalidParameter,
@@ -51,15 +75,16 @@ const transformGovernanceRegistrationParameters = (
51
75
  }
52
76
 
53
77
  return {
54
- voting_public_key: governanceRegistrationParameters.votingPublicKey,
55
- staking_path: validatePath(governanceRegistrationParameters.stakingPath, 3),
56
- reward_address_parameters: addressParametersToProto(
57
- governanceRegistrationParameters.rewardAddressParameters
58
- ),
59
- nonce: governanceRegistrationParameters.nonce as unknown as number,
60
- format: governanceRegistrationParameters.format,
61
- delegations: delegations?.map(transformDelegation) as any,
62
- voting_purpose: governanceRegistrationParameters.votingPurpose,
78
+ vote_public_key: cVoteRegistrationParameters.votePublicKey,
79
+ staking_path: validatePath(cVoteRegistrationParameters.stakingPath, 3),
80
+ payment_address_parameters: paymentAddressParameters
81
+ ? addressParametersToProto(paymentAddressParameters)
82
+ : undefined,
83
+ nonce: cVoteRegistrationParameters.nonce as unknown as number,
84
+ format: cVoteRegistrationParameters.format,
85
+ delegations: delegations?.map(transformDelegation) ?? [],
86
+ voting_purpose: cVoteRegistrationParameters.votingPurpose,
87
+ payment_address: cVoteRegistrationParameters.paymentAddress,
63
88
  };
64
89
  };
65
90
 
@@ -73,32 +98,32 @@ export const transformAuxiliaryData = (
73
98
  },
74
99
  ]);
75
100
 
76
- let governanceRegistrationParameters;
77
- if (auxiliaryData.governanceRegistrationParameters) {
78
- governanceRegistrationParameters = transformGovernanceRegistrationParameters(
79
- auxiliaryData.governanceRegistrationParameters
101
+ let cVoteRegistrationParameters;
102
+ if (auxiliaryData.cVoteRegistrationParameters) {
103
+ cVoteRegistrationParameters = transformCvoteRegistrationParameters(
104
+ auxiliaryData.cVoteRegistrationParameters
80
105
  );
81
106
  }
82
107
 
83
108
  return {
84
109
  hash: auxiliaryData.hash,
85
- governance_registration_parameters: governanceRegistrationParameters,
110
+ cvote_registration_parameters: cVoteRegistrationParameters,
86
111
  };
87
112
  };
88
113
 
89
114
  export const modifyAuxiliaryDataForBackwardsCompatibility = (
90
115
  auxiliary_data: PROTO.CardanoTxAuxiliaryData
91
116
  ): PROTO.CardanoTxAuxiliaryData => {
92
- const { governance_registration_parameters } = auxiliary_data;
93
- if (governance_registration_parameters) {
94
- governance_registration_parameters.reward_address_parameters =
117
+ const { cvote_registration_parameters } = auxiliary_data;
118
+ if (cvote_registration_parameters?.payment_address_parameters) {
119
+ cvote_registration_parameters.payment_address_parameters =
95
120
  modifyAddressParametersForBackwardsCompatibility(
96
- governance_registration_parameters.reward_address_parameters
121
+ cvote_registration_parameters.payment_address_parameters
97
122
  );
98
123
 
99
124
  return {
100
125
  ...auxiliary_data,
101
- governance_registration_parameters,
126
+ cvote_registration_parameters,
102
127
  };
103
128
  }
104
129
 
@@ -9,6 +9,7 @@ import type {
9
9
  CardanoPoolMetadata,
10
10
  CardanoPoolRelay,
11
11
  CardanoPoolOwner,
12
+ CardanoDRep,
12
13
  } from '../../../types/api/cardano';
13
14
  import { PROTO } from '../../../constants';
14
15
 
@@ -156,6 +157,37 @@ const transformPoolParameters = (
156
157
  };
157
158
  };
158
159
 
160
+ const transformDRep = (dRep: CardanoDRep | undefined): PROTO.CardanoDRep | undefined => {
161
+ if (!dRep) {
162
+ return undefined;
163
+ }
164
+
165
+ validateParams(dRep, [
166
+ { name: 'type', type: 'number', required: true },
167
+ { name: 'keyHash', type: 'string' },
168
+ { name: 'scriptHash', type: 'string' },
169
+ ]);
170
+
171
+ if (dRep.type === PROTO.CardanoDRepType.KEY_HASH && !dRep.keyHash) {
172
+ throw ERRORS.TypedError(
173
+ HardwareErrorCode.CallMethodInvalidParameter,
174
+ 'key_hash must be supplied for key_hash type'
175
+ );
176
+ }
177
+
178
+ if (dRep.type === PROTO.CardanoDRepType.SCRIPT_HASH && !dRep.scriptHash) {
179
+ throw ERRORS.TypedError(
180
+ HardwareErrorCode.CallMethodInvalidParameter,
181
+ 'script_hash must be supplied for script_hash type'
182
+ );
183
+ }
184
+ return {
185
+ type: dRep.type,
186
+ key_hash: dRep.keyHash,
187
+ script_hash: dRep.scriptHash,
188
+ };
189
+ };
190
+
159
191
  export const transformCertificate = (
160
192
  certificate: CardanoCertificate
161
193
  ): CertificateWithPoolOwnersAndRelays => {
@@ -176,12 +208,25 @@ export const transformCertificate = (
176
208
  paramsToValidate.push({ name: 'poolParameters', type: 'object', required: true });
177
209
  }
178
210
 
211
+ if (
212
+ certificate.type === PROTO.CardanoCertificateType.STAKE_REGISTRATION_CONWAY ||
213
+ certificate.type === PROTO.CardanoCertificateType.STAKE_DEREGISTRATION_CONWAY
214
+ ) {
215
+ paramsToValidate.push({ name: 'deposit', required: true });
216
+ }
217
+
218
+ if (certificate.type === PROTO.CardanoCertificateType.VOTE_DELEGATION) {
219
+ paramsToValidate.push({ name: 'dRep', type: 'object', required: true });
220
+ }
221
+
179
222
  validateParams(certificate, paramsToValidate);
180
223
 
181
224
  const { poolParameters, poolOwners, poolRelays } = transformPoolParameters(
182
225
  certificate.poolParameters
183
226
  );
184
227
 
228
+ const dRep = transformDRep(certificate.dRep);
229
+
185
230
  return {
186
231
  certificate: {
187
232
  type: certificate.type,
@@ -190,6 +235,8 @@ export const transformCertificate = (
190
235
  key_hash: certificate.keyHash,
191
236
  pool: certificate.pool,
192
237
  pool_parameters: poolParameters,
238
+ deposit: certificate.deposit,
239
+ drep: dRep,
193
240
  },
194
241
  poolOwners,
195
242
  poolRelays,
@@ -345,7 +345,6 @@
345
345
  "BenfenAddress": {
346
346
  "fields": {
347
347
  "address": {
348
- "rule": "required",
349
348
  "type": "string",
350
349
  "id": 1
351
350
  }
@@ -2016,7 +2015,18 @@
2016
2015
  "STAKE_REGISTRATION": 0,
2017
2016
  "STAKE_DEREGISTRATION": 1,
2018
2017
  "STAKE_DELEGATION": 2,
2019
- "STAKE_POOL_REGISTRATION": 3
2018
+ "STAKE_POOL_REGISTRATION": 3,
2019
+ "STAKE_REGISTRATION_CONWAY": 7,
2020
+ "STAKE_DEREGISTRATION_CONWAY": 8,
2021
+ "VOTE_DELEGATION": 9
2022
+ }
2023
+ },
2024
+ "CardanoDRepType": {
2025
+ "values": {
2026
+ "KEY_HASH": 0,
2027
+ "SCRIPT_HASH": 1,
2028
+ "ABSTAIN": 2,
2029
+ "NO_CONFIDENCE": 3
2020
2030
  }
2021
2031
  },
2022
2032
  "CardanoPoolRelayType": {
@@ -2029,10 +2039,10 @@
2029
2039
  "CardanoTxAuxiliaryDataSupplementType": {
2030
2040
  "values": {
2031
2041
  "NONE": 0,
2032
- "GOVERNANCE_REGISTRATION_SIGNATURE": 1
2042
+ "CVOTE_REGISTRATION_SIGNATURE": 1
2033
2043
  }
2034
2044
  },
2035
- "CardanoGovernanceRegistrationFormat": {
2045
+ "CardanoCVoteRegistrationFormat": {
2036
2046
  "values": {
2037
2047
  "CIP15": 0,
2038
2048
  "CIP36": 1
@@ -2206,6 +2216,10 @@
2206
2216
  "rule": "required",
2207
2217
  "type": "CardanoDerivationType",
2208
2218
  "id": 6
2219
+ },
2220
+ "chunkify": {
2221
+ "type": "bool",
2222
+ "id": 7
2209
2223
  }
2210
2224
  }
2211
2225
  },
@@ -2361,6 +2375,17 @@
2361
2375
  "options": {
2362
2376
  "default": 0
2363
2377
  }
2378
+ },
2379
+ "chunkify": {
2380
+ "type": "bool",
2381
+ "id": 22
2382
+ },
2383
+ "tag_cbor_sets": {
2384
+ "type": "bool",
2385
+ "id": 23,
2386
+ "options": {
2387
+ "default": false
2388
+ }
2364
2389
  }
2365
2390
  }
2366
2391
  },
@@ -2582,6 +2607,23 @@
2582
2607
  }
2583
2608
  }
2584
2609
  },
2610
+ "CardanoDRep": {
2611
+ "fields": {
2612
+ "type": {
2613
+ "rule": "required",
2614
+ "type": "CardanoDRepType",
2615
+ "id": 1
2616
+ },
2617
+ "key_hash": {
2618
+ "type": "bytes",
2619
+ "id": 2
2620
+ },
2621
+ "script_hash": {
2622
+ "type": "bytes",
2623
+ "id": 3
2624
+ }
2625
+ }
2626
+ },
2585
2627
  "CardanoTxCertificate": {
2586
2628
  "fields": {
2587
2629
  "type": {
@@ -2612,6 +2654,14 @@
2612
2654
  "key_hash": {
2613
2655
  "type": "bytes",
2614
2656
  "id": 6
2657
+ },
2658
+ "deposit": {
2659
+ "type": "uint64",
2660
+ "id": 7
2661
+ },
2662
+ "drep": {
2663
+ "type": "CardanoDRep",
2664
+ "id": 8
2615
2665
  }
2616
2666
  }
2617
2667
  },
@@ -2640,9 +2690,9 @@
2640
2690
  }
2641
2691
  }
2642
2692
  },
2643
- "CardanoGovernanceRegistrationDelegation": {
2693
+ "CardanoCVoteRegistrationDelegation": {
2644
2694
  "fields": {
2645
- "voting_public_key": {
2695
+ "vote_public_key": {
2646
2696
  "rule": "required",
2647
2697
  "type": "bytes",
2648
2698
  "id": 1
@@ -2654,9 +2704,9 @@
2654
2704
  }
2655
2705
  }
2656
2706
  },
2657
- "CardanoGovernanceRegistrationParametersType": {
2707
+ "CardanoCVoteRegistrationParametersType": {
2658
2708
  "fields": {
2659
- "voting_public_key": {
2709
+ "vote_public_key": {
2660
2710
  "type": "bytes",
2661
2711
  "id": 1
2662
2712
  },
@@ -2668,8 +2718,7 @@
2668
2718
  "packed": false
2669
2719
  }
2670
2720
  },
2671
- "reward_address_parameters": {
2672
- "rule": "required",
2721
+ "payment_address_parameters": {
2673
2722
  "type": "CardanoAddressParametersType",
2674
2723
  "id": 3
2675
2724
  },
@@ -2679,7 +2728,7 @@
2679
2728
  "id": 4
2680
2729
  },
2681
2730
  "format": {
2682
- "type": "CardanoGovernanceRegistrationFormat",
2731
+ "type": "CardanoCVoteRegistrationFormat",
2683
2732
  "id": 5,
2684
2733
  "options": {
2685
2734
  "default": "CIP15"
@@ -2687,19 +2736,23 @@
2687
2736
  },
2688
2737
  "delegations": {
2689
2738
  "rule": "repeated",
2690
- "type": "CardanoGovernanceRegistrationDelegation",
2739
+ "type": "CardanoCVoteRegistrationDelegation",
2691
2740
  "id": 6
2692
2741
  },
2693
2742
  "voting_purpose": {
2694
2743
  "type": "uint64",
2695
2744
  "id": 7
2745
+ },
2746
+ "payment_address": {
2747
+ "type": "string",
2748
+ "id": 8
2696
2749
  }
2697
2750
  }
2698
2751
  },
2699
2752
  "CardanoTxAuxiliaryData": {
2700
2753
  "fields": {
2701
- "governance_registration_parameters": {
2702
- "type": "CardanoGovernanceRegistrationParametersType",
2754
+ "cvote_registration_parameters": {
2755
+ "type": "CardanoCVoteRegistrationParametersType",
2703
2756
  "id": 1
2704
2757
  },
2705
2758
  "hash": {
@@ -2775,7 +2828,7 @@
2775
2828
  "type": "bytes",
2776
2829
  "id": 2
2777
2830
  },
2778
- "governance_signature": {
2831
+ "cvote_registration_signature": {
2779
2832
  "type": "bytes",
2780
2833
  "id": 3
2781
2834
  }
@@ -1,3 +1,4 @@
1
+ import type { UintType } from '@onekeyfe/hd-transport';
1
2
  import type { PROTO } from '../../constants';
2
3
 
3
4
  export interface CardanoAddressParameters {
@@ -32,6 +33,12 @@ export type AssetGroupWithTokens = {
32
33
  tokens: PROTO.CardanoToken[];
33
34
  };
34
35
 
36
+ export interface CardanoDRep {
37
+ type: PROTO.CardanoDRepType;
38
+ keyHash?: string;
39
+ scriptHash?: string;
40
+ }
41
+
35
42
  export interface CardanoCertificate {
36
43
  type: PROTO.CardanoCertificateType;
37
44
  path?: string | number[];
@@ -39,6 +46,8 @@ export interface CardanoCertificate {
39
46
  poolParameters?: CardanoPoolParameters;
40
47
  scriptHash?: string;
41
48
  keyHash?: string;
49
+ deposit?: UintType;
50
+ dRep?: CardanoDRep;
42
51
  }
43
52
 
44
53
  export type CertificateWithPoolOwnersAndRelays = {
@@ -129,8 +138,8 @@ export interface CardanoReferenceInput {
129
138
  prev_index: number;
130
139
  }
131
140
 
132
- export interface CardanoGovernanceRegistrationDelegation {
133
- votingPublicKey: string;
141
+ export interface CardanoCVoteRegistrationDelegation {
142
+ votePublicKey: string;
134
143
  weight: number;
135
144
  }
136
145
 
@@ -141,19 +150,20 @@ export interface CardanoCatalystRegistrationParameters {
141
150
  nonce: string;
142
151
  }
143
152
 
144
- export interface CardanoGovernanceRegistrationParameters {
145
- votingPublicKey?: string;
153
+ export interface CardanoCVoteRegistrationParameters {
154
+ votePublicKey?: string;
146
155
  stakingPath: string | number[];
147
- rewardAddressParameters: CardanoAddressParameters;
156
+ paymentAddressParameters: CardanoAddressParameters;
148
157
  nonce: string;
149
- format?: PROTO.CardanoGovernanceRegistrationFormat;
150
- delegations?: CardanoGovernanceRegistrationDelegation[];
158
+ format?: PROTO.CardanoCVoteRegistrationFormat;
159
+ delegations?: CardanoCVoteRegistrationDelegation[];
151
160
  votingPurpose?: number;
161
+ paymentAddress?: string;
152
162
  }
153
163
 
154
164
  export interface CardanoAuxiliaryData {
155
165
  hash?: string;
156
- governanceRegistrationParameters?: CardanoGovernanceRegistrationParameters;
166
+ cVoteRegistrationParameters?: CardanoCVoteRegistrationParameters;
157
167
  }
158
168
 
159
169
  export interface CardanoSignTransaction {
@@ -178,6 +188,8 @@ export interface CardanoSignTransaction {
178
188
  signingMode: PROTO.CardanoTxSigningMode;
179
189
  derivationType?: PROTO.CardanoDerivationType;
180
190
  includeNetworkId?: boolean;
191
+ chunkify?: boolean;
192
+ tagCborSets?: boolean;
181
193
  }
182
194
 
183
195
  export interface CardanoSignedTxWitness {
@@ -190,7 +202,7 @@ export interface CardanoSignedTxWitness {
190
202
  export interface CardanoAuxiliaryDataSupplement {
191
203
  type: PROTO.CardanoTxAuxiliaryDataSupplementType;
192
204
  auxiliaryDataHash: string;
193
- catalystSignature?: string;
205
+ cVoteRegistrationSignature?: string;
194
206
  }
195
207
 
196
208
  export interface CardanoSignedTxData {