Setup guide
NOTE: Current implementation of refresh service works only with issuer-node.
Preparation
- Run the issuer-node locally by following the quick-start installation guide.
- Clone the refresh service using the command
git clone [email protected]:0xPolygonID/refresh-service.git
. - Build JSON and JSONLD schemas, utilizing the provided examples:
Generate custom schemas through the schema builder. Additional details can be found in the schema builder documentation.
Setup with custom data provider
Consider an example of integrating polygon scan as a data provider for the refresh service.
- Integrate the custom data provider into the data provider module:
const polygonBalanceURL = "https://api.polygonscan.com/api?module=account&action=balance&address=%s&apikey=%s"
type BalanceResponse struct {
Status string `json:"status"`
Result string `json:"result"`
Message string `json:"message"`
}
func GetBalanceByAddress(address string) (map[string]any, error) {
resp, err := http.Get(
fmt.Sprintf(polygonBalanceURL, address, "<POLYGON_SCAN_TOKEN>"),
)
if err != nil {
return nil,
fmt.Errorf("failed to get balance: %w", err)
}
balanceResp := &BalanceResponse{}
if err = json.NewDecoder(resp.Body).Decode(balanceResp); err != nil {
return nil,
fmt.Errorf("failed to decode balance response: %w", err)
}
defer resp.Body.Close()
if balanceResp.Status != "1" {
return nil,
fmt.Errorf("invalid status in balance response: %s", balanceResp.Message)
}
// convert to credential subject format
// ensure that these fields align with the attributes specified in the JSONLD schema.
return map[string]any{
"balance": balanceResp.Result,
"address": address,
}, nil
}
Use the custom data provider within the refresh service:
- Remove the default data provider:
flexibleHTTP, err := rs.providers.ProduceFlexibleHTTP(credentialType)
if err != nil {
return nil,
errors.Wrapf(ErrCredentialNotUpdatable,
"for credential '%s' not possible to find a data provider: %v", credential.ID, err)
}
updatedFields, err := flexibleHTTP.Provide(credential.CredentialSubject)
if err != nil {
return nil, err
}- Use the new polygon scan data provider:
// confirm the credentialType matches a supported type in the refresh service,
// and its urn:uuid aligns with the id in the JSONLD schema
if credentialType != "urn:uuid:f50cfcf6-ded4-470e-83be-2d6820a66998" {
return nil, errors.New("unknow credentialType")
}
updatedFields, err := polygonscan.GetBalanceByAddress(credential.CredentialSubject["address"].(string))
if err != nil {
return nil, err
}Populate the .env variables:
export IPFS_GATEWAY_URL="https://infura..."
export SUPPORTED_RPC="137=https://infura..."
export SUPPORTED_STATE_CONTRACTS="137=0x624ce98D2d27b20b8f8d521723Df8fC4db71D79D"
export SUPPORTED_ISSUERS="*=https://my-issuer-node.com"
export ISSUERS_BASIC_AUTH="*=myuser:mypassword"Generate a blank config.yaml file:
touch config.yaml
- Run the refresh service:
source .env
go run .
Setup with default provider
To integrate polygon scan data provider with the default data provider, follow these general steps:
- Create a
config.yaml
file with the following content:
urn:uuid:f50cfcf6-ded4-470e-83be-2d6820a66998:
settings:
timeExpiration: 5m
provider:
url: https://api.polygonscan.com/api
method: GET
requestSchema:
params:
module: account
action: balance
address: "{{ credentialSubject.address }}" # this value will be substituted from the credentialSubject.address field
apikey: <POLYGON_SCAN_TOKEN>
headers:
Content-Type: application/json
responseSchema:
type: json
properties:
result:
type: string
match: credentialSubject.balance
- Populate the .env variables:
export IPFS_GATEWAY_URL="https://infura..."
export SUPPORTED_RPC="137=https://infura..."
export SUPPORTED_STATE_CONTRACTS="137=0x624ce98D2d27b20b8f8d521723Df8fC4db71D79D"
export SUPPORTED_ISSUERS="*=https://my-issuer-node.com"
export ISSUERS_BASIC_AUTH="*=myuser:mypassword"
- Run the service:
source .env
go run .
Testing
Go to the issuer-node UI and generate a credential with refresh service section:
Credential request
Retrieve the credential through the PolygonID mobile application. If the expiration date in the credential request was set in the past, the credential is supposed to be expired:
Expired credential
Visit https://verifier-demo.polygonid.me/ to create a proof request. This is necessary because https://schema-builder.polygonid.me/query-builder does not currently support the
xsd:positiveInteger
type:Proof request
Scan the QR using the PolygonID mobile application. During the refreshing process, you are expected to encounter the following message:
Refresh process
As a result, the successful completion of the verification process is expected, wallet must have one expired credential and one refreshed credential:
Result