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

Removed ethers from test #423

Merged
merged 1 commit into from
Jun 18, 2024
Merged
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
33 changes: 25 additions & 8 deletions example/src/tests.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { sha256 } from '@noble/hashes/sha256'

Check warning on line 1 in example/src/tests.ts

View workflow job for this annotation

GitHub Actions / lint

'sha256' is defined but never used
import { FramesClient } from '@xmtp/frames-client'
import { content, invitation, signature as signatureProto } from '@xmtp/proto'

Check warning on line 3 in example/src/tests.ts

View workflow job for this annotation

GitHub Actions / lint

'signatureProto' is defined but never used
import { createHmac } from 'crypto'
import { ethers } from 'ethers'
import ReactNativeBlobUtil from 'react-native-blob-util'
import Config from 'react-native-config'
import { TextEncoder, TextDecoder } from 'text-encoding'
import { createWalletClient, custom, PrivateKeyAccount, toHex } from 'viem'

Check warning on line 8 in example/src/tests.ts

View workflow job for this annotation

GitHub Actions / lint

'createWalletClient' is defined but never used

Check warning on line 8 in example/src/tests.ts

View workflow job for this annotation

GitHub Actions / lint

'custom' is defined but never used

Check warning on line 8 in example/src/tests.ts

View workflow job for this annotation

GitHub Actions / lint

'toHex' is defined but never used
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'
import { DecodedMessage } from 'xmtp-react-native-sdk/lib/DecodedMessage'

Expand Down Expand Up @@ -1678,13 +1677,31 @@
return true
})

class ViemSigner {
account: PrivateKeyAccount

constructor(account: PrivateKeyAccount) {
this.account = account
}

async getAddress() {
return this.account.address
}

async signMessage(message: string) {
return this.account.signMessage({ message })
}
}

test('can send and receive consent proofs', async () => {
const alixWallet = await ethers.Wallet.createRandom()
const boWallet = await ethers.Wallet.createRandom()
const bo = await Client.create(boWallet, { env: 'local' })
await delayToPropogate()
const alix = await Client.create(alixWallet, { env: 'local' })
await delayToPropogate()
const alixPrivateKey = generatePrivateKey()
const alixAccount = privateKeyToAccount(alixPrivateKey)
const boPrivateKey = generatePrivateKey()
const boAccount = privateKeyToAccount(boPrivateKey)
const alixSigner = new ViemSigner(alixAccount)
const boSigner = new ViemSigner(boAccount)
const alix = await Client.create(alixSigner, { env: 'local' })
const bo = await Client.create(boSigner, { env: 'local' })

const timestamp = Date.now()
const consentMessage =
Expand All @@ -1694,7 +1711,7 @@
`From Address: ${bo.address}\n` +
'\n' +
'For more info: https://xmtp.org/signatures/'
const sig = await alixWallet.signMessage(consentMessage)
const sig = await alixSigner.signMessage(consentMessage)
const consentProof = invitation.ConsentProofPayload.fromPartial({
payloadVersion:
invitation.ConsentProofPayloadVersion.CONSENT_PROOF_PAYLOAD_VERSION_1,
Expand Down
Loading