Skip to content

Commit

Permalink
Add etherium DID registry and universal DID resolver contract to genesis
Browse files Browse the repository at this point in the history
Signed-off-by: aziz.karabashov <[email protected]>
  • Loading branch information
akarabashov committed Dec 6, 2023
1 parent a15f6c7 commit 35e785b
Show file tree
Hide file tree
Showing 17 changed files with 149 additions and 62 deletions.
4 changes: 2 additions & 2 deletions indy-besu/docs/design/cl-registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
| parameter | value |
|--------------------|-----------------------------------------------------------------|
| id | “did:” method-name “:” namespace “:” method-specific-id |
| method-name | “indy2” |
| method-name | “indy2”, “indy”, “sov”, “ethr” |
| namespace | “testnet”/"mainnet" |
| indy-id | <issuer_did>/anoncreds/v0/SCHEMA/<schema_name>/<schema_version> |

Expand Down Expand Up @@ -136,7 +136,7 @@ Contract name: **SchemaRegistry**
| parameter | value |
|--------------------|---------------------------------------------------------|
| id | “did:” method-name “:” namespace “:” method-specific-id |
| method-name | “indy2” |
| method-name | “indy2”, “indy”, “sov”, “ethr” |
| namespace | “testnet”/"mainnet" |
| indy-id | <issuer_did>/anoncreds/v0/CLAIM_DEF/<schema_id>/<name> |
Expand Down
2 changes: 1 addition & 1 deletion indy-besu/docs/design/did-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Example:
| parameter | value |
|--------------------|---------------------------------------------------------|
| did | “did:” method-name “:” namespace “:” method-specific-id |
| method-name | "indy2" |
| method-name | indy2”, “indy”, “sov” |
| namespace | “testnet”/"mainnet" |
| method-specific-id | indy-id |
| indy-id | Base58(Truncate_msb(16(SHA256(publicKey)))) |
Expand Down
87 changes: 55 additions & 32 deletions indy-besu/network/config/besu/genesis.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion indy-besu/smart_contracts/contracts-ts/DidRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class DidRegistry extends Contract {
public async resolveDid(id: string): Promise<DidDocumentStorage> {
const didDocumentStorage = await this.instance.resolveDid(id)
return {
document: mapDidDocument(didDocumentStorage.didDocument),
document: mapDidDocument(didDocumentStorage.document),
metadata: mapDidMetadata(didDocumentStorage.metadata),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Contract } from '../utils'
import { DidDocument, DidMetadata, mapDidDocument, mapDidMetadata } from './types'

export class UniversalDidResolver extends Contract {
public static readonly defaultAddress = '0x0000000000000000000000000000000000003030'
public static readonly defaultAddress = '0x000000000000000000000000000000000019999'

constructor(sender?: any) {
super(UniversalDidResolver.name, sender)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ contract CredentialDefinitionRegistry is CredentialDefinitionRegistryInterface,
}

function initialize(
address issuerValidatorAddress,
address schemaRegistryAddress,
address upgradeControlAddress
address upgradeControlAddress,
address didResolverAddress,
address schemaRegistryAddress
) public reinitializer(1) {
_didResolver = UniversalDidResolverInterface(issuerValidatorAddress);
_schemaRegistry = SchemaRegistryInterface(schemaRegistryAddress);
_initializeUpgradeControl(upgradeControlAddress);
_didResolver = UniversalDidResolverInterface(didResolverAddress);
_schemaRegistry = SchemaRegistryInterface(schemaRegistryAddress);
}

/// @inheritdoc CredentialDefinitionRegistryInterface
Expand Down
4 changes: 2 additions & 2 deletions indy-besu/smart_contracts/contracts/cl/SchemaRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ contract SchemaRegistry is SchemaRegistryInterface, ControlledUpgradeable, CLReg
_;
}

function initialize(address didRegistryAddress, address upgradeControlAddress) public reinitializer(1) {
_didResolver = UniversalDidResolverInterface(didRegistryAddress);
function initialize(address upgradeControlAddress, address didResolverAddress) public reinitializer(1) {
_initializeUpgradeControl(upgradeControlAddress);
_didResolver = UniversalDidResolverInterface(didResolverAddress);
}

/// @inheritdoc SchemaRegistryInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ contract UniversalDidResolver is UniversalDidResolverInterface, ControlledUpgrad
EthereumDIDRegistry internal _ethereumDIDRegistry;

function initialize(
address ethereumDIDRegistryAddress,
address upgradeControlAddress,
address didRegistryddress,
address upgradeControlAddress
address ethereumDIDRegistryAddress
) public reinitializer(1) {
_ethereumDIDRegistry = EthereumDIDRegistry(ethereumDIDRegistryAddress);
_didRegistry = DidRegistryInterface(didRegistryddress);
_initializeUpgradeControl(upgradeControlAddress);
_didRegistry = DidRegistryInterface(didRegistryddress);
_ethereumDIDRegistry = EthereumDIDRegistry(ethereumDIDRegistryAddress);
}

/// @inheritdoc UniversalDidResolverInterface
Expand Down
2 changes: 1 addition & 1 deletion indy-besu/smart_contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"demo/upgrade": "yarn run-on-besu demos/upgrade-control.ts",
"genesis/generate": "ts-node scripts/genesis/generate.ts",
"postinstall": "cd ../../ && husky install indy-besu/smart_contracts/.husky",
"solc-compile": "solc -o compiled-contracts --optimize --bin-runtime --evm-version=constantinople @dk1a=$(pwd)/node_modules/@dk1a @openzeppelin=$(pwd)/node_modules/@openzeppelin contracts/**/*.sol node_modules/@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"
"solc-compile": "solc -o compiled-contracts --optimize --bin-runtime --evm-version=constantinople @dk1a=$(pwd)/node_modules/@dk1a @openzeppelin=$(pwd)/node_modules/@openzeppelin ethr-did-registry=$(pwd)/node_modules/ethr-did-registry contracts/**/*.sol node_modules/@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"
},
"license": "Apache-2.0",
"dependencies": {
Expand Down
23 changes: 22 additions & 1 deletion indy-besu/smart_contracts/scripts/genesis/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import {
DidRegexConfig,
DidsConfig,
DidValidatorConfig,
EthereumDidRegistryConfig,
RolesConfig,
SchemasConfig,
UniversalDidResolverConfig,
ValidatorsConfig,
} from './contracts'
import { UpgradeControlConfig } from './contracts/upgradeControl'
Expand All @@ -20,8 +22,10 @@ export interface Config {
didValidator: DidValidatorConfig
didRegistry: DidsConfig
didRegex: DidRegexConfig
ethereumDidRegistry: EthereumDidRegistryConfig
roleControl: RolesConfig
schemaRegistry: SchemasConfig
universalDidResolver: UniversalDidResolverConfig
upgradeControl: UpgradeControlConfig
validatorControl: ValidatorsConfig
}
Expand All @@ -36,6 +40,8 @@ const contractsAddresses = {
validators: '0x0000000000000000000000000000000000007777',
accountControl: '0x0000000000000000000000000000000000008888',
upgradeControl: '0x0000000000000000000000000000000000009999',
universalDidResolver: '0x000000000000000000000000000000000019999',
ethereumDIDRegistry: '0x0000000000000000000000000000000000018888',
}

export const config: Config = {
Expand All @@ -54,7 +60,7 @@ export const config: Config = {
description: 'Smart contract to manage credential definitions',
data: {
credentialDefinitions: [],
didRegistryAddress: contractsAddresses.didRegistry,
universalDidResolverAddress: contractsAddresses.universalDidResolver,
schemaRegistryAddress: contractsAddresses.schemas,
upgradeControlAddress: contractsAddresses.upgradeControl,
},
Expand All @@ -80,6 +86,11 @@ export const config: Config = {
upgradeControlAddress: contractsAddresses.upgradeControl,
},
},
ethereumDidRegistry: {
name: 'EthereumDidRegistry',
address: contractsAddresses.ethereumDIDRegistry,
description: 'Ethereum registry for ERC-1056 ethr did methods',
},
roleControl: {
name: 'RoleControl',
address: contractsAddresses.roles,
Expand Down Expand Up @@ -121,6 +132,16 @@ export const config: Config = {
description: 'Smart contract to manage schemas',
data: {
schemas: [],
universalDidResolverAddress: contractsAddresses.universalDidResolver,
upgradeControlAddress: contractsAddresses.upgradeControl,
},
},
universalDidResolver: {
name: 'UniversalDidResolver',
address: contractsAddresses.universalDidResolver,
description: 'Smart contract to resolve DIDs from various DID registries',
data: {
etheriumDidRegistryAddress: contractsAddresses.ethereumDIDRegistry,
didRegistryAddress: contractsAddresses.didRegistry,
upgradeControlAddress: contractsAddresses.upgradeControl,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { buildProxySection, slots } from '../helpers'
export interface CredentialDefinitionsConfig extends ContractConfig {
data: {
credentialDefinitions: Array<{ id: string; data: { name: string } }>
didRegistryAddress: string
universalDidResolverAddress: string
schemaRegistryAddress: string
upgradeControlAddress: string
}
Expand All @@ -16,11 +16,11 @@ export function credentialDefinitionRegistry() {
const { name, address, description, data } = config.credentialDefinitionRegistry
const storage: any = {}

// address of upgrade control contact stored in slot 2
// address of upgrade control contact stored in slot 0
storage[slots['0']] = padLeft(data.upgradeControlAddress, 64)
// address of DID registry contact stored in slot 0
storage[slots['1']] = padLeft(data.didRegistryAddress, 64)
// address of schema registry contact stored in slot 1
// address of DID registry contact stored in slot 1
storage[slots['1']] = padLeft(data.universalDidResolverAddress, 64)
// address of schema registry contact stored in slot 2
storage[slots['2']] = padLeft(data.schemaRegistryAddress, 64)
return buildProxySection(name, address, description, storage)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { config } from '../config'
import { ContractConfig } from '../contractConfig'
import { buildSection } from '../helpers'

export interface EthereumDidRegistryConfig extends ContractConfig {}

export function ethereumDidRegistry() {
const { name, address, description } = config.ethereumDidRegistry
const storage: any = {}

return buildSection(name, address, description, storage)
}
2 changes: 2 additions & 0 deletions indy-besu/smart_contracts/scripts/genesis/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ export * from './credentialDefinitionRegistry'
export * from './didRegistry'
export * from './didRegex'
export * from './didValidator'
export * from './ethereumDidRegistry'
export * from './roleControl'
export * from './schemaRegistry'
export * from './universalDidResolver'
export * from './upgradeControl'
export * from './validatorControl'
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { buildProxySection, slots } from '../helpers'
export interface SchemasConfig extends ContractConfig {
data: {
schemas: Array<{ id: string; data: { name: string } }>
didRegistryAddress: string
universalDidResolverAddress: string
upgradeControlAddress: string
}
}
Expand All @@ -15,9 +15,9 @@ export function schemaRegistry() {
const { name, address, description, data } = config.schemaRegistry
const storage: any = {}

// address of upgrade control contact stored in slot 1
// address of upgrade control contact stored in slot 0
storage[slots['0']] = padLeft(data.upgradeControlAddress, 64)
// address of DID registry contact stored in slot 0
storage[slots['1']] = padLeft(data.didRegistryAddress, 64)
// address of DID resolver contact stored in slot 1
storage[slots['1']] = padLeft(data.universalDidResolverAddress, 64)
return buildProxySection(name, address, description, storage)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { padLeft } from 'web3-utils'
import { config } from '../config'
import { ContractConfig } from '../contractConfig'
import { buildProxySection, slots } from '../helpers'

export interface UniversalDidResolverConfig extends ContractConfig {
data: {
didRegistryAddress: string
etheriumDidRegistryAddress: string
upgradeControlAddress: string
}
}

export function universalDidResolver() {
const { name, address, description, data } = config.universalDidResolver
const storage: any = {}

// address of upgrade control contact stored in slot 0
storage[slots['0']] = padLeft(data.upgradeControlAddress, 64)
// address of DID registry contact stored in slot 1
storage[slots['1']] = padLeft(data.didRegistryAddress, 64)
// address of etherium DID registry contact stored in slot 2
storage[slots['2']] = padLeft(data.etheriumDidRegistryAddress, 64)
return buildProxySection(name, address, description, storage)
}
4 changes: 4 additions & 0 deletions indy-besu/smart_contracts/scripts/genesis/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import {
didRegex,
didRegistry,
didValidator,
ethereumDidRegistry,
roleControl,
schemaRegistry,
universalDidResolver,
upgradeControl,
validatorControl,
} from './contracts'
Expand All @@ -21,6 +23,8 @@ function main() {
...didRegex(),
...didValidator(),
...didRegistry(),
...ethereumDidRegistry(),
...universalDidResolver(),
...schemaRegistry(),
...credentialDefinitionRegistry(),
}
Expand Down
6 changes: 3 additions & 3 deletions indy-besu/smart_contracts/test/utils/contract-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export async function deployUniversalDidResolver() {
const ethereumDIDRegistry = await new EthereumDIDRegistry().deploy()

const universalDidReolver = await new TestableUniversalDidResolver().deployProxy({
params: [ethereumDIDRegistry.address, didRegistry.address, ZERO_ADDRESS],
params: [ZERO_ADDRESS, didRegistry.address, ethereumDIDRegistry.address],
})

return { universalDidReolver, ethereumDIDRegistry, didRegistry, testAccounts }
Expand All @@ -73,7 +73,7 @@ export async function deployUniversalDidResolver() {
export async function deploySchemaRegistry() {
const { universalDidReolver, didRegistry, testAccounts } = await deployUniversalDidResolver()
const schemaRegistry = await new TestableSchemaRegistry().deployProxy({
params: [universalDidReolver.address, ZERO_ADDRESS],
params: [ZERO_ADDRESS, universalDidReolver.address],
})

return { universalDidReolver, didRegistry, schemaRegistry, testAccounts }
Expand All @@ -82,7 +82,7 @@ export async function deploySchemaRegistry() {
export async function deployCredentialDefinitionRegistry() {
const { universalDidReolver, didRegistry, schemaRegistry, testAccounts } = await deploySchemaRegistry()
const credentialDefinitionRegistry = await new TestableCredentialDefinitionRegistry().deployProxy({
params: [universalDidReolver.address, schemaRegistry.address, ZERO_ADDRESS],
params: [ZERO_ADDRESS, universalDidReolver.address, schemaRegistry.address],
})

return { credentialDefinitionRegistry, universalDidReolver, didRegistry, schemaRegistry, testAccounts }
Expand Down

0 comments on commit 35e785b

Please sign in to comment.