-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: merging multiple PeerDID classes
- Loading branch information
1 parent
9ed3e4e
commit 3d28da7
Showing
3 changed files
with
30 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,33 @@ | ||
import type { DID, KeyCurve } from "."; | ||
import { CastorError, type DID, type KeyCurve } from "."; | ||
|
||
export namespace PeerDID { | ||
// Q: why is this a custom shape instead of a Domain.PrivateKey? | ||
export interface PrivateKey { | ||
/** | ||
* Instance of a KeyCurve | ||
* | ||
* @type {KeyCurve} | ||
*/ | ||
keyCurve: KeyCurve; | ||
/** | ||
* Value as Uint8Array, buffer like | ||
* | ||
* @type {Uint8Array} | ||
*/ | ||
value: Uint8Array; | ||
} | ||
} | ||
|
||
export class PeerDID { | ||
constructor( | ||
public readonly did: DID, | ||
public readonly privateKeys: Array<{ | ||
/** | ||
* Instance of a KeyCurve | ||
* | ||
* @type {KeyCurve} | ||
*/ | ||
keyCurve: KeyCurve; | ||
/** | ||
* Value as Uint8Array, buffer like | ||
* | ||
* @type {Uint8Array} | ||
*/ | ||
value: Uint8Array; | ||
}> | ||
) {} | ||
public readonly privateKeys: PeerDID.PrivateKey[] = [] | ||
) { | ||
const regex = /(([01](z)([1-9a-km-zA-HJ-NP-Z]{46,47}))|(2((\.[AEVID](z)([1-9a-km-zA-HJ-NP-Z]{46,47}))+(\.(S)[0-9a-zA-Z=]*)?)))$/; | ||
const isValid = did.schema === "did" && did.method === "peer" && regex.test(did.methodId); | ||
|
||
if (isValid === false) { | ||
throw new CastorError.InvalidPeerDIDError(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters