-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwaltid-enterprise
executable file
·1509 lines (1181 loc) · 37.1 KB
/
waltid-enterprise
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
set -e
cli_name=${0##*/}
export WORKDIR=$(cd $(dirname $0) && pwd)
auth_token=""
init() {
echo "Walt.id Enterprise Stack Quickstarter v$(cat $WORKDIR/VERSION)"
info "Checking dependencies... TODO"
# jq
# curl
}
log() {
script_name=${0##*/}
timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
echo "== $script_name $timestamp $1"
}
info() {
log "[INFO] $1"
}
error() {
log "[ERROR] $1"
}
docker_hub_login(){
password=$(cat .docker-token | grep -v "#" | grep -v -e '^[[:space:]]*$')
info "Autheticating to Docker Hub. Please use the password provided..."
docker login -u waltid -p $password
echo
}
pull_docker_image() {
info "Pulling Enterprise Stack v0.1.0"
docker pull waltid/waltid-enterprise-api:0.1.0
echo
}
start_container() {
info "Starting up Enterprise Stack v0.1.0"
docker compose up
}
run() {
docker_hub_login
pull_docker_image
start_container
}
get_superadmin_auth_token() {
if [ -f .auth_token ]; then
info "Super admin already logged in."
else
info "Logging super admin in..."
superadmin_login
fi
AUTH_TOKEN=$(cat .auth_token)
eval $1=$AUTH_TOKEN
}
clean_all() {
info "Cleaning up..."
recreate_collections
rm -f .user_id
rm -f .auth_token
rm -f .user_auth_token
rm -f .did
}
check_last_command_failure() {
if [[ $result < 0 ]]; then
echo "
!!!!!!!!!!!
!! ERROR !!
!!!!!!!!!!!
Oops. I'm sorry. Something went wrong. Contact the WaltId guys to help you with it. Bye.
"
return -1
fi
result=0
}
pause() {
read -n1 -s
}
get_user_auth_token() {
if [ -f .user_auth_token ]; then
info "User already logged in."
else
info "Logging user in..."
user_admin_login
fi
USER_AUTH_TOKEN=$(cat .user_auth_token)
info "Auth token: $USER_AUTH_TOKEN"
eval $1=$USER_AUTH_TOKEN
}
wizard_pre_message() {
cat <<EOF
$1
EOF
pause
result=0
}
wizard_pos_message() {
check_last_command_failure
cat <<EOF
$1
EOF
}
wizard_welcome() {
echo "Welcome to the Quickstart Wizard of the WaltId Enterprise Stack! We will now guide you through each step to get you onboarded on our platform."
}
wizard_disclaimer_disagree() {
echo "
We understand. No worries. Friendship continues.
Let us give you 2 options:
1. Try each command by yourself and deal with eventual issues; or
2. Save the data you don't want to lose and come back again to this wizard ;-)
Tchüss!
"
}
wizard_disclaimer_agreed() {
echo "
Cool. Thanks for understanding.
"
}
wizard_disclaimer() {
echo "
In order to make you experience as smooth as possible, we need to recreate the whole database, just to make sure there's no data there that could cause any confusion and get in the way of the main purpose of this script: learning how to use the product.
Which means: all the data in your local WaltId Enterprise Stack instance will be lost.
"
read -p "Are you ok with that? (y/N) " -n1 AGREED
shopt -s nocasematch
if [[ "$AGREED" != "y" ]]; then
wizard_disclaimer_disagree
return -1
fi
wizard_disclaimer_agreed
}
wizard_pre_suerpadmin_create_account() {
wizard_pre_message "
The first thing we need to do is the creation of the so called Super Admin user. It's something like the 'root' in your OS.
Press any key to run the command below...
$cli_name superadmin-create-account
"
pause
}
wizard_pos_suerpadmin_create_account() {
wizard_pos_message "
Nice! The Super Admin user has just been created with the email and password specified in the ./config/superadmin-registration.conf file.
The Super Admin user can do anything in the platform. As the name suggests, he is the admin of the whole instance. He can manage all the resources in any tenant in any organization. So, please, never share this user's credential with anyone not related to the instance administration.
"
}
wizard_pre_superadmin_login() {
wizard_pre_message "
Now, it's time to log him in.
Press any key to run the command below to get access to super powers...
$cli_name superadmin-login
"
}
wizard_pos_superadmin_login() {
wizard_pos_message "
The Super Admin is now logged in.
Every command from now on will be executed with the Super Admin account. Take care.
"
}
wizard_pre_init_db() {
wizard_pre_message "
The next step is the database initialization. Since we've just recreated everything from scratch, it's not strictly necessary, but I'll show you how does it work anyway.
Press any key to run the command below...
$cli_name init-db
"
}
wizard_pos_init_db() {
wizard_pos_message "
The database has been initialized according to the information provided in the config/database.conf file.
"
}
wizard_pre_create_organization() {
wizard_pre_message "
It's now time to create the root organization. If you allow me, I will call it "waltid". Once you learn how to do it, you should use your company's name instead.
You can find more about organizations in the docs (https://docs.walt.id/enterprise-stack/concepts#the-organization)
Press any key to run the command below and create the "waltid" root organization...
$cli_name create-organization
"
}
wizard_pos_create_organization() {
wizard_pos_message "
Awesome. The "waltid" root organization has been created.
This is how you database structure looks like so far.
┌────────────┐
│ │
│ waltid │
│ │
└────────────┘
"
}
wizard_pre_list_organizations() {
wizard_pre_message "
At any time, you can list all the organizations in... #TODO
Press any key to run the command bellow to list all the organizations... #TODO
$(basename "$0") list-organizations
"
}
wizard_pos_list_organizations() {
wizard_pos_message "
"
}
wizard_pre_create_user_account() {
wizard_pre_message "
You are probably aware that it's not a good idea to use a super powered user for daily tasks, right? And, you know... big power leads to big responsibilities. We'd better create a less powered user.
We will now use the Super Admin account to create a new user account.
Press any key to run the command below to create a not-so-super user...
$cli_name create-user-account
"
}
wizard_pos_create_user_account() {
wizard_pos_message "
The user "max.mustermann@example.org" was successfuly created with password "password123456".
We will use it from now on.
"
}
wizard_pre_list_accounts() {
wizard_pre_message "
Press any key to run the command below to list all users registered in your instance.
$cli_name list-accounts
"
}
wizard_pos_list_accounts1() {
wizard_pos_message "
Notice that there are two user accounts: Superadmin and Max.
And, before we move forward, let's take a closer look to the "role" property of each account. What does it mean?
Each property in the "roles" object represents the set of roles assingned to that user in a specific organization.
Take Max as our first example. He doesn't have any specifc role. Which means he doesn't have any privilege on any resource (we will talk more about it later).
On the other hand, look at the Superadmin account. It has the role "admin" in the "waltid" organization. And, why does it have such privilege? Just because it's the account who created that organization.
Every time an organization is created, an "admin" role is automatically generated and assigned to its creator.
"
}
wizard_pos_list_accounts2() {
wizard_pos_message "
Now notice that Max also has the role "waltid.admin".
"
}
wizard_pre_list_resources() {
wizard_pre_message "
"
}
wizard_pos_list_resources() {
wizard_pos_message "
"
}
wizard_pre_list_keys() {
wizard_pre_message "
"
}
wizard_pos_list_keys() {
wizard_pos_message "
"
}
wizard_pre_add_admin_role() {
wizard_pre_message "
What if we now assign the same "waltid.admin" role to Max? Does he deserve it?
Press any key to run the command below and give Max some powers on the "waltid" organization.
$cli_name add-admin-role
"
}
wizard_pos_add_admin_role() {
wizard_pos_message "
Congratz, Max. You are now a VIP at "waltid". Oh, ok, no so VIP as the Super Admin. But you understand, right? ;-)
"
}
wizard_pre_user_admin_login() {
wizard_pre_message "
Let's switch to Max's account and stop using the Super Admin account.
Press any key to log Max in.
$cli_name user-admin-login
"
}
wizard_pos_user_admin_login() {
wizard_pos_message "
Max is in charge now. He logged in successfuly.
"
}
wizard_pre_create_tenant() {
wizard_pre_message "
"
}
wizard_pos_create_tenant() {
wizard_pos_message "
The root organization is like the '/' directory of a file system.
The WaltId Enterprise Stack
"
}
wizard_pre_create_kms_service() {
wizard_pre_message "
"
}
wizard_pos_create_kms_service() {
wizard_pos_message "
"
}
wizard_pre_generate_did_key() {
wizard_pre_message "
"
}
wizard_pos_generate_did_key() {
wizard_pos_message "
"
}
wizard_pre_generate_status_key() {
wizard_pre_message "
"
}
wizard_pos_generate_status_key() {
wizard_pos_message "
"
}
wizard_pre_create_did_service() {
wizard_pre_message "
"
}
wizard_pos_create_did_service() {
wizard_pos_message "
"
}
wizard_pre_create_did() {
wizard_pre_message "
"
}
wizard_pos_create_did() {
wizard_pos_message "
"
}
wizard_pre_create_credential_status_service() {
wizard_pre_message "
"
}
wizard_pos_create_credential_status_service() {
wizard_pos_message "
"
}
wizard_pre_create_issuer_service() {
wizard_pre_message "
"
}
wizard_pos_create_issuer_service() {
wizard_pos_message "
"
}
wizard_pre_create_verifier_service() {
wizard_pre_message "
"
}
wizard_pos_create_verifier_service() {
wizard_pos_message "
"
}
wizard_pre_issue_jwt_vc() {
wizard_pre_message "
"
}
wizard_pos_issue_jwt_vc() {
wizard_pos_message "
"
}
wizard() {
wizard_welcome
wizard_disclaimer
clean_all
wizard_pre_suerpadmin_create_account
superadmin_create_account
wizard_pos_suerpadmin_create_account
wizard_pre_superadmin_login
superadmin_login
wizard_pos_superadmin_login
wizard_pre_init_db
init_db
wizard_pos_init_db
wizard_pre_create_organization
create_organization
wizard_pos_create_organization
wizard_pre_list_organizations
list_organizations
wizard_pos_list_organizations
wizard_pre_create_user_account
create_user_account
wizard_pos_create_user_account
wizard_pre_list_accounts
list_accounts
wizard_pos_list_accounts1
wizard_pre_add_admin_role
add_admin_role_to_user
wizard_pos_add_admin_role
wizard_pre_list_accounts
list_accounts
wizard_pos_list_accounts2
wizard_pre_user_admin_login
user_admin_login
wizard_pos_user_admin_login
wizard_pre_create_tenant
create_tenant
wizard_pos_create_tenant
wizard_pre_list_resources
list_resources
wizard_pos_list_resources
wizard_pre_create_kms_service
create_kms_service
wizard_pos_create_kms_service
wizard_pre_list_resources
list_resources
wizard_pos_list_resources
wizard_pre_generate_did_key
generate_did_key
wizard_pos_generate_did_key
wizard_pre_generate_status_key
generate_status_key
wizard_pos_generate_status_key
wizard_pre_create_did_service
create_did_service
wizard_pos_create_did_service
wizard_pre_list_resources
list_resources
wizard_pos_list_resources
wizard_pre_create_did
create_did
wizard_pos_create_did
# wizard_pre_create_credential_status_service
# create_credential_status_service
# wizard_pos_create_credential_status_service
wizard_pre_create_issuer_service
create_issuer_service
wizard_pos_create_issuer_service
wizard_pre_list_resources
list_resources
wizard_pos_list_resources
wizard_pre_create_verifier_service
create_verifier_service
wizard_pos_create_verifier_service
wizard_pre_list_resources
list_resources
wizard_pos_list_resources
wizard_pre_issue_jwt_vc
issue_jwt_vc
wizard_pos_issue_jwt_vc
}
superadmin_create_account() {
superadmin_token=$(cat config/superadmin-registration.conf | sed -n '2 p' | cut -d \" -f 2)
info "Registering token \"${superadmin_token}\" provided in the superadmin-registration.conf file"
response=$(curl -X 'POST' \
'http://localhost:3000/v1/superadmin/create-by-token' \
-H 'accept: */*' \
-H 'Content-Type: application/json' \
-d "${superadmin_token}" 2> /dev/null)
if [[ $response == *"exception"* ]]; then
error "Super admin account could not be created."
error "$response"
result=-1
else
info "Super admin account successfully created."
fi
}
superadmin_login() {
superadmin_email=$(cat config/superadmin-registration.conf | grep identifier | cut -d \" -f 2)
superadmin_password=$(cat config/superadmin-registration.conf | grep password | cut -d \" -f 2)
info "Logging in super admin with credentials provided in the superadmin-registration.conf file"
response=$(curl -X 'POST' \
'http://localhost:3000/auth/account/emailpass' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d "{
\"email\": \"${superadmin_email}\",
\"password\": \"${superadmin_password}\"
}" 2> /dev/null)
if [[ $response == *"exception"* ]]; then
error "Super admin could not be logged in."
error "$response"
result=-1
else
info "Super admin logged in successfully."
info "$response"
AUTH_TOKEN=$(echo $response | jq .token | tr -d '"')
echo $AUTH_TOKEN > .auth_token
fi
}
init_db() {
get_superadmin_auth_token AUTH_TOKEN
info "Initializing the database based on the config/database.conf file"
response=$(curl -X 'POST' \
'http://localhost:3000/v1/admin/initial-setup' \
-H 'accept: */*' \
-H "Authorization: Bearer $AUTH_TOKEN" \
-d '' 2> /dev/null)
if [[ $response == *"Unauthorized"* ]]; then
error "Database could not be initialized. Access denied."
error "$response"
result=-1
else
info "Database successfully initialized."
fi
}
recreate_collections() {
# get_superadmin_auth_token AUTH_TOKEN
response=$(curl -X 'POST' \
'http://localhost:3000/v1/dev/database-recreate' \
-H 'accept: */*' \
-d '' 2> /dev/null)
if [[ $response == *"exception"* ]]; then
error "Database could not be recreated."
error "$response"
else
info "Database successfully recreated."
fi
}
create_organization() {
get_superadmin_auth_token AUTH_TOKEN
response=$(curl -X 'POST' \
'http://localhost:3000/v1/organization/create' \
-H 'accept: */*' \
-H "Authorization: Bearer $AUTH_TOKEN" \
-H 'Content-Type: application/json' \
-d '{
"_id": "waltid",
"profile": {
"name": "walt.id GmbH"
},
"billing": {
"billingCountry": "AT",
"billingAddress": "Liechtensteinstraße 111/115, 1090 Vienna",
"vatNr": "ATU75569617"
}
}' 2> /dev/null)
if [[ $response == *"exception"* ]]; then
error "Organization could not be created."
error "$response"
else
info "Organization successfully created."
fi
}
create_user_account() {
get_superadmin_auth_token AUTH_TOKEN
rm -f .user_id
response=$(curl -X 'POST' \
'http://localhost:3000/v1/admin/account/register' \
-H 'accept: application/json' \
-H "Authorization: Bearer $AUTH_TOKEN" \
-H 'Content-Type: application/json' \
-d '{
"profile": {
"name": "Max Mustermann",
"email": "max.mustermann@example.org",
"addressCountry": "AT",
"address": "Liechtensteinstraße 111/115, 1090 Vienna"
},
"preferences": {
"timeZone": "UTC",
"languagePreference": "EN"
},
"initialAuth": {
"type": "email",
"identifier": {
"type": "email",
"email": "max.mustermann@example.org"
},
"data": {
"type": "email",
"password": "password123456"
}
}
}' 2> /dev/null)
if [[ $response == *"exception"* ]]; then
error "User account could not be created."
error "$response"
# TODO Offer to select an existing user to be used
else
# TODO Handle user already exists
info "User account successfully created."
regex="\"_id\":\"([0-9a-z-]+)\","
if [[ "$response" =~ $regex ]]; then
user_id=${BASH_REMATCH[1]}
info "User ID: $user_id"
echo $user_id > .user_id
info "User ID saved at .user_id"
else
error "User ID not found in the HTTP response."
fi
fi
}
get_user_id() {
if [ -f .user_id ]; then
USER_ID=$(cat .user_id)
info "User ID found: $USER_ID"
else
error "No user id found. Please run '$0 create-user-account' first. "
exit -1
fi
eval $1=$USER_ID
}
add_admin_role_to_user() {
# TODO Parameterise USER and ORG
get_superadmin_auth_token AUTH_TOKEN
get_user_id USER_ID
ROLE="waltid.admin"
ORGANIZATION="waltid"
info "Adding role '$ROLE' to user '$USER_ID' from organization '$ORGANIZATION'..."
response=$(curl -X 'POST' \
"http://localhost:3000/v1/admin/account/$USER_ID/roles/add/$ORGANIZATION/$ROLE" \
-H 'accept: application/json' \
-H "Authorization: Bearer $AUTH_TOKEN" \
-d '' 2> /dev/null)
if [[ $response == *"exception"* ]]; then
error "Role could not be added."
error "$response"
else
# TODO If response = {}, role hasn't been added either
info "Role successfully added."
info $response
fi
}
user_admin_login() {
# get_superadmin_auth_token AUTH_TOKEN
USER="max.mustermann@example.org"
PASS="password123456"
response=$(curl -X 'POST' \
'http://waltid.enterprise.localhost:3000/auth/account/emailpass' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d "{
\"email\": \"$USER\",
\"password\": \"$PASS\"
}" 2> /dev/null)
if [[ $response == *"exception"* ]]; then
error "User $USER could not be logged in."
error "$response"
else
regex="\"token\":\"([A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+)\""
if [[ "$response" =~ $regex ]]; then
AUTH_TOKEN=${BASH_REMATCH[1]}
# info "User ID: $user_id"
rm -f .user_auth_token
echo $AUTH_TOKEN > .user_auth_token
info "User $USER successfully logged in with token $AUTH_TOKEN"
else
error "Auth token not found in the HTTP response."
fi
fi
}
create_tenant() {
get_user_auth_token AUTH_TOKEN
TENANT_ID="waltid.tenant1"
response=$(curl -X 'POST' \
"http://waltid.enterprise.localhost:3000/v1/$TENANT_ID/resource-api/tenants/create" \
-H 'accept: */*' \
-H "Authorization: Bearer $AUTH_TOKEN" \
-H 'Content-Type: application/json' \
-d '{
"name":"My first Tenant with Tamino"
}' 2> /dev/null)
if [[ $response == *"exception"* ]]; then
error "Tenant $TENANT_ID could not be created."
error "$response"
else
info "Tenant $TENANT_ID successfully created."
fi
}
create_service() {
get_user_auth_token AUTH_TOKEN
SERVICE_TYPE=$1
SERVICE_NAME=$2
SERVICE_ID="waltid.tenant1.$SERVICE_NAME"
response=$(curl -X 'POST' \
"http://waltid.enterprise.localhost:3000/v1/$SERVICE_ID/resource-api/services/create" \
-H 'accept: */*' \
-H "Authorization: Bearer $AUTH_TOKEN" \
-H 'Content-Type: application/json' \
-d "{
\"type\": \"$SERVICE_TYPE\"
}" 2> /dev/null)
if [[ $response == *"exception"* ]]; then
error "$SERVICE_ID could not be created."
error "$response"
else
info "$SERVICE_ID successfully created."
echo "$response" | jq
fi
}
create_kms_service() {
create_service "kms" "kms1"
}
generate_key() {
get_user_auth_token AUTH_TOKEN
PURPOSE=$1
KEY_FILE=$2
KMS_ID="waltid.tenant1.kms1"
response=$(curl -X 'POST' \
"http://waltid.enterprise.localhost:3000/v1/$KMS_ID/kms-service-api/keys/generate" \
-H 'accept: application/json' \
-H "Authorization: Bearer $AUTH_TOKEN" \
-H 'Content-Type: application/json' \
-d '{
"backend": "jwk",
"keyType": "Ed25519"
}' 2> /dev/null)
if [[ $response == *"exception"* ]]; then
error "$PURPOSE key could not be generate from $KMS_ID."
error "$response"
else
info "$PURPOSE key successfully generated."
echo "$response" | jq
echo "$response"
DID_KEY=$(echo $response | jq "._id" | cut -d\" -f2)
echo $DID_KEY > $KEY_FILE
info "Key saved in the $KEY_FILE file"
fi
}
generate_did_key() {
generate_key "DID" ".did_key"
}
generate_status_key() {
generate_key "Credential Status" ".status_key"
}
create_did_service() {
create_service "did" "did1"
}
create_did() {
get_user_auth_token AUTH_TOKEN
DID_SERVICE_ID="waltid.tenant1.did1"
if [[ ! -f .did_key ]]; then
info "DID key doesn't exist. Let's create one..."
generate_did_key
fi
KEY_ID=$(cat .did_key)
response=$(curl -X 'POST' \
"http://waltid.enterprise.localhost:3000/v1/$DID_SERVICE_ID/did-service-api/dids/create/key" \
-H 'accept: application/json' \
-H "Authorization: Bearer $AUTH_TOKEN" \
-H 'Content-Type: application/json' \
-d "{
\"keyId\": \"$KEY_ID\",
\"useJwkJcsPub\": true
}" 2> /dev/null)
if [[ $response == *"exception"* ]]; then
error "did:key could not be created."
error "$response"
else
echo $response > .did
info "did:key successfully created and saved in the .did file:"
echo "$response" | jq ".did"
fi