mirror of
https://gh.wpcy.net/https://github.com/fairpm/mini-fair-repo.git
synced 2026-06-19 02:23:34 +08:00
Signed-off-by: Joost de Valk <joost@altha.nl> Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com>
129 lines
2.5 KiB
PHP
129 lines
2.5 KiB
PHP
<?php
|
|
/**
|
|
* Command.
|
|
*
|
|
* @package FAIR\Beacon
|
|
*/
|
|
|
|
namespace FAIR\Beacon\PLC;
|
|
|
|
use WP_CLI;
|
|
use WP_CLI_Command;
|
|
|
|
/**
|
|
* Command class.
|
|
*/
|
|
class Command extends WP_CLI_Command {
|
|
/**
|
|
* Generate a new DID.
|
|
*
|
|
* @param array $args The command line arguments.
|
|
* @param array $assoc_args The associative command line arguments.
|
|
* @return void
|
|
*/
|
|
public function generate( $args, $assoc_args ) {
|
|
$did = DID::create();
|
|
|
|
printf(
|
|
"DID: %s\n",
|
|
esc_html( $did->id )
|
|
);
|
|
|
|
$rot_keys = $did->get_rotation_keys();
|
|
foreach ( $rot_keys as $key ) {
|
|
$encoded = $key->encode_public();
|
|
printf(
|
|
"Rotation key: %s\n",
|
|
esc_html( $encoded )
|
|
);
|
|
}
|
|
$verif_keys = $did->get_verification_keys();
|
|
foreach ( $verif_keys as $key ) {
|
|
$encoded = $key->encode_public();
|
|
printf(
|
|
"Verification key: %s\n",
|
|
esc_html( $encoded )
|
|
);
|
|
}
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Get a DID.
|
|
*
|
|
* @param array $args The command line arguments.
|
|
* @param array $assoc_args The associative command line arguments.
|
|
* @return void
|
|
*/
|
|
public function get( $args, $assoc_args ) {
|
|
$did = DID::get( $args[0] );
|
|
var_dump( $did );
|
|
|
|
printf(
|
|
"DID: %s\n",
|
|
esc_html( $did->id )
|
|
);
|
|
|
|
$rot_keys = $did->get_rotation_keys();
|
|
foreach ( $rot_keys as $key ) {
|
|
$encoded = $key->encode_public();
|
|
printf(
|
|
"Rotation key: %s\n",
|
|
esc_html( $encoded )
|
|
);
|
|
}
|
|
$verif_keys = $did->get_verification_keys();
|
|
foreach ( $verif_keys as $key ) {
|
|
$encoded = $key->encode_public();
|
|
printf(
|
|
"Verification key: %s\n",
|
|
esc_html( $encoded )
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Update a DID.
|
|
*
|
|
* ## OPTIONS
|
|
* <did>
|
|
* : The DID to update
|
|
*
|
|
* @param array $args The command line arguments.
|
|
* @param array $assoc_args The associative command line arguments.
|
|
* @return void
|
|
*/
|
|
public function update( $args, $assoc_args ) {
|
|
$did = DID::get( $args[0] );
|
|
if ( ! $did ) {
|
|
WP_CLI::error( 'DID not found' );
|
|
}
|
|
|
|
$res = $did->update();
|
|
var_dump( $res );
|
|
}
|
|
|
|
/**
|
|
* Import a DID.
|
|
*
|
|
* ## OPTIONS
|
|
* <did>
|
|
* : The DID to import.
|
|
*
|
|
* <rotation_keys>
|
|
* : The rotation keys for the DID.
|
|
*
|
|
* <verification_keys>
|
|
* : The verification keys for the DID.
|
|
*
|
|
* @param array $args The command line arguments.
|
|
* @param array $assoc_args The associative command line arguments.
|
|
*/
|
|
public function import( $args, $assoc_args ) {
|
|
$did = new DID();
|
|
// $did->set_id( $args[0] );.
|
|
// $did->set_rotation_keys( $args[1] );.
|
|
// $did->set_verification_keys( $args[2] );.
|
|
$did->save();
|
|
}
|
|
}
|