@graphprotocol/toolshed
Version:
A collection of tools and utilities for the Graph Protocol Typescript components
40 lines • 1.86 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EIP712_ALLOCATION_ID_PROOF_TYPES = exports.EIP712_ALLOCATION_PROOF_TYPEHASH = void 0;
exports.generateLegacyAllocationProof = generateLegacyAllocationProof;
exports.generateAllocationProof = generateAllocationProof;
exports.randomAllocationMetadata = randomAllocationMetadata;
const ethers_1 = require("ethers");
const bytes_1 = require("../lib/bytes");
// For legacy allocations in the staking contract
async function generateLegacyAllocationProof(indexerAddress, allocationPrivateKey) {
const wallet = new ethers_1.ethers.Wallet(allocationPrivateKey);
const messageHash = ethers_1.ethers.solidityPackedKeccak256(['address', 'address'], [indexerAddress, wallet.address]);
const messageHashBytes = ethers_1.ethers.getBytes(messageHash);
return wallet.signMessage(messageHashBytes);
}
exports.EIP712_ALLOCATION_PROOF_TYPEHASH = (0, ethers_1.id)('AllocationIdProof(address indexer,address allocationId)');
exports.EIP712_ALLOCATION_ID_PROOF_TYPES = {
AllocationIdProof: [
{ name: 'indexer', type: 'address' },
{ name: 'allocationId', type: 'address' },
],
};
// For new allocations in the subgraph service
async function generateAllocationProof(indexerAddress, allocationPrivateKey, subgraphServiceAddress, chainId) {
const wallet = new ethers_1.ethers.Wallet(allocationPrivateKey);
const domain = {
name: 'SubgraphService',
version: '1.0',
chainId: chainId,
verifyingContract: subgraphServiceAddress,
};
return wallet.signTypedData(domain, exports.EIP712_ALLOCATION_ID_PROOF_TYPES, {
indexer: indexerAddress,
allocationId: wallet.address,
});
}
function randomAllocationMetadata() {
return (0, bytes_1.randomHexBytes)(32);
}
//# sourceMappingURL=allocation.js.map