Skip to content

Commit

Permalink
fix(mu): fetch wallet address of the process id for relay
Browse files Browse the repository at this point in the history
  • Loading branch information
VinceJuliano committed Feb 7, 2025
1 parent c2b0837 commit 3208305
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
11 changes: 9 additions & 2 deletions servers/mu/src/domain/clients/relay.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@ function httpSigName (address) {
return `http-sig-${hexString}`;
}

export function topUpWith ({ fetch, logger, wallet, address }) {
export function topUpWith ({ fetch, logger, wallet, address, fetchTransactionDetails }) {
const privateKey = createPrivateKey({ key: wallet, format: 'jwk' })
const s = createSigner(privateKey, 'rsa-pss-sha512', address)
const params = ['alg', 'keyid'].sort()

return async ({ logId, relayUrl, amount, recipient }) => {
return async ({ logId, relayUrl, amount, recipientProcessId }) => {
let processInfo = await fetchTransactionDetails([recipientProcessId])
let recipient = processInfo?.data?.transactions?.edges?.length >= 1 ? processInfo.data.transactions.edges[0].node.owner.address : null

if(!recipient) {
return new Error("Invalid recipient for top up")
}

let relayUrlObj = new URL(relayUrl)
const urlString = `${relayUrl}?amount+integer=${amount}&recipient=${recipient}`

Expand Down
21 changes: 19 additions & 2 deletions servers/mu/src/domain/clients/relay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,31 @@ describe('topUpWith function', function () {
logger.tap = () => (args) => {
return args
}
let topUp = topUpWith({ fetch, logger, wallet, address })
const fetchTransactionDetails = async () => {
return {
data: {
transactions: {
edges: [
{
node: {
owner: {
address: "asdf"
}
}
}
]
}
}
}
}
let topUp = topUpWith({ fetch, logger, wallet, address, fetchTransactionDetails })

it('should correctly sign and verify a request', async function () {
const params = {
logId: 'test-log',
relayUrl: 'https://relay1.example/path/topup',
amount: 100,
recipient: 'recipient-address'
recipient: 'recipient-process-id'
}

const result = await topUp(params)
Expand Down
3 changes: 2 additions & 1 deletion servers/mu/src/domain/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@ export const createResultApis = async (ctx) => {
isWallet: gatewayClient.isWalletWith({ fetch, histogram, ARWEAVE_URL, logger: processMsgLogger, setById, getById }),
writeDataItemArweave: uploaderClient.uploadDataItemWith({ UPLOADER_URL, logger: processMsgLogger, fetch, histogram }),
RELAY_MAP,
topUp: RelayClient.topUpWith({ fetch, logger: processMsgLogger, wallet: MU_WALLET, address: walletAddress })
topUp: RelayClient.topUpWith({ fetch, logger: processMsgLogger, wallet: MU_WALLET, address: walletAddress }),
fetchTransactions: gatewayClient.fetchTransactionDetailsWith({ fetch, GRAPHQL_URL }),
})

const processSpawnLogger = logger.child('processSpawn')
Expand Down

0 comments on commit 3208305

Please sign in to comment.