Skip to content

Require different wallets for receivable uploading and arweave uploading #205

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/huma-sdk/src/services/v2/HumaReceivableFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ export class HumaReceivableFactory {
throw new Error('Input must be a JSON object.')
}

// Check that the private key is different from the signer passed in the context
const signerAddress = await this.#humaContext.signer.getAddress()
const arweavePaymentAddress = ethers.utils.computeAddress(
arweavePaymentPrivateKey,
)
if (signerAddress === arweavePaymentAddress) {
throw new Error(
'The ARWeave payment private key must be different from the signer address',
)
}

await this.throwIfReferenceIdExists(referenceId)

const metadataURI = await this.uploadMetadata(
Expand Down
41 changes: 41 additions & 0 deletions packages/huma-sdk/tests/services/v2/HumaReceivableFactory.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { ChainEnum, POOL_NAME, POOL_TYPE } from '@huma-finance/shared'
import { BigNumber, ethers } from 'ethers'
import { HumaReceivableFactory, HumaContext } from '../../../src/services'

describe('HumaReceivableFactory', () => {
beforeEach(() => {
jest.resetAllMocks()
})

it('should throw if the signer and arweave uploader wallet are the same', async () => {
const mnemonic =
'test test test test test test test test test test test junk'
const mnemonicWallet = ethers.Wallet.fromMnemonic(mnemonic)
const provider = new ethers.providers.JsonRpcProvider(
`http://localhost:8545`,
)

const humaContext = new HumaContext({
signer: mnemonicWallet,
provider,
chainId: ChainEnum.Localhost,
poolName: POOL_NAME.ArfCreditPoolV2,
poolType: POOL_TYPE.ReceivableBackedCreditLine,
})
const receivableFactory = new HumaReceivableFactory({
humaContext,
})

await expect(
receivableFactory.createReceivableWithMetadata(
mnemonicWallet.privateKey, // privateKey
840, // currencyCode for USD
BigNumber.from(1000), // receivableAmount
1684517656, // maturityDate
JSON.parse('{"test": "test"}'),
),
).rejects.toThrow(
'The ARWeave payment private key must be different from the signer address',
)
})
})