-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
2,874 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { artifacts, ethers } from 'hardhat'; | ||
import { TokenboundClient } from '@tokenbound/sdk'; | ||
import { IoID, IoIDRegistry } from '../typechain-types'; | ||
|
||
const SortedTroves = artifacts.require('SortedTroves'); | ||
|
||
async function main() { | ||
const network = await ethers.provider.getNetwork(); | ||
const chainId = Number(network.chainId.toString()); | ||
const owner = new ethers.Wallet(process.env.PRIVATE_KEY!, ethers.provider); | ||
console.log(`owner: ${owner.address}`); | ||
|
||
const deviceNFTFactory = await ethers.getContractFactory('DeviceNFT'); | ||
const deviceGaugeFactory = await ethers.getContractFactory('DummyDeviceGauge'); | ||
const deviceGauge = deviceGaugeFactory.attach('0x6af1F299aa518423F469D5e89b4FBb2B81d89a5B'); | ||
const ioIDRegistryFactory = await ethers.getContractFactory('ioIDRegistry'); | ||
const ioIDRegistry = ioIDRegistryFactory.attach('0x04e4655Cf258EC802D17c23ec6112Ef7d97Fa2aF') as IoIDRegistry; | ||
const ioIDFactory = await ethers.getContractFactory('ioID'); | ||
const ioID = ioIDFactory.attach('0x1FCB980eD0287777ab05ADc93012332e11300e54') as IoID; | ||
|
||
// @ts-ignore | ||
const tokenboundClient = new TokenboundClient({ | ||
chain: { | ||
id: chainId, | ||
name: 'IoTeX Testnet', | ||
network: 'mainnet', | ||
rpcUrls: { | ||
default: { | ||
http: ['https://babel-api.mainnet.iotex.io'], | ||
}, | ||
public: { | ||
http: ['https://babel-api.mainnet.iotex.io'], | ||
}, | ||
}, | ||
nativeCurrency: { | ||
name: 'IoTeX', | ||
symbol: 'IOTX', | ||
decimals: 18, | ||
}, | ||
}, | ||
// registryAddress: '0x000000006551c19487814612e58FE06813775758', | ||
// implementationAddress: '0x1d1C779932271e9Dc683d5373E84Fa4239F2b3fb', | ||
signer: owner, | ||
}); | ||
|
||
const did = await ioIDRegistry.documentID('0xdCD0a79a5A2bdC1392B31573dA3B960985E98dcb'); | ||
const wallet = await ioID['wallet(string)'](did); | ||
const approveCall = await tokenboundClient.execute({ | ||
account: wallet, | ||
to: '0xB31d7d8950C490F316A0A553b141994249Be4012', | ||
value: BigInt(0), | ||
data: deviceNFTFactory.interface.encodeFunctionData('approve', [deviceGauge.target, 1]), | ||
}); | ||
console.log(`${wallet} approve txHash: ${approveCall}`); | ||
} | ||
|
||
main().catch(err => { | ||
console.error(err); | ||
process.exitCode = 1; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { ethers } from 'hardhat'; | ||
|
||
import { IoIDRegistry, VerifyingProxy } from '../typechain-types'; | ||
import { getBytes, keccak256, solidityPacked } from 'ethers'; | ||
|
||
async function main() { | ||
const [verifier] = await ethers.getSigners(); | ||
const owner = ethers.Wallet.createRandom(); | ||
|
||
const network = await ethers.provider.getNetwork(); | ||
const chainId = Number(network.chainId.toString()); | ||
const ioIDRegistryFactory = await ethers.getContractFactory('ioIDRegistry'); | ||
const ioIDRegistry = ioIDRegistryFactory.attach('0x04e4655Cf258EC802D17c23ec6112Ef7d97Fa2aF') as IoIDRegistry; | ||
const verifyingProxyFactory = await ethers.getContractFactory('VerifyingProxy'); | ||
const verifyingProxy = verifyingProxyFactory.attach('0xa5c293471ef44625d9ef079296ff4f223405714d') as VerifyingProxy; | ||
|
||
const device = ethers.Wallet.createRandom(); | ||
const domain = { | ||
name: 'ioIDRegistry', | ||
version: '1', | ||
chainId: chainId, | ||
verifyingContract: ioIDRegistry.target, | ||
}; | ||
const types = { | ||
Permit: [ | ||
{ name: 'owner', type: 'address' }, | ||
{ name: 'nonce', type: 'uint256' }, | ||
], | ||
}; | ||
|
||
const nonce = await ioIDRegistry.nonces(device.address); | ||
|
||
// @ts-ignore | ||
const signature = await device.signTypedData(domain, types, { owner: verifyingProxy.target, nonce: nonce }); | ||
const r = signature.substring(0, 66); | ||
const s = '0x' + signature.substring(66, 130); | ||
const v = '0x' + signature.substring(130); | ||
|
||
const projectId = await verifyingProxy.projectId(); | ||
const deviceNFT = await verifyingProxy.deviceNFT(); | ||
|
||
const verifyMessage = solidityPacked(['uint256', 'address', 'address'], [chainId, owner.address, device.address]); | ||
const verifySignature = await verifier.signMessage(getBytes(verifyMessage)); | ||
|
||
const tx = await verifyingProxy.register( | ||
verifySignature, | ||
keccak256('0x'), // did hash | ||
'http://resolver.did', // did document uri | ||
owner.address, // owner | ||
device.address, // device | ||
v, | ||
r, | ||
s, | ||
); | ||
|
||
console.log(`divice nft: ${projectId}`); | ||
console.log(`divice nft: ${deviceNFT}`); | ||
console.log(`divice address: ${device.address}`); | ||
console.log(`owner private key: ${owner.privateKey}`); | ||
console.log(`register device txHash: ${tx.hash}`); | ||
} | ||
|
||
main().catch(err => { | ||
console.error(err); | ||
process.exitCode = 1; | ||
}); |
Oops, something went wrong.