Identity Protocol JS-SDK reference
The Rarimo SDK identity packages provide tools for the identity protocol.
@rarimo/shared-zkp-iden3
The @rarimo/shared-zkp-iden3 package provides constants, types, and tools other packages used for identity functionality.
@rarimo/auth-zkp-iden3
The @rarimo/auth-zkp-iden3 package provides tools that authenticate a zero-knowledge proof and provide verifiable credentials from it.
Usage example:
import { AuthZkp } from '@rarimo/auth-zkp-iden3'
import { type Identity } from '@rarimo/identity-gen-iden3'
/**
* define type with variable to proof,
* verifiableCredentials response will keep this variable in credentialSubject
*/
type QueryVariableName = { isNatural: number }
const getVerifiableCredentials = async (identity: Identity) => {
/**
* Setup config is necessary to let AuthZkp works properly
*/
AuthZkp.setConfig({
// rpc url where statev2 contract is deployed
RPC_URL: 'https://matic-mumbai.chainstacklabs.com',
// statev2 contract address
STATE_V2_ADDRESS: '0x134B1BE34911E39A8397ec6289782989729807a4',
// api url of issuer svc
ISSUER_API_URL: 'http://127.0.0.1:8000/',
})
const authProof = new AuthZkp<QueryVariableName>(identity)
const verifiableCredentials = await authProof.getVerifiableCredentials()
}
@rarimo/identity-gen-iden3
The @rarimo/identity-gen-iden3 package provides tools to generate distributed identities for the Iden3 protocol.
Usage example:
Identity.setConfig({
AUTH_BJJ_CREDENTIAL_HASH: '[your_hash]',
})
const identity = await Identity.create()
@rarimo/zkp-gen-iden3
The @rarimo/zkp-gen-iden3 package provides tools to generate zero-knowledge proofs for the Iden3 protocol.
Usage example:
import { CircuitId, ZkpGen, ZkpOperators } from '@rarimo/zkp-gen-iden3'
import { type Identity } from '@rarimo/identity-gen-iden3'
import { type VerifiableCredentials } from '@rarimo/auth-zkp-iden3'
/**
* define type with variable to proof,
* verifiableCredentials response will keep this variable in credentialSubject
*/
type QueryVariableName = { isNatural: number }
const getZkProof = async (
identity: Identity,
verifiableCredentials: VerifiableCredentials,
providerAddress: string
) => {
ZkpGen.setConfig({
// rpc url where statev2 contract is deployed
RPC_URL: 'https://matic-mumbai.chainstacklabs.com',
// statev2 contract address
STATE_V2_ADDRESS: '0x134B1BE34911E39A8397ec6289782989729807a4',
// api url of issuer svc
ISSUER_API_URL: 'http://127.0.0.1:8000/',
})
const zkProof = new ZkpGen<QueryVariableName>({
/**
* In zkp environment, every prove request should have a unique requestId
* by using this requestId, issuer svc can identify the request
*/
requestId: '1',
/**
* Identity generated by @rarimo/identity-gen-iden3
*/
identity: identity,
/**
* Verifiable credentials generated by @rarimo/auth-zkp-iden3
*/
verifiableCredentials: verifiableCredentials,
/**
* Challenge is a random string for example user metamask address without '0x'
*/
challenge: String(providerAddress).substring(2),
/**
* Query is a json object with variable to proof
*/
query: {
/**
* variableName is the name of variable to proof
*/
variableName: 'isNatural',
/**
* operator is the operator to compare the variable with value
*/
operator: ZkpOperators.Equals,
/**
* value is the value to compare with variable
*/
value: ['1'],
circuitId: CircuitId.AtomicQueryMTPV2OnChain,
issuerId: config.ISSUER_ID,
},
})
await zkProof.generateProof()
setIsNaturalProof(zkProof)
}