-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add remote sign for attestation #59
Draft
shrimalmadhur
wants to merge
3
commits into
master
Choose a base branch
from
madhur/remote-signer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI: there were a LOT of changes to index.ts. It might be easier to start with a fresh PR? |
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,115 @@ | ||
import { Signer, providers, utils } from 'ethers'; | ||
|
||
export class RemoteSigner extends Signer { | ||
private readonly address: string; | ||
readonly provider: providers.Provider; | ||
private readonly remoteSigningEndpoint: string; | ||
|
||
constructor(address: string, provider: providers.Provider, remoteSigningEndpoint: string) { | ||
super(); | ||
this.address = address; | ||
this.provider = provider; | ||
this.remoteSigningEndpoint = remoteSigningEndpoint; | ||
} | ||
|
||
async getAddress(): Promise<string> { | ||
return this.address; | ||
} | ||
|
||
async signMessage(message: string | utils.Bytes): Promise<string> { | ||
if (typeof(message) === "string") { | ||
return this.signMessageHash(message); | ||
} else { | ||
const messageHash = utils.solidityKeccak256(["string"], [message]) | ||
return this.signMessageHash(messageHash); | ||
} | ||
} | ||
|
||
async signTransaction(transaction: utils.Deferrable<providers.TransactionRequest>): Promise<string> { | ||
// Implement the logic to send the transaction to your remote signing service | ||
// and return the signed transaction | ||
const tx = { | ||
from: transaction.from, | ||
to: transaction.to, | ||
value: transaction.value, | ||
gas: transaction.gasLimit?.toString(), | ||
maxPriorityFeePerGas: transaction.maxPriorityFeePerGas?.toString(), | ||
maxFeePerGas: transaction.maxFeePerGas?.toString(), | ||
nonce: transaction.nonce, | ||
data: transaction.data, | ||
} | ||
const signedTransaction = await callJsonRpcEndpoint( | ||
this.remoteSigningEndpoint, | ||
"eth_signTransaction", | ||
[tx] | ||
); | ||
|
||
return signedTransaction; | ||
} | ||
|
||
connect(provider: providers.Provider): Signer { | ||
return new RemoteSigner(this.address, provider, this.remoteSigningEndpoint); | ||
} | ||
|
||
private async signMessageHash(messageHash: string): Promise<string> { | ||
// Implement the logic to send the message hash to your remote signing service | ||
// and return the signature | ||
const signature = await callJsonRpcEndpoint( | ||
this.remoteSigningEndpoint, | ||
"eth_sign", | ||
[this.address, messageHash] | ||
); | ||
|
||
return signature; | ||
} | ||
} | ||
|
||
interface JsonRpcRequest { | ||
jsonrpc: string; | ||
method: string; | ||
params: any[]; | ||
id: number; | ||
} | ||
|
||
interface JsonRpcResponse { | ||
jsonrpc: string; | ||
result?: any; | ||
error?: { | ||
code: number; | ||
message: string; | ||
}; | ||
id: number; | ||
} | ||
|
||
async function callJsonRpcEndpoint( | ||
url: string, | ||
method: string, | ||
params: any[] = [] | ||
): Promise<any> { | ||
const request: JsonRpcRequest = { | ||
jsonrpc: "2.0", | ||
method, | ||
params, | ||
id: 1, // You might want to generate a unique id for each request | ||
}; | ||
|
||
const response = await fetch(url, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify(request), | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error(`HTTP error! status: ${response.status}`); | ||
} | ||
|
||
const jsonResponse: JsonRpcResponse = await response.json(); | ||
|
||
if (jsonResponse.error) { | ||
throw new Error(`JSON-RPC error: ${jsonResponse.error.message}`); | ||
} | ||
|
||
return jsonResponse.result; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind moving these changes to: https://github.com/Layr-Labs/hello-world-avs/blob/master/.env.example ?
We're trying to make the deployments more streamlined for local and holesky, so we removed .env.local