-
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 pull request #4 from rhinestonewtf/feat/v0.1.0
Feat/v0.1.0
- Loading branch information
Showing
10 changed files
with
91 additions
and
109 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,49 +1,32 @@ | ||
import { | ||
getOwnableValidatorSignature, | ||
OWNABLE_VALIDATOR_ADDRESS, | ||
} from '@rhinestone/module-sdk' | ||
import { hashTypedData, Hex } from 'viem' | ||
import { privateKeyToAccount } from 'viem/accounts' | ||
import { SignedIntent, SignedOrderBundle } from '../types' | ||
import { smartContractTypes } from '../constants' | ||
import { getOrderDomain } from '../utils' | ||
|
||
|
||
export async function signOrderBundleWithOwnableValidator( | ||
export async function getOrderBundleHash( | ||
orderBundle: SignedIntent, | ||
privateKey: Hex, | ||
): Promise<SignedOrderBundle> { | ||
const hash = hashTypedData({ | ||
): Promise<Hex> { | ||
return hashTypedData({ | ||
domain: getOrderDomain(), | ||
types: smartContractTypes, | ||
primaryType: 'SignedIntent', | ||
message: orderBundle, | ||
}) | ||
} | ||
|
||
const account = privateKeyToAccount(privateKey) | ||
|
||
// Add the prefix for ownable validator sig | ||
const signature = await account.signMessage({ | ||
message: { | ||
raw: hash, | ||
}, | ||
}) | ||
|
||
const ownableValidatorSig = getOwnableValidatorSignature({ | ||
signatures: [signature], | ||
}) | ||
|
||
const encodedSignature = (OWNABLE_VALIDATOR_ADDRESS + | ||
ownableValidatorSig.slice(2)) as Hex | ||
|
||
export async function getSignedOrderBundle( | ||
orderBundle: SignedIntent, | ||
orderBundleSignature: Hex, | ||
): Promise<SignedOrderBundle> { | ||
return { | ||
settlement: orderBundle.settlement, | ||
acrossTransfers: orderBundle.acrossTransfers.map((transfer) => ({ | ||
...transfer, | ||
userSignature: encodedSignature, | ||
userSignature: orderBundleSignature, | ||
})), | ||
targetChainExecutions: orderBundle.targetChainExecutions, | ||
targetExecutionSignature: encodedSignature, | ||
targetExecutionSignature: orderBundleSignature, | ||
userOp: orderBundle.userOp, | ||
} | ||
} |
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,60 @@ | ||
import { Address, Hex } from 'viem' | ||
import { | ||
getOrderBundleHash, | ||
getSignedOrderBundle, | ||
} from '../../src/common/signer' | ||
import { MetaIntent, SignedIntent, SignedOrderBundle } from '../../src/types' | ||
import { privateKeyToAccount } from 'viem/accounts' | ||
import { Orchestrator } from '../../src/orchestrator' | ||
|
||
const OWNABLE_VALIDATOR_ADDRESS: Address = | ||
'0x2483da3a338895199e5e538530213157e931bf06' | ||
|
||
// NOTE: This only works for Safe7579 | ||
export async function signOrderBundleWithOwnableValidator( | ||
orderBundle: SignedIntent, | ||
privateKey: Hex, | ||
): Promise<SignedOrderBundle> { | ||
const digest = await getOrderBundleHash(orderBundle) | ||
|
||
const account = privateKeyToAccount(privateKey) | ||
|
||
// Add the prefix for ownable validator sig | ||
const signature = await account.signMessage({ | ||
message: { | ||
raw: digest, | ||
}, | ||
}) | ||
|
||
const encodedSignature = (OWNABLE_VALIDATOR_ADDRESS + | ||
signature.slice(2)) as Hex | ||
|
||
return getSignedOrderBundle(orderBundle, encodedSignature) | ||
} | ||
|
||
export async function postMetaIntentWithOwnableValidator( | ||
metaIntent: MetaIntent, | ||
userId: string, | ||
privateKey: Hex, | ||
orchestrator: Orchestrator, | ||
): Promise<string> { | ||
try { | ||
const { orderBundle, injectedExecutions } = await orchestrator.getOrderPath( | ||
metaIntent, | ||
userId, | ||
) | ||
|
||
// TODO: Add injected executions to orderBundleExecution | ||
const signedOrderBundle = await signOrderBundleWithOwnableValidator( | ||
orderBundle, | ||
privateKey, | ||
) | ||
|
||
return orchestrator.postSignedOrderBundle(signedOrderBundle, userId) | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
console.log(error) | ||
} | ||
} | ||
throw new Error('Failed to post order bundle') | ||
} |