1
- import { ethers } from 'ethers'
1
+ import { ethers , id } from 'ethers'
2
2
import { randomHexBytes } from '../lib/bytes'
3
3
4
- // Generate allocation proof with the indexer's address and the allocation id, signed by the allocation private key
5
- export async function generateAllocationProof ( indexerAddress : string , allocationPrivateKey : string ) {
4
+ // For legacy allocations in the staking contract
5
+ export async function encodeLegacyAllocationProof ( indexerAddress : string , allocationPrivateKey : string ) {
6
6
const wallet = new ethers . Wallet ( allocationPrivateKey )
7
7
const messageHash = ethers . solidityPackedKeccak256 (
8
8
[ 'address' , 'address' ] ,
@@ -12,6 +12,37 @@ export async function generateAllocationProof(indexerAddress: string, allocation
12
12
return wallet . signMessage ( messageHashBytes )
13
13
}
14
14
15
+ export const EIP712_ALLOCATION_PROOF_TYPEHASH = id ( 'AllocationIdProof(address indexer,address allocationId)' )
16
+
17
+ export const EIP712_ALLOCATION_ID_PROOF_TYPES = {
18
+ AllocationIdProof : [
19
+ { name : 'indexer' , type : 'address' } ,
20
+ { name : 'allocationId' , type : 'address' } ,
21
+ ] ,
22
+ }
23
+
24
+ // For new allocations in the subgraph service
25
+ export async function encodeAllocationProof (
26
+ indexerAddress : string ,
27
+ allocationPrivateKey : string ,
28
+ subgraphServiceAddress : string ,
29
+ chainId : number ,
30
+ ) {
31
+ const wallet = new ethers . Wallet ( allocationPrivateKey )
32
+
33
+ const domain = {
34
+ name : 'SubgraphService' ,
35
+ version : '1.0' ,
36
+ chainId : chainId ,
37
+ verifyingContract : subgraphServiceAddress ,
38
+ }
39
+
40
+ return wallet . signTypedData ( domain , EIP712_ALLOCATION_ID_PROOF_TYPES , {
41
+ indexer : indexerAddress ,
42
+ allocationId : wallet . address ,
43
+ } )
44
+ }
45
+
15
46
export function randomAllocationMetadata ( ) {
16
47
return randomHexBytes ( 32 )
17
48
}
0 commit comments