@@ -2,13 +2,15 @@ package config
2
2
3
3
import (
4
4
"context"
5
+ "encoding/json"
5
6
"errors"
6
7
"fmt"
7
8
"net/url"
8
9
"os"
9
10
"path/filepath"
10
11
"regexp"
11
12
"runtime"
13
+ "strconv"
12
14
"strings"
13
15
"time"
14
16
@@ -46,7 +48,8 @@ type Configuration struct {
46
48
IPFS IPFS `mapstructure:"IPFS"`
47
49
VaultUserPassAuthEnabled bool
48
50
VaultUserPassAuthPassword string
49
- CredentialStatus CredentialStatus `mapstructure:"CredentialStatus"`
51
+ CredentialStatus CredentialStatus `mapstructure:"CredentialStatus"`
52
+ CustomDIDMethods []CustomDIDMethods `mapstructure:"-"`
50
53
}
51
54
52
55
// Database has the database configuration
@@ -90,6 +93,43 @@ type Ethereum struct {
90
93
TransferAccountKeyPath string `tip:"Transfer account key path"`
91
94
}
92
95
96
+ // CustomDIDMethods struct
97
+ // Example: ISSUER_CUSTOM_DID_METHODS='[{"blockchain":"linea","network":"testnet","networkFlag":"0b01000001","chainID":59140}]'
98
+ type CustomDIDMethods struct {
99
+ Blockchain string `tip:"Identity blockchain for custom network"`
100
+ Network string `tip:"Identity network for custom network"`
101
+ NetworkFlag byte `tip:"Identity network flag for custom network"`
102
+ ChainID int `tip:"Chain id for custom network"`
103
+ }
104
+
105
+ // UnmarshalJSON implements the Unmarshal interface for CustomNetwork
106
+ func (cn * CustomDIDMethods ) UnmarshalJSON (data []byte ) error {
107
+ aux := struct {
108
+ Blockchain string `json:"blockchain"`
109
+ Network string `json:"network"`
110
+ NetworkFlag string `json:"networkFlag"`
111
+ ChainID int `json:"chainId"`
112
+ }{}
113
+
114
+ if err := json .Unmarshal (data , & aux ); err != nil {
115
+ return err
116
+ }
117
+ if len (aux .NetworkFlag ) != 10 || aux .NetworkFlag [:2 ] != "0b" {
118
+ return errors .New ("invalid NetworkFlag format" )
119
+ }
120
+ flag , err := strconv .ParseUint (aux .NetworkFlag [2 :], 2 , 8 )
121
+ if err != nil {
122
+ return err
123
+ }
124
+
125
+ cn .Blockchain = aux .Blockchain
126
+ cn .Network = aux .Network
127
+ cn .NetworkFlag = byte (flag )
128
+ cn .ChainID = aux .ChainID
129
+
130
+ return nil
131
+ }
132
+
93
133
// Prover struct
94
134
type Prover struct {
95
135
ServerURL string
@@ -344,6 +384,17 @@ func Load(fileName string) (*Configuration, error) {
344
384
if err := viper .Unmarshal (config ); err != nil {
345
385
log .Error (ctx , "error unmarshalling configuration" , "err" , err )
346
386
}
387
+
388
+ jsonStr := viper .GetString ("CUSTOM_DID_METHODS" )
389
+ var customDIDMethods []CustomDIDMethods
390
+ if jsonStr != "" {
391
+ if err := json .Unmarshal ([]byte (jsonStr ), & customDIDMethods ); err != nil {
392
+ log .Error (ctx , "error unmarshalling custom networks" , "err" , err )
393
+ return nil , err
394
+ }
395
+ }
396
+ config .CustomDIDMethods = customDIDMethods
397
+
347
398
checkEnvVars (ctx , config )
348
399
return config , nil
349
400
}
@@ -452,6 +503,8 @@ func bindEnv() {
452
503
_ = viper .BindEnv ("APIUI.IdentityNetwork" , "ISSUER_API_IDENTITY_NETWORK" )
453
504
_ = viper .BindEnv ("APIUI.KeyType" , "ISSUER_API_UI_KEY_TYPE" )
454
505
506
+ _ = viper .BindEnv ("ISSUER_CUSTOM_DID_METHODS" )
507
+
455
508
viper .AutomaticEnv ()
456
509
}
457
510
0 commit comments