public function __construct(Channel $chan, array $updateData)
{
/**
* This represents data from the base64urlsafe encoded JSON blob that is signed by the channel.
*/
$this->channelId = (int) $updateData['id'];
$this->channelName = $chan->getName();
$this->merkleRoot = $updateData['root'];
$this->stored = $updateData['stored'];
$this->action = $this->stored['action'];
$packageRelatedActions = [self::ACTION_CORE_UPDATE, self::ACTION_PACKAGE_UPDATE];
if (\in_array($this->action, $packageRelatedActions)) {
// This is a package-related update:
$this->checksum = $this->stored['checksum'];
// This is the JSON message from the tree node, stored as an array:
$data = \json_decode($updateData['data'], true);
$this->updateMessage = $data;
// What action are we performing?
if ($this->action === self::ACTION_PACKAGE_UPDATE) {
$this->packageType = $data['pkg_type'];
$this->packageName = $data['name'];
} else {
$this->packageType = 'Core';
$this->packageName = 'Airship';
}
if ($this->action === self::ACTION_CORE_UPDATE) {
$state = State::instance();
$trustedSupplier = (string) ($state->universal['airship']['trusted-supplier'] ?? 'paragonie');
$this->supplier = $chan->getSupplier($trustedSupplier);
} else {
$this->supplier = $chan->getSupplier($data['supplier']);
}
} else {
// This is a key-related update:
if (!empty($updateData['master_signature'])) {
$this->masterSig = $updateData['master_signature'];
}
$data = \json_decode($updateData['data'], true);
try {
$this->unpackMessageUpdate($chan, $data);
} catch (NoSupplier $ex) {
$this->isNewSupplier = true;
$chan->createSupplier($data);
$this->supplier = $chan->getSupplier($data['supplier']);
}
$this->keyType = $data['type'];
$this->newPublicKey = $data['public_key'];
}
$this->supplierName = $this->supplier->getName();
}