Skip to content
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

Create with a incorrect encryption key hangs instead of erroring. #605

Merged
merged 3 commits into from
Feb 19, 2025
Merged
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
5 changes: 5 additions & 0 deletions .changeset/six-apricots-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@xmtp/react-native-sdk": patch
---

Create errors instead of promise hanging.
57 changes: 57 additions & 0 deletions example/src/tests/clientTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,3 +529,60 @@ test('can add and remove accounts', async () => {

return true
})

test('errors if dbEncryptionKey is lost', async () => {
const keyBytes = new Uint8Array([
233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64,
166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145,
])
const badKeyBytes = new Uint8Array([
0, 0, 0, 0, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, 166, 83,
208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 0, 0, 0, 0,
])
const alixWallet = Wallet.createRandom()

const alix = await Client.create(adaptEthersWalletToSigner(alixWallet), {
env: 'local',
appVersion: 'Testing/0.0.0',
dbEncryptionKey: keyBytes,
})

let errorThrown = false

try {
await Client.build(alix.address, {
env: 'local',
appVersion: 'Testing/0.0.0',
dbEncryptionKey: badKeyBytes,
})
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (error) {
errorThrown = true
}

if (!errorThrown) {
throw new Error(
'Expected build to throw an error with a bad encryption key but it did not'
)
}

errorThrown = false
try {
await Client.create(adaptEthersWalletToSigner(alixWallet), {
env: 'local',
appVersion: 'Testing/0.0.0',
dbEncryptionKey: badKeyBytes,
})
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (error) {
errorThrown = true
}

if (!errorThrown) {
throw new Error(
'Expected create to throw an error with a bad encryption key but it did not'
)
}

return true
})
1 change: 1 addition & 0 deletions src/lib/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export class Client<
})().catch((error) => {
this.removeAllSubscriptions(authInboxSubscription)
console.error('ERROR in create: ', error.message)
reject(error)
})
})
}
Expand Down
Loading