Skip to content

Commit 998a3f8

Browse files
committed
feat: upgrade modules
1 parent 421cb9e commit 998a3f8

15 files changed

+887
-401
lines changed

packages/evolution/src/Certificate.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,24 +176,14 @@ export const CDDLSchema = Schema.Union(
176176
Schema.Tuple(
177177
Schema.Literal(9n),
178178
Credential.CDDLSchema,
179-
Schema.Union(
180-
Schema.Tuple(Schema.Literal(0), Schema.Uint8ArrayFromSelf),
181-
Schema.Tuple(Schema.Literal(1), Schema.Uint8ArrayFromSelf),
182-
Schema.Tuple(Schema.Literal(2)),
183-
Schema.Tuple(Schema.Literal(3))
184-
)
179+
DRep.CDDLSchema
185180
),
186181
// 10: stake_vote_deleg_cert = (10, stake_credential, pool_keyhash, drep)
187182
Schema.Tuple(
188183
Schema.Literal(10n),
189184
Credential.CDDLSchema,
190185
CBOR.ByteArray,
191-
Schema.Union(
192-
Schema.Tuple(Schema.Literal(0), Schema.Uint8ArrayFromSelf),
193-
Schema.Tuple(Schema.Literal(1), Schema.Uint8ArrayFromSelf),
194-
Schema.Tuple(Schema.Literal(2)),
195-
Schema.Tuple(Schema.Literal(3))
196-
)
186+
DRep.CDDLSchema,
197187
),
198188
// 11: stake_reg_deleg_cert = (11, stake_credential, pool_keyhash, coin)
199189
Schema.Tuple(Schema.Literal(11n), Credential.CDDLSchema, CBOR.ByteArray, CBOR.Integer),

packages/evolution/src/DRep.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ export const DRep = Schema.Union(
4444
export type DRep = typeof DRep.Type
4545

4646
export const CDDLSchema = Schema.Union(
47-
Schema.Tuple(Schema.Literal(0), Schema.Uint8ArrayFromSelf),
48-
Schema.Tuple(Schema.Literal(1), Schema.Uint8ArrayFromSelf),
49-
Schema.Tuple(Schema.Literal(2)),
50-
Schema.Tuple(Schema.Literal(3))
47+
Schema.Tuple(Schema.Literal(0n), Schema.Uint8ArrayFromSelf),
48+
Schema.Tuple(Schema.Literal(1n), Schema.Uint8ArrayFromSelf),
49+
Schema.Tuple(Schema.Literal(2n)),
50+
Schema.Tuple(Schema.Literal(3n))
5151
)
5252

5353
/**
@@ -64,41 +64,41 @@ export const FromCDDL = Schema.transformOrFail(CDDLSchema, Schema.typeSchema(DRe
6464
switch (toA._tag) {
6565
case "KeyHashDRep": {
6666
const keyHashBytes = yield* ParseResult.encode(KeyHash.FromBytes)(toA.keyHash)
67-
return [0, keyHashBytes] as const
67+
return [0n, keyHashBytes] as const
6868
}
6969
case "ScriptHashDRep": {
7070
const scriptHashBytes = yield* ParseResult.encode(ScriptHash.FromBytes)(toA.scriptHash)
71-
return [1, scriptHashBytes] as const
71+
return [1n, scriptHashBytes] as const
7272
}
7373
case "AlwaysAbstainDRep":
74-
return [2] as const
74+
return [2n] as const
7575
case "AlwaysNoConfidenceDRep":
76-
return [3] as const
76+
return [3n] as const
7777
}
7878
}),
7979
decode: (fromA) =>
8080
Eff.gen(function* () {
8181
const [tag, ...rest] = fromA
8282
switch (tag) {
83-
case 0: {
83+
case 0n: {
8484
const keyHash = yield* ParseResult.decode(KeyHash.FromBytes)(rest[0] as Uint8Array)
8585
return yield* ParseResult.decode(DRep)({
8686
_tag: "KeyHashDRep",
8787
keyHash
8888
})
8989
}
90-
case 1: {
90+
case 1n: {
9191
const scriptHash = yield* ParseResult.decode(ScriptHash.FromBytes)(rest[0] as Uint8Array)
9292
return yield* ParseResult.decode(DRep)({
9393
_tag: "ScriptHashDRep",
9494
scriptHash
9595
})
9696
}
97-
case 2:
97+
case 2n:
9898
return yield* ParseResult.decode(DRep)({
9999
_tag: "AlwaysAbstainDRep"
100100
})
101-
case 3:
101+
case 3n:
102102
return yield* ParseResult.decode(DRep)({
103103
_tag: "AlwaysNoConfidenceDRep"
104104
})

packages/evolution/src/GovernanceAction.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export class ParameterChangeAction extends Schema.TaggedClass<ParameterChangeAct
8989
* @category schemas
9090
*/
9191
export const ParameterChangeActionCDDL = Schema.Tuple(
92-
Schema.Literal(0), // action type
92+
Schema.Literal(0n), // action type
9393
Schema.NullOr(GovActionIdCDDL), // gov_action_id / nil
9494
CBOR.RecordSchema, // protocol_param_update
9595
Schema.NullOr(CBOR.ByteArray) // policy_hash / nil
@@ -115,7 +115,7 @@ export const ParameterChangeActionFromCDDL = Schema.transformOrFail(
115115
const policyHash = action.policyHash ? yield* ParseResult.encode(ScriptHash.FromBytes)(action.policyHash) : null
116116

117117
// Return as CBOR tuple
118-
return [0, govActionId, protocolParamUpdate, policyHash] as const
118+
return [0n, govActionId, protocolParamUpdate, policyHash] as const
119119
}),
120120
decode: (cddl) =>
121121
Eff.gen(function* () {
@@ -157,7 +157,7 @@ export class HardForkInitiationAction extends Schema.TaggedClass<HardForkInitiat
157157
* @category schemas
158158
*/
159159
export const HardForkInitiationActionCDDL = Schema.Tuple(
160-
Schema.Literal(1), // action type
160+
Schema.Literal(1n), // action type
161161
Schema.NullOr(GovActionIdCDDL), // gov_action_id / nil
162162
Schema.Tuple(CBOR.Integer, CBOR.Integer), // protocol_version = [major, minor]
163163
Schema.NullOr(CBOR.ByteArray) // policy_hash / nil
@@ -183,7 +183,7 @@ export const HardForkInitiationActionFromCDDL = Schema.transformOrFail(
183183

184184
// Return as CBOR tuple
185185
return [
186-
1,
186+
1n,
187187
govActionId,
188188
[BigInt(action.protocolVersion[0]), BigInt(action.protocolVersion[1])],
189189
policyHash
@@ -231,7 +231,7 @@ export class TreasuryWithdrawalsAction extends Schema.TaggedClass<TreasuryWithdr
231231
* @category schemas
232232
*/
233233
export const TreasuryWithdrawalsActionCDDL = Schema.Tuple(
234-
Schema.Literal(2), // action type
234+
Schema.Literal(2n), // action type
235235
Schema.MapFromSelf({
236236
key: CBOR.ByteArray, // reward_account as bytes
237237
value: CBOR.Integer // coin as bigint
@@ -260,7 +260,7 @@ export const TreasuryWithdrawalsActionFromCDDL = Schema.transformOrFail(
260260
const policyHash = action.policyHash ? yield* ParseResult.encode(ScriptHash.FromBytes)(action.policyHash) : null
261261

262262
// Return as CBOR tuple
263-
return [2, withdrawals, policyHash] as const
263+
return [2n, withdrawals, policyHash] as const
264264
}),
265265
decode: (cddl) =>
266266
Eff.gen(function* () {
@@ -300,7 +300,7 @@ export class NoConfidenceAction extends Schema.TaggedClass<NoConfidenceAction>()
300300
* @category schemas
301301
*/
302302
export const NoConfidenceActionCDDL = Schema.Tuple(
303-
Schema.Literal(3), // action type
303+
Schema.Literal(3n), // action type
304304
Schema.NullOr(GovActionIdCDDL) // gov_action_id / nil
305305
)
306306

@@ -322,7 +322,7 @@ export const NoConfidenceActionFromCDDL = Schema.transformOrFail(
322322
: null
323323

324324
// Return as CBOR tuple
325-
return [3, govActionId] as const
325+
return [3n, govActionId] as const
326326
}),
327327
decode: (cddl) =>
328328
Eff.gen(function* () {
@@ -359,7 +359,7 @@ export class UpdateCommitteeAction extends Schema.TaggedClass<UpdateCommitteeAct
359359
* @category schemas
360360
*/
361361
export const UpdateCommitteeActionCDDL = Schema.Tuple(
362-
Schema.Literal(4), // action type
362+
Schema.Literal(4n), // action type
363363
Schema.NullOr(GovActionIdCDDL), // gov_action_id / nil
364364
Schema.Array(CBOR.CBORSchema), // set<committee_cold_credential>
365365
CBOR.MapSchema, // { * committee_cold_credential => committee_hot_credential }
@@ -387,7 +387,7 @@ export const UpdateCommitteeActionFromCDDL = Schema.transformOrFail(
387387
const threshold = yield* ParseResult.encode(CBOR.CBORSchema)(action.threshold)
388388

389389
// Return as CBOR tuple
390-
return [4, govActionId, membersToRemove, membersToAdd, threshold] as const
390+
return [4n, govActionId, membersToRemove, membersToAdd, threshold] as const
391391
}),
392392
decode: (cddl) =>
393393
Eff.gen(function* () {
@@ -425,7 +425,7 @@ export class NewConstitutionAction extends Schema.TaggedClass<NewConstitutionAct
425425
* @category schemas
426426
*/
427427
export const NewConstitutionActionCDDL = Schema.Tuple(
428-
Schema.Literal(5), // action type
428+
Schema.Literal(5n), // action type
429429
Schema.NullOr(GovActionIdCDDL), // gov_action_id / nil
430430
CBOR.CBORSchema // constitution
431431
)
@@ -449,7 +449,7 @@ export const NewConstitutionActionFromCDDL = Schema.transformOrFail(
449449
const constitution = yield* ParseResult.encode(CBOR.CBORSchema)(action.constitution)
450450

451451
// Return as CBOR tuple
452-
return [5, govActionId, constitution] as const
452+
return [5n, govActionId, constitution] as const
453453
}),
454454
decode: (cddl) =>
455455
Eff.gen(function* () {
@@ -483,7 +483,7 @@ export class InfoAction extends Schema.TaggedClass<InfoAction>()("InfoAction", {
483483
* @category schemas
484484
*/
485485
export const InfoActionCDDL = Schema.Tuple(
486-
Schema.Literal(6) // action type
486+
Schema.Literal(6n) // action type
487487
)
488488

489489
/**
@@ -497,7 +497,7 @@ export const InfoActionFromCDDL = Schema.transformOrFail(InfoActionCDDL, Schema.
497497
encode: (_action) =>
498498
Eff.gen(function* () {
499499
// Return as CBOR tuple
500-
return [6] as const
500+
return [6n] as const
501501
}),
502502
decode: (_cddl) =>
503503
Eff.gen(function* () {

packages/evolution/src/Mint.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@ export const policyCount = (mint: Mint): number => mint.size
219219
export const equals = (self: Mint, that: Mint): boolean => Equal.equals(self, that)
220220

221221
export const CDDLSchema = Schema.MapFromSelf({
222-
key: CBOR.ByteArray, // Policy ID as Uint8Array (28 bytes)
222+
key: CBOR.ByteArray, // Policy ID as 28-byte Uint8Array
223223
value: Schema.MapFromSelf({
224224
key: CBOR.ByteArray, // Asset name as Uint8Array (variable length)
225-
value: CBOR.Integer // Amount as number (will be converted to NonZeroInt64)
225+
value: CBOR.Integer // Amount as nonZeroInt64
226226
})
227227
})
228228

@@ -240,16 +240,16 @@ export const CDDLSchema = Schema.MapFromSelf({
240240
* @since 2.0.0
241241
* @category schemas
242242
*/
243-
export const MintCDDLSchema = Schema.transformOrFail(CDDLSchema, Schema.typeSchema(Mint), {
243+
export const FromCDDL = Schema.transformOrFail(Schema.encodedSchema(CDDLSchema), Schema.typeSchema(Mint), {
244244
strict: true,
245245
encode: (toA) =>
246246
Eff.gen(function* () {
247247
// Convert Mint to raw Map data for CBOR encoding
248-
const outerMap = new Map<Uint8Array, Map<Uint8Array, bigint>>()
248+
const outerMap = new Map() as Map<Uint8Array, Map<Uint8Array, bigint>>
249249

250250
for (const [policyId, assetMap] of toA.entries()) {
251251
const policyIdBytes = yield* ParseResult.encode(PolicyId.FromBytes)(policyId)
252-
const innerMap = new Map<Uint8Array, bigint>()
252+
const innerMap = new Map() as Map<Uint8Array, bigint>
253253

254254
for (const [assetName, amount] of assetMap.entries()) {
255255
const assetNameBytes = yield* ParseResult.encode(AssetName.FromBytes)(assetName)
@@ -294,7 +294,7 @@ export const MintCDDLSchema = Schema.transformOrFail(CDDLSchema, Schema.typeSche
294294
export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) =>
295295
Schema.compose(
296296
CBOR.FromBytes(options), // Uint8Array → CBOR
297-
MintCDDLSchema // CBOR → Mint
297+
FromCDDL // CBOR → Mint
298298
).annotations({
299299
identifier: "Mint.FromCBORBytes",
300300
title: "Mint from CBOR Bytes",

packages/evolution/src/Pointer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Schema, FastCheck } from "effect"
1+
import { FastCheck,Schema } from "effect"
22

33
import * as Natural from "./Natural.js"
44

packages/evolution/src/PrivateKey.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { wordlist } from "@scure/bip39/wordlists/english"
55
import { Data, Effect as Eff, FastCheck, ParseResult, Schema } from "effect"
66
import sodium from "libsodium-wrappers-sumo"
77

8-
import { Bytes32, Bytes64, VKey } from "./index.js"
8+
import * as Bytes32 from "./Bytes32.js"
9+
import * as Bytes64 from "./Bytes64.js"
10+
import * as VKey from "./VKey.js"
911

1012
/**
1113
* Error class for PrivateKey related operations.

0 commit comments

Comments
 (0)