mirror of
https://github.com/luxfi/onchain-id.git
synced 2026-10-30 15:23:49 +00:00
102 lines
3.7 KiB
TypeScript
102 lines
3.7 KiB
TypeScript
import { ethers } from 'hardhat';
|
|
|
|
export async function deployFactoryFixture() {
|
|
const [deployerWallet, claimIssuerWallet, aliceWallet, bobWallet, carolWallet, davidWallet] =
|
|
await ethers.getSigners();
|
|
|
|
const Identity = await ethers.getContractFactory('Identity');
|
|
const identityImplementation = await Identity.connect(deployerWallet).deploy(deployerWallet.address, true);
|
|
|
|
const ImplementationAuthority = await ethers.getContractFactory(
|
|
'ImplementationAuthority'
|
|
);
|
|
const implementationAuthority = await ImplementationAuthority.connect(deployerWallet).deploy(
|
|
identityImplementation.address,
|
|
);
|
|
|
|
const IdentityFactory = await ethers.getContractFactory('IdFactory');
|
|
const identityFactory = await IdentityFactory.connect(deployerWallet).deploy(
|
|
implementationAuthority.address,
|
|
);
|
|
|
|
return {
|
|
identityFactory,
|
|
identityImplementation,
|
|
implementationAuthority,
|
|
aliceWallet,
|
|
bobWallet,
|
|
carolWallet,
|
|
davidWallet,
|
|
deployerWallet,
|
|
claimIssuerWallet,
|
|
};
|
|
}
|
|
|
|
export async function deployIdentityFixture() {
|
|
const [deployerWallet, claimIssuerWallet, aliceWallet, bobWallet, carolWallet, davidWallet, tokenOwnerWallet] =
|
|
await ethers.getSigners();
|
|
|
|
const { identityFactory, identityImplementation, implementationAuthority } = await deployFactoryFixture();
|
|
|
|
const ClaimIssuer = await ethers.getContractFactory('ClaimIssuer');
|
|
const claimIssuer = await ClaimIssuer.connect(claimIssuerWallet).deploy(claimIssuerWallet.address);
|
|
await claimIssuer.connect(claimIssuerWallet).addKey(
|
|
ethers.utils.keccak256(
|
|
ethers.utils.defaultAbiCoder.encode(['address'], [claimIssuerWallet.address])
|
|
),
|
|
3,
|
|
1,
|
|
);
|
|
|
|
await identityFactory.connect(deployerWallet).createIdentity(aliceWallet.address, 'alice');
|
|
const aliceIdentity = await ethers.getContractAt('Identity', await identityFactory.getIdentity(aliceWallet.address));
|
|
await aliceIdentity.connect(aliceWallet).addKey(ethers.utils.keccak256(
|
|
ethers.utils.defaultAbiCoder.encode(['address'], [carolWallet.address])
|
|
), 3, 1);
|
|
await aliceIdentity.connect(aliceWallet).addKey(ethers.utils.keccak256(
|
|
ethers.utils.defaultAbiCoder.encode(['address'], [davidWallet.address])
|
|
), 2, 1);
|
|
const aliceClaim666 = {
|
|
id: '',
|
|
identity: aliceIdentity.address,
|
|
issuer: claimIssuer.address,
|
|
topic: 666,
|
|
scheme: 1,
|
|
data: '0x0042',
|
|
signature: '',
|
|
uri: 'https://example.com',
|
|
};
|
|
aliceClaim666.id = ethers.utils.keccak256(ethers.utils.defaultAbiCoder.encode(['address', 'uint256'], [aliceClaim666.issuer, aliceClaim666.topic]));
|
|
aliceClaim666.signature = await claimIssuerWallet.signMessage(ethers.utils.arrayify(ethers.utils.keccak256(ethers.utils.defaultAbiCoder.encode(['address', 'uint256', 'bytes'], [aliceClaim666.identity, aliceClaim666.topic, aliceClaim666.data]))));
|
|
|
|
await aliceIdentity.connect(aliceWallet).addClaim(aliceClaim666.topic, aliceClaim666.scheme, aliceClaim666.issuer, aliceClaim666.signature, aliceClaim666.data, aliceClaim666.uri);
|
|
|
|
await identityFactory.connect(deployerWallet).createIdentity(bobWallet.address, 'bob');
|
|
const bobIdentity = await ethers.getContractAt('Identity', await identityFactory.getIdentity(bobWallet.address));
|
|
|
|
const tokenAddress = '0xdEE019486810C7C620f6098EEcacA0244b0fa3fB';
|
|
await identityFactory.connect(deployerWallet).createTokenIdentity(tokenAddress, tokenOwnerWallet.address, 'tokenOwner');
|
|
|
|
return {
|
|
identityFactory,
|
|
identityImplementation,
|
|
implementationAuthority,
|
|
claimIssuer,
|
|
aliceWallet,
|
|
bobWallet,
|
|
carolWallet,
|
|
davidWallet,
|
|
deployerWallet,
|
|
claimIssuerWallet,
|
|
tokenOwnerWallet,
|
|
aliceIdentity,
|
|
bobIdentity,
|
|
aliceClaim666,
|
|
tokenAddress
|
|
};
|
|
}
|
|
|
|
export async function deployVerifierFixture() {
|
|
|
|
}
|