- public static function removeSecurityLink(array $json)
- {
- if (!is_array($json['@context'])) {
- return $json;
- }
-
- if (($key = array_search('https://w3id.org/security/v1', $json['@context'])) !== false) {
- unset($json['@context'][$key]);
- $json['@context'] = array_values(array_filter($json['@context']));
- }
-
- return $json;
- }
-
- public static function fixContext(array $json)
- {
- // Preparation for adding possibly missing content to the context
- if (!empty($json['@context']) && is_string($json['@context'])) {
- $json['@context'] = [$json['@context']];
- }
-
- if (($key = array_search('https://w3id.org/security/v1', $json['@context'])) !== false) {
- unset($json['@context'][$key]);
- $json['@context'] = array_values(array_filter($json['@context']));
- }
-
- $last_entry = count($json['@context']) - 1;
-
- $additional = [
- 'w3id' => 'https://w3id.org/security#',
- 'signature' => 'w3id:signature',
- 'RsaSignature2017' => 'w3id:RsaSignature2017',
- 'created' => 'w3id:created',
- 'creator' => 'w3id:creator',
- 'nonce' => 'w3id:nonce',
- 'signatureValue' => 'w3id:signatureValue',
- 'publicKey' => 'w3id:publicKey',
- 'publicKeyPem' => 'w3id:publicKeyPem'];
-
- if (is_array($json['@context'][$last_entry])) {
- $json['@context'][$last_entry] = array_merge($json['@context'][$last_entry], $additional);
- } else {
- $json['@context'][] = $additional;
- }
-
- return $json;
- }
-