Skip to content

Commit

Permalink
feat(global): adds string as return type of postSignature
Browse files Browse the repository at this point in the history
  • Loading branch information
allemanfredi committed Feb 13, 2025
1 parent 51e4b0d commit e2fe646
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
10 changes: 8 additions & 2 deletions src/AssetsManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { JsonRpcProvider, Contract } from 'ethers'
import { Wallet } from './WalletManager'
import erc20Abi from './kms/keyring/abi/erc20'
import { string } from './kms/types'

export type NetworkConfigs = {
[key: string]: {
Expand Down Expand Up @@ -33,7 +34,12 @@ export class AssetsManager {
}
}

async transferToken(wallet: Wallet, amount: number, destinationAddressAsEIP3770: string, tokenAddress: string) {
async transferToken(
wallet: Wallet,
amount: number,
destinationAddressAsEIP3770: string,
tokenAddress: string
): Promise<string> {
const [chain, recipient] = destinationAddressAsEIP3770.split(':')

const networkConfig = this.networkConfigs[chain]
Expand All @@ -46,6 +52,6 @@ export class AssetsManager {

const data = await wallet.kms.prepareTransfer(tokenAddress, onchainAmount.toString(), recipient, provider)
const signature = await wallet.sign(data)
await wallet.kms.postSignature(signature, data, provider)
return await wallet.kms.postSignature(signature, data, provider)
}
}
9 changes: 5 additions & 4 deletions src/kms/keyring/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AbiCoder, Contract, getBytes, hexlify, JsonRpcProvider, sha256, Wallet
import { buildSafeTransaction, buildSignatureBytes, safeApproveHash } from './safe'
import { addHexPrefix, stripHexPrefix } from '../../utils'
import { Operation } from './Operation'
import { IKms, Signature } from '../types'
import { IKms, Signature, string } from '../types'
import { Kms } from '../Kms'
import keyringGatewayAbi from './abi/keyring-gateway'
import erc20Abi from './abi/erc20'
Expand Down Expand Up @@ -151,17 +151,18 @@ export class KeyringKms extends Kms implements IKms<KeyringSignOptions> {
return Buffer.from(getBytes(addHexPrefix(result.signature)))
}

async postSignature(signature: Signature, data: Buffer, provider: JsonRpcProvider) {
async postSignature(signature: Signature, data: Buffer, provider: JsonRpcProvider): Promise<string> {
// NOTE: there will be an api call to propagate the signed

const gatewayAddress = KEYRING_GATEWAY_ADDRESSES[Number(provider._network.chainId)]
if (!gatewayAddress) throw new Error('invalid network')

// NOTE: provisional wallet with funds in ordet to be able to relay the tx
const wallet = new Wallet(process.env.RELAY_PK as string, provider)
const wallet = new Wallet(this._instanceKeyWallet.privateKey, provider)

const gateway = new Contract(gatewayAddress, keyringGatewayAbi, wallet)
const serializedOperation = data
await gateway.executeOperation(serializedOperation, signature)
const tx = await gateway.executeOperation(serializedOperation, signature)
return tx.hash
}
}
5 changes: 3 additions & 2 deletions src/kms/lit/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { JsonRpcProvider } from 'ethers'
import { IKms, Signature } from '../types'
import { IKms, Signature, string } from '../types'

export interface LitKmsConfigs {}

Expand Down Expand Up @@ -32,8 +32,9 @@ export class LitKms implements IKms<LitSignOptions> {
return Buffer.from([])
}

async postSignature(signature: Signature, data: Buffer, provider: JsonRpcProvider) {
async postSignature(signature: Signature, data: Buffer, provider: JsonRpcProvider): Promise<string> {
// TODO
console.log(signature, data, provider)
return ''
}
}
2 changes: 1 addition & 1 deletion src/kms/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export interface IKms<O> {
initialize(): Promise<void>
sign(data: Buffer, options: O): Promise<Buffer>
prepareTransfer(tokenAddress: string, amount: string, receiver: string, provider: JsonRpcProvider): Promise<Buffer>
postSignature(signature: Signature, data: Buffer, provider: JsonRpcProvider): Promise<void>
postSignature(signature: Signature, data: Buffer, provider: JsonRpcProvider): Promise<string>
}

0 comments on commit e2fe646

Please sign in to comment.