Skip to content

Commit

Permalink
changed getting transit params in zkp-gen package
Browse files Browse the repository at this point in the history
  • Loading branch information
lukachi committed Aug 25, 2023
1 parent d46a39a commit 0c9005e
Show file tree
Hide file tree
Showing 24 changed files with 91 additions and 79 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0.0-rc.20] - 2023-08-25
### Added
- `@rarimo/client` - `getOperation` method and followed types
- `@rarimo/zkp-gen-iden3` - `getOperation` method
-
### Changed
- `@rarimo/zkp-gen-iden3` - getting params for transiting state (`loadParamsForTransitState`)

### Removed
- `@rarimo/client` - `getIdentityParams` method and followed types
- `@rarimo/shared-zkp-iden3` - IdentityNode query

## [2.0.0-rc.19] - 2023-08-22
### Changed
- `@rarimo/auth-zkp-iden3` - config options
Expand Down Expand Up @@ -432,7 +444,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Under the hood changes
- Initiated repo with `@rarimo/provider` and `@rarimo/nft-checkout` packages

[Unreleased]: https://github.com/rarimo/js-sdk/compare/2.0.0-rc.19...HEAD
[Unreleased]: https://github.com/rarimo/js-sdk/compare/2.0.0-rc.20...HEAD
[2.0.0-rc.20]: https://github.com/rarimo/js-sdk/compare/2.0.0-rc.19...2.0.0-rc.20
[2.0.0-rc.19]: https://github.com/rarimo/js-sdk/compare/2.0.0-rc.18...2.0.0-rc.19
[2.0.0-rc.18]: https://github.com/rarimo/js-sdk/compare/2.0.0-rc.17...2.0.0-rc.18
[2.0.0-rc.17]: https://github.com/rarimo/js-sdk/compare/2.0.0-rc.16...2.0.0-rc.17
Expand Down
2 changes: 1 addition & 1 deletion packages/auth-zkp-iden3/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/auth-zkp-iden3",
"version": "2.0.0-rc.19",
"version": "2.0.0-rc.20",
"description": "Tools that authenticate a zero-knowledge proof and provide verifiable credentials from it.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/bridge",
"version": "2.0.0-rc.19",
"version": "2.0.0-rc.20",
"description": "Internal tools that other Rarimo packages use to bridge tokens.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/client",
"version": "2.0.0-rc.19",
"version": "2.0.0-rc.20",
"description": "The Rarimo chain client",
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/enums/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './auth'
export * from './gov'
export * from './operation'
export * from './staking'
export * from './tokenmanager'
6 changes: 6 additions & 0 deletions packages/client/src/enums/operation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum OperationStatus {
Signed = 'SIGNED',
Initialized = 'INITIALIZED',
Approved = 'APPROVED',
NotApproved = 'NOT_APPROVED',
}
12 changes: 6 additions & 6 deletions packages/client/src/querier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import type {
GetStateInfoResponse,
GovParams,
IdentityNode,
IdentityParams,
MerkleProof,
NodeInfo,
Operation,
OperationProof,
Proposal,
RarimoQuerier,
Expand Down Expand Up @@ -91,11 +91,11 @@ export const makeRarimoQuerier = (
return data!
}

const getIdentityParams = async () => {
const endpoint = '/rarimo/rarimo-core/identity/params'
const { data } = await api.get<IdentityParams>(endpoint)
const getOperation = async (index: string) => {
const endpoint = `/rarimo/rarimo-core/rarimocore/operation/${index}`
const { data } = await api.get<{ operation: Operation }>(endpoint)

return data!
return data!.operation!
}

const getIdentityNodeByKey = async (key: string) => {
Expand All @@ -116,7 +116,7 @@ export const makeRarimoQuerier = (
getMerkleProof,
getState,
getOperationProof,
getIdentityParams,
getOperation,
getIdentityNodeByKey,
}
}
11 changes: 3 additions & 8 deletions packages/client/src/types/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@ import type { Coin } from './bank'
import type { RarimoBroadcaster } from './broadcaster'
import type { Config } from './config'
import type { GovParams, Proposal } from './gov'
import type {
IdentityNode,
IdentityParams,
MerkleProof,
StateInfo,
} from './identity'
import type { OperationProof } from './rarimocore'
import type { IdentityNode, MerkleProof, StateInfo } from './identity'
import type { Operation, OperationProof } from './rarimocore'
import type { DelegationResponse } from './staking'
import type { NodeInfo } from './tendermint'

Expand Down Expand Up @@ -50,7 +45,7 @@ export type RarimoQuerier = {
getState(id: string): Promise<StateInfo>
// rarimocore/rarimocore
getOperationProof(index: string): Promise<OperationProof>
getIdentityParams(): Promise<IdentityParams>
getOperation(index: string): Promise<Operation>
getIdentityNodeByKey(key: string): Promise<IdentityNode>
}

Expand Down
15 changes: 0 additions & 15 deletions packages/client/src/types/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,3 @@ export type IdentityNode = {
childrenHash: string
}
}

export type IdentityParams = {
params: {
lcgA: string
lcgB: string
lcgMod: string
lcgValue: string
identityContractAddress: string
chainName: string
GISTHash: string
GISTUpdatedTimestamp: string
treapRootKey: string
statesWaitingForSign: [string]
}
}
18 changes: 18 additions & 0 deletions packages/client/src/types/rarimocore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
import type { OperationStatus } from '@/enums'

export type OperationProof = {
path: string[]
signature: string
}

export type Operation = {
index: string
operationType: string
details: {
'@type': string
contract: string
chain: string
GISTHash: string
stateRootHash: string
timestamp: string
}
status: OperationStatus
creator: string
timestamp: string
}
2 changes: 1 addition & 1 deletion packages/identity-gen-iden3/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/identity-gen-iden3",
"version": "2.0.0-rc.19",
"version": "2.0.0-rc.20",
"description": "Tools that generate distributed identities for the Iden3 protocol.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/nft-checkout/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/nft-checkout",
"version": "2.0.0-rc.19",
"version": "2.0.0-rc.20",
"description": "Features of the Rarimo SDK that create cross-chain transactions based on the Rarimo protocol.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/provider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/provider",
"version": "2.0.0-rc.19",
"version": "2.0.0-rc.20",
"description": "A common interface for access to wallets (EVM and non-EVM) in the Rarimo SDK, used by packages that provide access to wallets on specific chains such as @rarimo/providers-evm, @rarimo/providers-solana, and @rarimo/providers-near.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/providers-evm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/providers-evm",
"version": "2.0.0-rc.19",
"version": "2.0.0-rc.20",
"description": "Features of the Rarimo SDK that provide access to wallets and the ability to interact with them on EVM-compatible blockchains.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/providers-near/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/providers-near",
"version": "2.0.0-rc.19",
"version": "2.0.0-rc.20",
"description": "Features of the Rarimo SDK that provide access to wallets and the ability to interact with them on the NEAR blockchain.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/providers-solana/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/providers-solana",
"version": "2.0.0-rc.19",
"version": "2.0.0-rc.20",
"description": "Features of the Rarimo SDK that provide access to wallets and the ability to interact with them on the Solana blockchain.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-nft-checkout/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/react-nft-checkout",
"version": "2.0.0-rc.19",
"version": "2.0.0-rc.20",
"description": "React components that you can use in your UI to create cross-chain transactions with the Rarimo protocol.",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-provider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/react-provider",
"version": "2.0.0-rc.19",
"version": "2.0.0-rc.20",
"description": "Tools to connect to wallets in React applications through the Rarimo SDK.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/shared-zkp-iden3/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/shared-zkp-iden3",
"version": "2.0.0-rc.19",
"version": "2.0.0-rc.20",
"description": "Internal tools that other Rarimo packages use for identity functionality.",
"repository": {
"type": "git",
Expand Down
21 changes: 5 additions & 16 deletions packages/shared-zkp-iden3/src/helpers/state-v2-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import type {
IdentityNode,
IdentityParams,
RarimoQuerier,
StateInfo,
} from '@rarimo/client'
import type { Operation, RarimoQuerier, StateInfo } from '@rarimo/client'
import type { RawProvider } from '@rarimo/provider'
import { isString } from '@rarimo/shared'
import { providers } from 'ethers'
Expand Down Expand Up @@ -97,15 +92,9 @@ export const getTransitStateTxBody = (
}
}

export const getIdentityParams = async (
export const getOperation = async (
querier: RarimoQuerier,
): Promise<IdentityParams> => {
return querier.getIdentityParams()
}

export const getIdentityNode = async (
querier: RarimoQuerier,
key: string,
): Promise<IdentityNode> => {
return querier.getIdentityNodeByKey(key)
index: string,
): Promise<Operation> => {
return querier.getOperation(index)
}
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/shared",
"version": "2.0.0-rc.19",
"version": "2.0.0-rc.20",
"description": "Utility functions, types and constants shared across Rarimo packages.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/swap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/swap",
"version": "2.0.0-rc.19",
"version": "2.0.0-rc.20",
"description": "Internal tools that other Rarimo packages use to swap tokens.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/zkp-gen-iden3/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/zkp-gen-iden3",
"version": "2.0.0-rc.19",
"version": "2.0.0-rc.20",
"description": "Tools that generate zero-knowledge proofs for the Iden3 protocol.",
"repository": {
"type": "git",
Expand Down
41 changes: 23 additions & 18 deletions packages/zkp-gen-iden3/src/zkp-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ import {
Proof,
} from '@iden3/js-merkletree'
import type { VerifiableCredentials } from '@rarimo/auth-zkp-iden3'
import type { MerkleProof, OperationProof, RarimoQuerier } from '@rarimo/client'
import type {
MerkleProof,
Operation,
OperationProof,
RarimoQuerier,
} from '@rarimo/client'
import { type Identity } from '@rarimo/identity-gen-iden3'
import { isString, omit } from '@rarimo/shared'
import {
getBytesFile,
getCoreChainStateInfo,
getGISTProof,
getGISTRootInfo,
getIdentityNode,
getIdentityParams,
getOperation,
unmarshalBinary,
} from '@rarimo/shared-zkp-iden3'
import { Buffer } from 'buffer'
Expand Down Expand Up @@ -93,6 +97,7 @@ export class ZkpGen<T extends QueryVariableNameAbstract> {
public targetStateDetails?: Awaited<ReturnType<typeof getGISTRootInfo>>
public coreStateDetails?: Awaited<ReturnType<typeof getCoreChainStateInfo>>
public operationProof?: OperationProof
public operation?: Operation
public merkleProof?: MerkleProof

public circuitWasm?: Uint8Array
Expand Down Expand Up @@ -654,16 +659,19 @@ export class ZkpGen<T extends QueryVariableNameAbstract> {
targetStateDetails,
coreStateDetails,
operationProof,
operation,
merkleProof,
}: {
targetStateDetails?: Awaited<ReturnType<typeof getGISTRootInfo>>
coreStateDetails?: Awaited<ReturnType<typeof getCoreChainStateInfo>>
operationProof?: OperationProof
operation?: Operation
merkleProof?: MerkleProof
}) {
this.targetStateDetails = targetStateDetails
this.coreStateDetails = coreStateDetails
this.operationProof = operationProof
this.operation = operation
this.merkleProof = merkleProof
}

Expand All @@ -688,6 +696,10 @@ export class ZkpGen<T extends QueryVariableNameAbstract> {
this.operationProof = await querier.getOperationProof(operationIndex)
}

public async loadOperation(querier: RarimoQuerier, operationIndex: string) {
this.operation = await getOperation(querier, operationIndex)
}

public async loadMerkleProof(querier: RarimoQuerier, issuerId: string) {
this.merkleProof = await querier.getMerkleProof(issuerId)
}
Expand All @@ -700,25 +712,18 @@ export class ZkpGen<T extends QueryVariableNameAbstract> {
)
}

public async loadParamsForTransitState(
querier: RarimoQuerier,
opts?: {
operationProof?: OperationProof
},
) {
public async loadParamsForTransitState(opts?: {
operationProof?: OperationProof
operation?: Operation
}) {
const currOperationProof = opts?.operationProof || this.operationProof

const identityParams = await getIdentityParams(querier)

const identityNode = await getIdentityNode(
querier,
identityParams.params.treapRootKey,
)
const currOperation = opts?.operation || this.operation

const newIdentitiesStatesRoot = identityNode.node.hash
const newIdentitiesStatesRoot = currOperation?.details?.stateRootHash
const gistData = {
root: identityParams.params.GISTHash,
createdAtTimestamp: identityParams.params.GISTUpdatedTimestamp,
root: currOperation?.details?.GISTHash,
createdAtTimestamp: currOperation?.details?.timestamp,
}

const decodedPath = currOperationProof?.path?.map((el: string) =>
Expand Down

0 comments on commit 0c9005e

Please sign in to comment.