Skip to content

Commit

Permalink
feat: readonly members
Browse files Browse the repository at this point in the history
  • Loading branch information
sublimator authored and armfazh committed Sep 2, 2023
1 parent ce51aa8 commit 44f96ab
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
21 changes: 7 additions & 14 deletions src/groupNoble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,21 +301,14 @@ class GroupNb implements Group {
return ScalarNb.hash(this, msg, dst)
}

eltDes: Deserializer<EltNb> = {
size: (compressed?: boolean) => {
return this.eltSize(compressed)
},
deserialize: (b: Uint8Array) => {
return this.desElt(b)
}
readonly eltDes: Deserializer<EltNb> = {
size: (compressed) => this.eltSize(compressed),
deserialize: (b) => this.desElt(b)
}
scalarDes: Deserializer<ScalarNb> = {
size: () => {
return this.scalarSize()
},
deserialize: (b: Uint8Array) => {
return this.desScalar(b)
}

readonly scalarDes: Deserializer<ScalarNb> = {
size: () => this.scalarSize(),
deserialize: (b) => this.desScalar(b)
}

desElt(bytes: Uint8Array): EltNb {
Expand Down
31 changes: 16 additions & 15 deletions src/groupSjcl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@
import { checkSize, joinAll, xor } from './util.js'

import sjcl from './sjcl/index.js'
import { Elt, errBadGroup, Group, GroupCons, GroupID, GroupIDs, Scalar } from './groupTypes.js'
import {
Deserializer,
Elt,
errBadGroup,
Group,
GroupCons,
GroupID,
GroupIDs,
Scalar
} from './groupTypes.js'

function errDeserialization(T: { name: string }) {
return new Error(`group: deserialization of ${T.name} failed.`)
Expand Down Expand Up @@ -530,25 +539,17 @@ class GroupSj implements Group {
return ScalarSj.hash(this, msg, dst)
}

get eltDes() {
get eltDes(): Deserializer<EltSj> {
return {
size: (compressed?: boolean): number => {
return EltSj.size(this, compressed)
},
deserialize: (b: Uint8Array): EltSj => {
return EltSj.deserialize(this, b)
}
size: (compressed): number => EltSj.size(this, compressed),
deserialize: (b) => EltSj.deserialize(this, b)
}
}

get scalarDes() {
get scalarDes(): Deserializer<ScalarSj> {
return {
size: (): number => {
return ScalarSj.size(this)
},
deserialize: (b: Uint8Array): ScalarSj => {
return ScalarSj.deserialize(this, b)
}
size: () => ScalarSj.size(this),
deserialize: (b) => ScalarSj.deserialize(this, b)
}
}

Expand Down

0 comments on commit 44f96ab

Please sign in to comment.