generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* #564 - Added delegated grant support for RecordsRead * Update names with Message, AbstractMessage, and MessageInterface
- Loading branch information
1 parent
5740a26
commit 947a372
Showing
24 changed files
with
166 additions
and
116 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import type { MessageInterface } from '../types/message-interface.js'; | ||
import type { GenericMessage, GenericSignaturePayload } from '../types/message-types.js'; | ||
|
||
import { Jws } from '../utils/jws.js'; | ||
import { Message } from './message.js'; | ||
|
||
/** | ||
* An abstract implementation of the `MessageInterface` interface. | ||
*/ | ||
export abstract class AbstractMessage<M extends GenericMessage> implements MessageInterface<M> { | ||
private _message: M; | ||
public get message(): M { | ||
return this._message as M; | ||
} | ||
|
||
private _author: string | undefined; | ||
public get author(): string | undefined { | ||
return this._author; | ||
} | ||
|
||
private _signaturePayload: GenericSignaturePayload | undefined; | ||
public get signaturePayload(): GenericSignaturePayload | undefined { | ||
return this._signaturePayload; | ||
} | ||
|
||
protected constructor(message: M) { | ||
this._message = message; | ||
|
||
if (message.authorization !== undefined) { | ||
// if the message authorization contains author delegated grant, the author would be the grantor of the grant | ||
// else the author would be the signer of the message | ||
if (message.authorization.authorDelegatedGrant !== undefined) { | ||
this._author = Message.getSigner(message.authorization.authorDelegatedGrant); | ||
} else { | ||
this._author = Message.getSigner(message as GenericMessage); | ||
} | ||
|
||
this._signaturePayload = Jws.decodePlainObjectPayload(message.authorization.signature); | ||
} | ||
} | ||
|
||
/** | ||
* Called by `JSON.stringify(...)` automatically. | ||
*/ | ||
toJSON(): GenericMessage { | ||
return this.message; | ||
} | ||
} |
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
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
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
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
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
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
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
Oops, something went wrong.