Skip to content

Commit

Permalink
Merge branch 'main' into update-issued-assets
Browse files Browse the repository at this point in the history
  • Loading branch information
fhildeb committed Apr 16, 2024
2 parents c85da02 + 4a8b5c5 commit fcecdca
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 67 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions key-manager/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PRIVATE_KEY=0x...
UP_ADDR=0x...
2 changes: 1 addition & 1 deletion key-manager/execute-relay-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const universalProfileAddress = '0x...';
const recipientAddress = '0x...';

// Setup the Universal Profile controller account
const controllerPrivateKey = '0x...';
const controllerPrivateKey = process.env.PRIVATE_KEY || '';
const controllerAccount = new ethers.Wallet(controllerPrivateKey).connect(
provider,
);
Expand Down
90 changes: 90 additions & 0 deletions key-manager/grant-permissions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { ethers } from 'ethers';
import { ERC725 } from '@erc725/erc725.js';
import LSP6Schema from '@erc725/erc725.js/schemas/LSP6KeyManager.json';
import UniversalProfileArtifact from '@lukso/lsp-smart-contracts/artifacts/UniversalProfile.json';

const myUniversalProfileAddress = process.env.UP_ADDR || '';

const RPC_ENDPOINT = 'https://4201.rpc.thirdweb.com';
const provider = new ethers.JsonRpcProvider(RPC_ENDPOINT);

// Initialize erc725.js with the permission data keys from LSP6 Key Manager
const erc725 = new ERC725(
LSP6Schema,
myUniversalProfileAddress,
RPC_ENDPOINT,
{},
);

// Create the permissions for the beneficiary address
const beneficiaryPermissions = erc725.encodePermissions({
SETDATA: true,
});

// EOA address of the new controller
const myBeneficiaryAddress = '0xcafecafecafecafecafecafecafecafecafecafe';

// Retrieve the current controllers of the Universal Profile
const addressPermissionsArray = await erc725.getData('AddressPermissions[]');
let currentControllerAddresses = null;
let currentControllerLength = 0;

if (Array.isArray(addressPermissionsArray.value)) {
currentControllerAddresses = addressPermissionsArray.value;
currentControllerLength = currentControllerAddresses.length;
}

// Encode the key-value pairs of the controller permission
const permissionData = erc725.encodeData([
// the permission of the beneficiary address
{
keyName: 'AddressPermissions:Permissions:<address>',
dynamicKeyParts: myBeneficiaryAddress,
value: beneficiaryPermissions,
},
// The new incremented list of permissioned controllers addresses
{
keyName: 'AddressPermissions[]',
value: [myBeneficiaryAddress],
startingIndex: currentControllerLength,
totalArrayLength: currentControllerLength + 1,
},
]);

// Private key to sign the transaction
const PRIVATE_KEY = process.env.PRIVATE_KEY || '';

// Existing UP controller
const controller = new ethers.Wallet(PRIVATE_KEY).connect(provider);

// instantiate the Universal Profile
const myUniversalProfile = new ethers.Contract(
myUniversalProfileAddress,
UniversalProfileArtifact.abi,
);

try {
// Execute the transaction
await myUniversalProfile
.connect(controller)
// @ts-expect-error Ethers BaseContract does not pick dynamic types from ABIs
.setData(permissionData.keys, permissionData.values);

const updatedPermissions = await erc725.getData({
keyName: 'AddressPermissions:Permissions:<address>',
dynamicKeyParts: myBeneficiaryAddress,
});

if (updatedPermissions && typeof updatedPermissions.value === 'string') {
console.log(
`The beneficiary address ${myBeneficiaryAddress} has the following permissions:`,
erc725.decodePermissions(updatedPermissions.value),
);
} else {
console.error(
`No permissions for beneficiary address ${myBeneficiaryAddress} found`,
);
}
} catch (error) {
console.error('Could not execute the controller update:', error);
}
64 changes: 0 additions & 64 deletions key-manager/set-permissions.ts

This file was deleted.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"lint:fix": "eslint . --fix"
},
"devDependencies": {
"@erc725/erc725.js": "^0.24.1",
"@lukso/eip191-signer.js": "^0.2.2",
"@erc725/erc725.js": "^0.24.2",
"@lukso/lsp-smart-contracts": "^0.14.0",
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^6.20.0",
Expand Down

0 comments on commit fcecdca

Please sign in to comment.