Skip to content
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',
)
})
})