File tree Expand file tree Collapse file tree 3 files changed +26
-7
lines changed
Expand file tree Collapse file tree 3 files changed +26
-7
lines changed Original file line number Diff line number Diff line change @@ -5,3 +5,5 @@ export class MalformedHashChainError extends Error {}
55export class BadSignatureError extends Error { }
66
77export class BadNextKeySpecifiedError extends Error { }
8+
9+ export class BadOptionsSpecifiedError extends Error { }
Original file line number Diff line number Diff line change 11import canonicalize from "canonicalize" ;
22import {
33 BadNextKeySpecifiedError ,
4+ BadOptionsSpecifiedError ,
45 BadSignatureError ,
56 MalformedHashChainError ,
67 MalformedIndexChainError ,
78} from "../errors/errors" ;
89import { isSubsetOf } from "../utils/array" ;
910import { hash } from "../utils/hash" ;
1011import {
12+ isGenesisOptions ,
13+ isRotationOptions ,
1114 type CreateLogEventOptions ,
1215 type GenesisLogOptions ,
1316 type LogEvent ,
@@ -135,8 +138,11 @@ export class IDLogManager {
135138
136139 async createLogEvent ( options : CreateLogEventOptions ) {
137140 const entries = await this . repository . findMany ( { } ) ;
138- if ( entries . length > 0 )
139- return this . appendEntry ( entries , options as RotationLogOptions ) ;
140- return this . createGenesisEntry ( options as GenesisLogOptions ) ;
141+ if ( entries . length > 0 ) {
142+ if ( ! isRotationOptions ( options ) ) throw new BadOptionsSpecifiedError ( ) ;
143+ return this . appendEntry ( entries , options ) ;
144+ }
145+ if ( ! isGenesisOptions ( options ) ) throw new BadOptionsSpecifiedError ( ) ;
146+ return this . createGenesisEntry ( options ) ;
141147 }
142148}
Original file line number Diff line number Diff line change @@ -14,6 +14,11 @@ export type VerifierCallback = (
1414 pubKey : string ,
1515) => Promise < boolean > ;
1616
17+ export type Signer = {
18+ sign : ( string : string ) => Promise < string > | string ;
19+ pubKey : string ;
20+ } ;
21+
1722export type RotationLogOptions = {
1823 nextKeyHashes : string [ ] ;
1924 signer : Signer ;
@@ -26,9 +31,15 @@ export type GenesisLogOptions = {
2631 signer : Signer ;
2732} ;
2833
29- export type Signer = {
30- sign : ( string : string ) => Promise < string > | string ;
31- pubKey : string ;
32- } ;
34+ export function isGenesisOptions (
35+ options : CreateLogEventOptions ,
36+ ) : options is GenesisLogOptions {
37+ return "id" in options ;
38+ }
39+ export function isRotationOptions (
40+ options : CreateLogEventOptions ,
41+ ) : options is RotationLogOptions {
42+ return "nextKeySigner" in options ;
43+ }
3344
3445export type CreateLogEventOptions = GenesisLogOptions | RotationLogOptions ;
You can’t perform that action at this time.
0 commit comments