'RsaSignature2017', 'nonce' => Strings::getRandomHex(64), 'creator' => $owner['url'] . '#main-key', 'created' => DateTimeFormat::utcNow(DateTimeFormat::ATOM) ]; $ohash = self::hash(self::signableOptions($options)); $dhash = self::hash(self::signableData($data)); $options['signatureValue'] = base64_encode(Crypto::rsaSign($ohash . $dhash, $owner['uprvkey'])); return array_merge($data, ['signature' => $options]); } private static function signableData($data) { unset($data['signature']); return $data; } private static function signableOptions($options) { $newopts = ['@context' => 'https://w3id.org/identity/v1']; unset($options['type']); unset($options['id']); unset($options['signatureValue']); return array_merge($newopts, $options); } private static function hash($obj) { return hash('sha256', JsonLD::normalize($obj)); } }