Example Repo
Clone the repo and follow the README to run the full VC flow locally
Live Demo
Try the live demo
Prerequisites
| Requirement | Details |
|---|---|
| Newton SDK | @magicnewton/newton-protocol-sdk installed in your JavaScript/TypeScript app |
| Newton API key | Create one in the dashboard |
| Policy client contract | Must inherit NewtonPolicyClient + EIP712 and be registered with PolicyClientRegistry |
| Identity domain | A fixed bytes32 hex value for your application — the output of keccak256("kyc") |
| KYC vendor | A third-party vendor to collect user identity data. The vendor’s output must map to Newton’s IdentityData fields. |
Step 1: Write and Deploy a Policy
1a. Write your Rego policy
Write a Rego policy that uses Newton identity built-in functions. For example, to enforce that a user is approved and at least 18 years old:1b. Write your params_schema.json
Define the schema for your policy params, including the identity_domain:
1c. Write your policy_metadata.json
Verifiable Credential policies do not use a
secrets_schema.json or policy_data_metadata.json. You only need policy_metadata.json and params_schema.json.1d. Deploy your policy using newton-cli
Your policy directory should look like this before deploying:policy_cids.json file with the Newton CLI command documented here.
Deploy the policy contract
Once you have policy_cids.json, run:
Step 2: Deploy a Policy Client Contract
Your policy client must inherit from bothNewtonPolicyClient and EIP712. See the Reference for a complete sample contract.
Key requirements:
- Inherit
NewtonPolicyClientandEIP712 - Call
_initNewtonPolicyClient(policyTaskManager, owner)in the constructor - Register the contract with the
PolicyClientRegistry— see Smart Contract Integration
setPolicyAddress(policyContractAddress)— point it to the policy deployed in Step 1setPolicy(params)— set the policy params, including your identity domain:
Step 3: Collect KYC Data
Collect identity data from your users using a third-party KYC vendor. The data you receive from the vendor must map to Newton’s IdentityData fields — fields likestatus, birthdate, address_country_code, etc.
Step 4: Register and Confirm KYC Data
4a. Register KYC Data
Once you have the KYC data from your vendor, callregisterUserData to register it with Newton, scoped to your identity domain:
When the Newton identity popup opens, Newton creates a new wallet for the user to manage their identity. The user will need to fund this wallet with ETH to continue.
4b. User Confirms KYC Data
The user sees a confirmation prompt in the Newton identity popup to verify the KYC data being registered. This is handled automatically by the popup opened in step 4a — no additional SDK calls are required.Step 5: Link Identity to Your App
5a. Initiate Identity Link
CalllinkApp to link the user’s registered identity to your policy client contract:
IdentityRegistry. After this link is established, Newton’s policy engine can access the user’s registered KYC data when evaluating tasks submitted through your policy client.
You can find the IdentityRegistry contract address in Contract Addresses.
5b. User Confirms the Link
The user completes the link confirmation in the Newton identity popup. Under the hood, this callslinkIdentityAsUser on the IdentityRegistry contract — a transaction signed by the user’s Newton identity wallet.
Step 6: Submit a Task
Submit a task with a signed intent from the user’s dapp wallet. The intent must be constructed and signed using the EIP712 domain of your policy client. 1. Construct the intentStep 7: Execute On-Chain Transaction with Attestation
Use the attestation returned in Step 6 to execute the transaction on-chain through your policy client.validateAndExecuteDirect verifies the attestation on-chain and executes the call — only if the policy passed.
Unlinking
To remove a user’s identity link from your app, callunlinkApp:
Reference Pages
SDK & Contract Reference
Full SDK method signatures and contract functions
Identity Policy Reference
All Rego built-in functions for identity checks
Have questions?
Get in touch with someone from the Newton team to discuss your integration