/
internal.ts
273 lines (224 loc) · 7.5 KB
/
internal.ts
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
import { AddressType, CertificateType, PoolKeyType, PoolOwnerType, PoolRewardAccountType, RelayType, TransactionSigningMode, TxAuxiliaryDataType, TxOutputDestinationType } from './public'
// Basic primitives
export type VarlenAsciiString = string & { __type: 'ascii' }
export type FixlenHexString<N> = string & { __type: 'hex', __length: N }
export type HexString = string & { __type: 'hex' }
export type _Uint64_num = number & { __type: 'uint64_t' }
export type _Uint64_bigint = bigint & { __type: 'uint64_t' }
export type ValidBIP32Path = Array<Uint32_t> & { __type: 'bip32_path' }
export type Uint64_str = string & { __type: 'uint64_t' }
export type Uint32_t = number & { __type: 'uint32_t' }
export type Uint16_t = number & { __type: 'uint16_t' }
export type Uint8_t = number & { __type: 'uint8_t' }
export type Int64_str = string & { __type: 'int64_t' }
export type _Int64_num = number & { __type: 'int64_t' }
export type _Int64_bigint = bigint & { __type: 'int64_t' }
// Reexport blockchain spec
export { AddressType, CertificateType, RelayType, PoolKeyType, PoolOwnerType, PoolRewardAccountType, TransactionSigningMode, TxAuxiliaryDataType, TxOutputDestinationType }
export { Version, DeviceCompatibility } from './public'
// Our types
export const EXTENDED_PUBLIC_KEY_LENGTH = 64
export const KEY_HASH_LENGTH = 28
export const TX_HASH_LENGTH = 32
export const AUXILIARY_DATA_HASH_LENGTH = 32
export const KES_PUBLIC_KEY_LENGTH = 32
export const VRF_KEY_HASH_LENGTH = 32
export const REWARD_ACCOUNT_HEX_LENGTH = 29
export const ED25519_SIGNATURE_LENGTH = 64
export type ParsedCertificate = {
type: CertificateType.STAKE_REGISTRATION
path: ValidBIP32Path
} | {
type: CertificateType.STAKE_DEREGISTRATION
path: ValidBIP32Path
} | {
type: CertificateType.STAKE_DELEGATION
path: ValidBIP32Path
poolKeyHashHex: FixlenHexString<typeof KEY_HASH_LENGTH>
} | {
type: CertificateType.STAKE_POOL_REGISTRATION
pool: ParsedPoolParams
} | {
type: CertificateType.STAKE_POOL_RETIREMENT
path: ValidBIP32Path
retirementEpoch: Uint64_str
}
export const TOKEN_POLICY_LENGTH = 28
export type ParsedToken<Type> = {
assetNameHex: HexString,
amount: Type,
};
export type ParsedAssetGroup<Type> = {
policyIdHex: FixlenHexString<typeof TOKEN_POLICY_LENGTH>,
tokens: Array<ParsedToken<Type>>,
};
export type ParsedNetwork = {
protocolMagic: Uint32_t
networkId: Uint8_t
}
export const CATALYST_VOTING_PUBLIC_KEY_LENGTH = 32
export type CatalystVotingPublicKey = FixlenHexString<typeof CATALYST_VOTING_PUBLIC_KEY_LENGTH>
export type ParsedTxAuxiliaryData = {
type: TxAuxiliaryDataType.ARBITRARY_HASH
hashHex: FixlenHexString<typeof AUXILIARY_DATA_HASH_LENGTH>
} | {
type: TxAuxiliaryDataType.CATALYST_REGISTRATION
params: ParsedCatalystRegistrationParams
}
export type ParsedCatalystRegistrationParams = {
type: TxAuxiliaryDataType.CATALYST_REGISTRATION,
votingPublicKey: CatalystVotingPublicKey
stakingPath: ValidBIP32Path
rewardsDestination: ShelleyAddressParams
nonce: Uint64_str
}
export type ParsedTransaction = {
network: ParsedNetwork
inputs: ParsedInput[]
outputs: ParsedOutput[]
fee: Uint64_str
ttl: Uint64_str | null
certificates: ParsedCertificate[]
withdrawals: ParsedWithdrawal[]
auxiliaryData: ParsedTxAuxiliaryData | null
validityIntervalStart: Uint64_str | null
mintInstructions: Array<ParsedAssetGroup<Int64_str>> | null
}
export type ParsedSigningRequest = {
tx: ParsedTransaction
signingMode: TransactionSigningMode
}
export type ParsedInput = {
txHashHex: FixlenHexString<typeof TX_HASH_LENGTH>
outputIndex: Uint32_t
path: ValidBIP32Path | null
}
export type ParsedWithdrawal = {
amount: Uint64_str
path: ValidBIP32Path
}
export type ParsedMargin = {
numerator: Uint64_str,
denominator: Uint64_str
}
export type ParsedPoolParams = {
poolKey: ParsedPoolKey,
vrfHashHex: FixlenHexString<typeof VRF_KEY_HASH_LENGTH>,
pledge: Uint64_str,
cost: Uint64_str,
margin: ParsedMargin,
rewardAccount: ParsedPoolRewardAccount,
owners: ParsedPoolOwner[],
relays: ParsedPoolRelay[],
metadata: ParsedPoolMetadata | null
}
export type ParsedPoolKey = {
type: PoolKeyType.DEVICE_OWNED,
path: ValidBIP32Path
} | {
type: PoolKeyType.THIRD_PARTY
hashHex: FixlenHexString<typeof KEY_HASH_LENGTH>
}
export type ParsedPoolOwner = {
type: PoolOwnerType.DEVICE_OWNED,
path: ValidBIP32Path
} | {
type: PoolOwnerType.THIRD_PARTY
hashHex: FixlenHexString<typeof KEY_HASH_LENGTH>
}
export type ParsedPoolRewardAccount = {
type: PoolRewardAccountType.DEVICE_OWNED,
path: ValidBIP32Path
} | {
type: PoolRewardAccountType.THIRD_PARTY
rewardAccountHex: FixlenHexString<typeof REWARD_ACCOUNT_HEX_LENGTH>
}
export type ParsedPoolRelay = {
type: RelayType.SINGLE_HOST_IP_ADDR,
port: Uint16_t | null,
ipv4: Buffer | null,
ipv6: Buffer | null,
} | {
type: RelayType.SINGLE_HOST_HOSTNAME,
port: Uint16_t | null,
dnsName: VarlenAsciiString,
} | {
type: RelayType.MULTI_HOST,
dnsName: VarlenAsciiString
}
export type ParsedPoolMetadata = {
url: VarlenAsciiString,
hashHex: FixlenHexString<32>,
} & { __brand: 'pool_metadata' }
export const enum StakingChoiceType {
NO_STAKING = 'no_staking',
STAKING_KEY_PATH = 'staking_key_path',
STAKING_KEY_HASH = 'staking_key_hash',
BLOCKCHAIN_POINTER = 'blockchain_pointer',
}
type ParsedBlockchainPointer = {
blockIndex: Uint32_t,
txIndex: Uint32_t,
certificateIndex: Uint32_t,
}
type StakingChoiceNone = {
type: StakingChoiceType.NO_STAKING
}
type StakingChoicePath = {
type: StakingChoiceType.STAKING_KEY_PATH,
path: ValidBIP32Path
}
type StakingChoiceHash = {
type: StakingChoiceType.STAKING_KEY_HASH,
hashHex: FixlenHexString<typeof KEY_HASH_LENGTH>
}
type StakingChoicePointer = {
type: StakingChoiceType.BLOCKCHAIN_POINTER,
pointer: ParsedBlockchainPointer
}
export type StakingChoice = StakingChoiceNone | StakingChoicePath | StakingChoiceHash | StakingChoicePointer
export type ByronAddressParams = {
type: AddressType.BYRON,
protocolMagic: Uint32_t
spendingPath: ValidBIP32Path,
stakingChoice: StakingChoiceNone,
}
export type ShelleyAddressParams = {
type: AddressType.BASE | AddressType.ENTERPRISE | AddressType.POINTER | AddressType.REWARD,
networkId: Uint8_t,
spendingPath: ValidBIP32Path
} & ( // Extra properties
{
type: AddressType.BASE,
stakingChoice: StakingChoicePath | StakingChoiceHash
} | {
type: AddressType.ENTERPRISE,
stakingChoice: StakingChoiceNone
} | {
type: AddressType.POINTER,
stakingChoice: StakingChoicePointer
} | {
type: AddressType.REWARD
stakingChoice: StakingChoiceNone // included in spending path
}
)
export type ParsedAddressParams = ByronAddressParams | ShelleyAddressParams
export type OutputDestination = {
type: TxOutputDestinationType.THIRD_PARTY
addressHex: HexString
} | {
type: TxOutputDestinationType.DEVICE_OWNED
addressParams: ParsedAddressParams
}
export type ParsedOutput = {
amount: Uint64_str
tokenBundle: ParsedAssetGroup<Uint64_str>[]
destination: OutputDestination
}
export const ASSET_NAME_LENGTH_MAX = 32
export type ParsedOperationalCertificate = {
kesPublicKeyHex: FixlenHexString<typeof KES_PUBLIC_KEY_LENGTH>,
kesPeriod: Uint64_str,
issueCounter: Uint64_str,
coldKeyPath: ValidBIP32Path,
}