This file contains hidden or 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
(ns custom-resteasy-client | |
"Creates a custom `javax.ws.rs.client.Client` with settings for timeouts, | |
evicting idle connections and a retry handler. This client can be a | |
resteasyClient for KeycloakBuilder that does not lead to \"RESTEASY004655 | |
Unable to invoke request: java.net.SocketException: Connection reset errors\" | |
according to the suggestion in | |
https://github.com/keycloak/keycloak/issues/8917#issuecomment-1712895984." | |
(:import | |
(java.util.concurrent TimeUnit) | |
(org.apache.http.impl.client DefaultHttpRequestRetryHandler HttpClients) |
This file contains hidden or 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
"Formal education will make you a living. Self-education will make you a | |
fortune." | |
~ Jim Rohn | |
% | |
"Programming is not easy like Sunday morning, it is silent poetry." | |
~ Waseem Latif | |
% | |
"The best way to get the right answer on the internet is not to ask a question; | |
it's to post the wrong answer." | |
~ Cunningham's Law |
This file contains hidden or 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
{ | |
type: 'KEY_ROTATION, | |
// IOTA address Side key encrypted with authorized service provider's public key | |
TOBVJSE9FAAMQGJXYDB...: 'TYBD9HVRWENQKYLKRAKZOHNWJYMDTTVXGOP...', | |
CUEIYQBOFIYGRBMOEG9...: 'ACNIUSZKCMSSEQ9ILSEACKWLQWSYMRAZYIR...' | |
} |
This file contains hidden or 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
/** | |
* Send encrypted MAM data to a service provider. | |
* | |
* @function sendMamData | |
* @param {string} seed IOTA seed of sender | |
* @param {string} address IOTA address of the service provider | |
* @param {string} publicKey Public key of the service provider in trytes | |
* @returns {Promise} containing IOTA transactions | |
*/ | |
async sendMamData(seed, address, publicKey) { |
This file contains hidden or 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
/** | |
* Process MAM message revoked: authorization | |
* @param message {Object} MAM message of type {@link AUTHORIZATION_REVOKED_TYPE}. | |
* @returns {undefined} | |
*/ | |
processAuthorizationRevokedMessage(message) { | |
const newSideKey = DeviceClient.createSideKey(); | |
this.authorizedServiceProviders.remove(message.policy.serviceProvider); | |
this.informUpdateSideKey( | |
this.authorizedServiceProviders.getAll(), |
This file contains hidden or 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
/** | |
* Process MAM message for added authorization. | |
* @param message {Object} MAM message of type {@link AUTHORIZED_TYPE}. | |
* @returns {undefined} | |
*/ | |
processAuthorizedMessage(message) { | |
const { serviceProvider } = message.policy; | |
logger.info(`Authorizing service provider ${JSON.stringify(serviceProvider)}`); | |
this.authorizedServiceProviders.add(serviceProvider); | |
this.sendMamData(this.seed, serviceProvider.iotaAddress, serviceProvider.publicKeyTrytes); |
This file contains hidden or 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
/** | |
* Retrieves and processes MAM messages by dispatching the type of message to | |
* its handler. | |
* | |
* @function processMamMessage | |
* @returns {undefined} | |
*/ | |
async processMamMessage() { | |
const IS_PAIRED = (typeof this.root !== 'undefined'); | |
if (!IS_PAIRED) { |
This file contains hidden or 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
/** | |
* Attach an MAM message. | |
* @function attach | |
* @param {JSON} packet JSON packet to attach. | |
* @returns {Promise} Containing the root or error | |
*/ | |
async attach(packet) { | |
this.logger.info(`Attaching packet ${util.inspect(packet)} to the Tangle`); | |
const trytes = iota.api.toTrytes(JSON.stringify(packet)); |
This file contains hidden or 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
/** | |
* Starts serial port reader. Retries via {@link tryInitP1} when port is | |
* disconnected or on error. | |
* | |
* @function tryInitP1 | |
* @param {function} messageHandler What to do with the message | |
* @returns {undefined} | |
*/ | |
function initP1(messageHandler) { | |
logger.info(`Initializing P1 reader on serial port ${RASPBERRY_PI_USB_PORT}`); |
This file contains hidden or 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
/** | |
* Creates the devices aggregate from the MAM event stream. | |
* @function toDevices | |
* @param {array} messages JSON messages from an MAM event stream | |
* @returns {array} Array of devices (device is object with address and type) | |
*/ | |
function toDevices(messages) { | |
const devicesSet = messages.reduce((devices, { type, device }) => { | |
switch (type) { | |
case DEVICE_ADDED_TYPE: |
NewerOlder