Skip to content

Commit

Permalink
fix: improve typedefs
Browse files Browse the repository at this point in the history
  • Loading branch information
getlarge committed Mar 11, 2021
1 parent 1c308fb commit 1990100
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/lib/condition.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class Condition {
if (type.Class.TYPE_CATEGORY === 'compound') {
condition.setSubtypes(new Set(query.subtypes.split(',')))
} else {
// ? Should be bitmask number ?
condition.setSubtypes(new Set())
}
condition.setHash(base64url.decode(parsed[1]))
Expand Down
2 changes: 2 additions & 0 deletions src/util/buffer-to-uint-array.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

module.exports = function bufferToUint8Array (buffer) {
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / Uint8Array.BYTES_PER_ELEMENT)
}
16 changes: 9 additions & 7 deletions types/lib/condition.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TypeAsn1Condition } from '../types';
import { TypeAsn1Condition, TypeId, TypeName } from '../types';

export interface ConditionAsn1Json {
type: TypeAsn1Condition;
Expand All @@ -13,8 +13,10 @@ export interface ConditionAsn1Json {
}

export default class Condition {
// TODO: in which cases subtypes is number ?
private subtypes: Set<string> | number;
private type?: TypeId;
private subtypes?: Set<TypeName> | number;
private hash?: Buffer;
private cost?: number;

static readonly MAX_SAFE_SUBTYPES = 0xffffffff;
static readonly SUPPORTED_SUBTYPES = 0x3f;
Expand All @@ -33,14 +35,14 @@ export default class Condition {

getTypeId(): number;

setTypeId(type: number): void;
setTypeId(type: TypeId): void;

getTypeName(): string;

//? Should be Set<string>
getSubtypes(): Set<string> | number;
//TODO: improve base on Condition typeCategory, if compound : Set<TypeName>, if simple : number
getSubtypes(): Set<TypeName> | number;

setSubtypes(subtypes: Set<string> | number): void;
setSubtypes(subtypes: Set<TypeName> | number): void;

getHash(): Buffer;

Expand Down
6 changes: 3 additions & 3 deletions types/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ export interface PrefixSha256Json {
type: Types.PrefixSha256;
prefix: string;
maxMessageLength: number;
subfulfillment: FulfillmentAsn1Json;
subfulfillment: FulfillmentAsn1Json<any>; // TODO: improve type
}

export interface PrefixSha256Asn1Json {
prefix: Buffer;
maxMessageLength: number;
subfulfillment: FulfillmentAsn1Json;
subfulfillment: FulfillmentAsn1Json<any>; // TODO: improve type
}

export interface RsaSha256Json {
Expand Down Expand Up @@ -105,6 +105,6 @@ export interface ThresholdSha256Json {
subconditions?: ConditionAsn1Json[];
}
export interface ThresholdSha256Asn1Json {
subfulfillments?: FulfillmentAsn1Json[];
subfulfillments?: FulfillmentAsn1Json<any>[];
subconditions?: ConditionAsn1Json[];
}

0 comments on commit 1990100

Please sign in to comment.