forked from Abstract-Foundation/agw-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main'
- Loading branch information
Showing
34 changed files
with
1,462 additions
and
272 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ | |
"trailingComma": "all", | ||
"singleQuote": true, | ||
"printWidth": 80 | ||
} | ||
} |
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,8 @@ | ||
{ | ||
"editor.formatOnPaste": true, | ||
"editor.formatOnSave": true, | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": "always" | ||
} | ||
} |
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
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,40 @@ | ||
import { | ||
type Account, | ||
bytesToString, | ||
type Client, | ||
fromHex, | ||
hashMessage, | ||
type Hex, | ||
type SignMessageParameters, | ||
type Transport, | ||
type WalletClient, | ||
} from 'viem'; | ||
import type { ChainEIP712 } from 'viem/chains'; | ||
|
||
import { getAgwTypedSignature } from '../getAgwTypedSignature.js'; | ||
import { sendPrivySignMessage } from './sendPrivyTransaction.js'; | ||
|
||
export async function signMessage( | ||
client: Client<Transport, ChainEIP712, Account>, | ||
signerClient: WalletClient<Transport, ChainEIP712, Account>, | ||
parameters: Omit<SignMessageParameters, 'account'>, | ||
isPrivyCrossApp = false, | ||
): Promise<Hex> { | ||
if (isPrivyCrossApp) { | ||
// We handle {message: {raw}} here because the message is expected to be a string | ||
if (typeof parameters.message === 'object') { | ||
if (parameters.message.raw instanceof Uint8Array) { | ||
parameters.message = bytesToString(parameters.message.raw); | ||
} else { | ||
parameters.message = fromHex(parameters.message.raw, 'string'); | ||
} | ||
} | ||
return await sendPrivySignMessage(client, parameters); | ||
} | ||
|
||
return await getAgwTypedSignature({ | ||
client, | ||
signer: signerClient, | ||
messageHash: hashMessage(parameters.message), | ||
}); | ||
} |
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,50 @@ | ||
import { | ||
type Account, | ||
type Client, | ||
encodeAbiParameters, | ||
hashTypedData, | ||
type Hex, | ||
parseAbiParameters, | ||
type Transport, | ||
type WalletClient, | ||
} from 'viem'; | ||
import type { SignTypedDataParameters } from 'viem/accounts'; | ||
import { signTypedData as viemSignTypedData } from 'viem/actions'; | ||
import type { ChainEIP712 } from 'viem/chains'; | ||
|
||
import { VALIDATOR_ADDRESS } from '../constants.js'; | ||
import { isEIP712Transaction } from '../eip712.js'; | ||
import { getAgwTypedSignature } from '../getAgwTypedSignature.js'; | ||
import { sendPrivySignTypedData } from './sendPrivyTransaction.js'; | ||
|
||
export async function signTypedData( | ||
client: Client<Transport, ChainEIP712, Account>, | ||
signerClient: WalletClient<Transport, ChainEIP712, Account>, | ||
parameters: Omit<SignTypedDataParameters, 'account' | 'privateKey'>, | ||
isPrivyCrossApp = false, | ||
): Promise<Hex> { | ||
if (isPrivyCrossApp) return await sendPrivySignTypedData(client, parameters); | ||
|
||
// if the typed data is already a zkSync EIP712 transaction, don't try to transform it | ||
// to an AGW typed signature, just pass it through to the signer. | ||
if ( | ||
parameters.message && | ||
parameters.domain?.name === 'zkSync' && | ||
isEIP712Transaction(parameters.message) | ||
) { | ||
const rawSignature = await viemSignTypedData(signerClient, parameters); | ||
// Match the expect signature format of the AGW smart account so the result can be | ||
// directly used in eth_sendRawTransaction as the customSignature field | ||
const signature = encodeAbiParameters( | ||
parseAbiParameters(['bytes', 'address', 'bytes[]']), | ||
[rawSignature, VALIDATOR_ADDRESS, []], | ||
); | ||
return signature; | ||
} | ||
|
||
return await getAgwTypedSignature({ | ||
client, | ||
signer: signerClient, | ||
messageHash: hashTypedData(parameters), | ||
}); | ||
} |
Oops, something went wrong.