Skip to content

Commit

Permalink
Merge pull request #123 from 0xPolygonID/install-husky-and-format-files
Browse files Browse the repository at this point in the history
Merge Install husky and format files to Develop
  • Loading branch information
amonsosanz authored Feb 21, 2024
2 parents e543c0f + 1016f05 commit 8818e06
Show file tree
Hide file tree
Showing 15 changed files with 963 additions and 328 deletions.
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ keywords:

## Question

Why do I encounter an error stating "unexpected status code: 404" when trying to create an identity, specifically while publishing the state to the RHS?
Why do I encounter an error stating "unexpected status code: 404" when trying to create an identity, specifically while publishing the state to the Reverse Hash Service?

## Answer

Expand All @@ -23,6 +23,7 @@ The error you're experiencing is typically due to an incorrect configuration of
To resolve this issue, check your `.env-issuer` file for the `ISSUER_CREDENTIAL_STATUS_RHS_MODE` value. If it is set to `OffChain`, you must specify a valid Reverse Hash Service Endpoint in `ISSUER_CREDENTIAL_STATUS_RHS_URL`. For example, you could use our staging RHS: `https://rhs-staging.polygonid.me/`.

If your `ISSUER_CREDENTIAL_STATUS_RHS_MODE` is configured for on-chain operation, ensure you have the correct smart contract information for your network, such as Mumbai:

- `ISSUER_CREDENTIAL_STATUS_ONCHAIN_TREE_STORE_SUPPORTED_CONTRACT`=0x76EB7216F2400aC18C842D8C76739F3B8E619DB9
- `ISSUER_CREDENTIAL_STATUS_RHS_CHAIN_ID`=8001

Expand All @@ -34,4 +35,5 @@ For a comprehensive understanding and configuration guidance, please review the
Wrong answer:

Simply replace the RHS URL with the Issuer Node URL or remove the `ISSUER_CREDENTIAL_STATUS_RHS_URL` from your .env-issuer file without adjusting the `ISSUER_CREDENTIAL_STATUS_RHS_MODE` setting or ensuring the RHS endpoint's validity.

</div>
1 change: 1 addition & 0 deletions docs/faqs/content/issuer-node-reusing-issuer-did.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ If you **have not deleted the database** and wish to reuse a previously configur
Wrong answer:

If you want to reuse a previously used DID, it's sufficient to manually edit the database entries to reflect the old DID, bypassing the need to update environment files or restart any services. This direct database manipulation ensures immediate reuse of the DID without considering system synchronization or security implications.

</div>
4 changes: 2 additions & 2 deletions docs/issuer-node/install-kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export ISSUERNAME="My Issuer"
export ISSUER_ETHERUM_URL="https://polygon-mumbai.XXXX"
export INGRESS_ENABLED=true
export VAULT_PWD=password
export RHS_MODE=None
export RHS_MODE=None
export RHS_URL="https://reverse-hash-service.com"
```

Expand Down Expand Up @@ -142,7 +142,7 @@ export ISSUERNAME="My Issuer"
export ISSUER_ETHERUM_URL="https://polygon-mumbai.XXXX"
export INGRESS_ENABLED=false
export VAULT_PWD=password
export RHS_MODE=None
export RHS_MODE=None
export RHS_URL="https://reverse-hash-service.com"
```

Expand Down
1 change: 1 addition & 0 deletions docs/issuer/refresh-service/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import useBaseUrl from '@docusaurus/useBaseUrl';

Extend customization by incorporating custom providers and integrating them into the refresh flow.
This is the easiest way to add custom business logic to retrieve data from a data provider. Go to [setup guide](/docs/issuer/refresh-service/setup-guide/#setup-with-custom-data-provider) for more information

## 2. Flexible HTTP package

Utilize the [flexible HTTP package](https://github.com/0xPolygonID/refresh-service/blob/main/providers/flexiblehttp/http.go) to configure HTTP requests to a data provider. Refer to the [configuration guide](https://github.com/0xPolygonID/refresh-service/blob/main/README.md) for instructions on how to set this up.
Expand Down
245 changes: 132 additions & 113 deletions docs/issuer/refresh-service/setup-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,146 +17,165 @@ keywords:
import useBaseUrl from '@docusaurus/useBaseUrl';

> **NOTE: Current implementation of [refresh service](https://github.com/0xPolygonID/refresh-service) works only with [issuer-node](https://github.com/0xPolygonID/issuer-node/).**
>
## Preparation

1. Run the issuer-node locally by following the [quick-start installation guide](https://github.com/0xPolygonID/issuer-node/#quick-start-installation).
1. Clone the refresh service using the command `git clone git@github.com:0xPolygonID/refresh-service.git`.
1. Build JSON and JSONLD schemas, utilizing the provided examples:

- [JSON](https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json/non-zero-balance.json)
- [JSONLD](https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json-ld/non-zero-balance.jsonld)
- [JSON](https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json/non-zero-balance.json)
- [JSONLD](https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json-ld/non-zero-balance.jsonld)

Generate custom schemas through the [schema builder](https://schema-builder.polygonid.me/builder). Additional details can be found in the [schema builder documentation](/docs/issuer/schema-builder/).
Generate custom schemas through the [schema builder](https://schema-builder.polygonid.me/builder). Additional details can be found in the [schema builder documentation](/docs/issuer/schema-builder/).

## Setup with custom data provider

Consider an example of integrating [polygon scan](https://polygonscan.com/) as a data provider for the refresh service.

1. Integrate the custom data provider into the [data provider module](https://github.com/0xPolygonID/refresh-service/tree/main/providers):
```go
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"`
```go
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)
}

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
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
}
```

1. Use the custom data provider within the refresh service:
1. Remove the default data provider:
```go
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
}
```
1. Use the new polygon scan data provider:
```go
// 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
}
```

1. Remove the default data provider:

```go
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
}
```

1. Use the new polygon scan data provider:

```go
// 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
}
```

1. Populate the .env variables:
```
export IPFS_URL="https://infure..."
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"
```
```
export IPFS_URL="https://infure..."
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"
```
1. Generate a blank config.yaml file:
```bash
touch config.yaml
```

```bash
touch config.yaml
```

1. Run the refresh service:
```bash
source .env
go run .
```

```bash
source .env
go run .
```

## Setup with default provider

To integrate [polygon scan](https://polygonscan.com/) data provider with the default data provider, follow these general steps:

1. Create a `config.yaml` file with the following content:
```yaml
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
```

```yaml
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
```
2. Populate the .env variables:
```
export IPFS_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"
```
```
export IPFS_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"
```

3. Run the service:
```bash
source .env
go run .
```

```bash
source .env
go run .
```

## Testing

1. Go to the issuer-node UI and generate a credential with refresh service section:

<details>
Expand Down Expand Up @@ -200,4 +219,4 @@ To integrate [polygon scan](https://polygonscan.com/) data provider with the def
<div align="center">
<img src= {useBaseUrl("img/refreshed-cred.png")} align="center" width="400px" />
</div>
</details>
</details>
2 changes: 1 addition & 1 deletion docs/verifier/on-chain-verification/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -580,5 +580,5 @@ Now that you have been able to create your first on-chain ZK-based application,
Another possibility to customize your Smart Contract involves setting different ZK requests. First of all, multiple `REQUEST_ID` must be defined inside the main Smart Contract. Therefore, the contract deployer can set a different query for each request ID and create different outcomes inside `_afterProofSubmit` according to the type of proof received. For example, an airdrop contract can verify the role of a user inside a DAO and distribute a different amount of tokens based on the role.

## Estimated Gas Costs for On-Chain Verifier
While it is clear that gas cost is highly dependent on the complexity of the logic that you add to the `_afterProofSubmit` and `_beforeProofSubmit` functions, the sample code for the on-chain verifier in this tutorial costs approximately 700k gas to execute on-chain. The zk proof verification function specifically costs approximately 520k gas. The above estimates are accurate as of January 2024.

While it is clear that gas cost is highly dependent on the complexity of the logic that you add to the `_afterProofSubmit` and `_beforeProofSubmit` functions, the sample code for the on-chain verifier in this tutorial costs approximately 700k gas to execute on-chain. The zk proof verification function specifically costs approximately 520k gas. The above estimates are accurate as of January 2024.
2 changes: 1 addition & 1 deletion docs/verifier/verification-library/zk-query-language.md
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ const proofRequest: protocol.ZKPRequest = {

## Multi query

In the example below, the verifier requests two different proof queries in the single authorization request. Queries can be created for different credentials.
In the example below, the verifier requests two different proof queries in the single authorization request. Queries can be created for different credentials.

```json
{
Expand Down
Loading

0 comments on commit 8818e06

Please sign in to comment.