Skip to content

Commit

Permalink
Merge pull request #600 from xmtp/ar/consent-proofs
Browse files Browse the repository at this point in the history
fix: updated consent proof text
  • Loading branch information
alexrisch authored May 6, 2024
2 parents 56d3cee + 8117726 commit 76f8cad
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 31 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
},
"dependencies": {
"@noble/secp256k1": "1.7.1",
"@xmtp/consent-proof-signature": "^0.1.2",
"@xmtp/proto": "3.54.0",
"@xmtp/user-preferences-bindings-wasm": "^0.3.6",
"async-mutex": "^0.5.0",
Expand Down
8 changes: 3 additions & 5 deletions src/Contacts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createConsentMessage } from '@xmtp/consent-proof-signature'
import { privatePreferences, type invitation } from '@xmtp/proto'
import { hashMessage, hexToBytes } from 'viem'
import { ecdsaSignerKey, WalletSigner } from '@/crypto/Signature'
import { ecdsaSignerKey } from '@/crypto/Signature'
import { splitSignature } from '@/crypto/utils'
import type { EnvelopeWithMessage } from '@/utils/async'
import { fromNanoString } from '@/utils/date'
Expand Down Expand Up @@ -275,10 +276,7 @@ export class Contacts {
return false
}
const signatureData = splitSignature(signature as `0x${string}`)
const message = WalletSigner.consentProofRequestText(
peerAddress,
timestampMs
)
const message = createConsentMessage(peerAddress, timestampMs)
const digest = hexToBytes(hashMessage(message))
// Recover public key
const publicKey = ecdsaSignerKey(digest, signatureData)
Expand Down
14 changes: 0 additions & 14 deletions src/crypto/Signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,6 @@ export class WalletSigner implements KeySigner {
)
}

static consentProofRequestText(
peerAddress: string,
timestamp: number
): string {
return (
'XMTP : Grant inbox consent to sender\n' +
'\n' +
`Current Time: ${timestamp}\n` +
`From Address: ${peerAddress}\n` +
'\n' +
'For more info: https://xmtp.org/signatures/'
)
}

static signerKey(
key: SignedPublicKey,
signature: ECDSACompactWithRecovery
Expand Down
16 changes: 4 additions & 12 deletions test/Contacts.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createConsentMessage } from '@xmtp/consent-proof-signature'
import { invitation } from '@xmtp/proto'
import Client from '@/Client'
import { Contacts } from '@/Contacts'
Expand Down Expand Up @@ -202,10 +203,7 @@ describe('Contacts', () => {
env: 'local',
})
const timestamp = Date.now()
const consentMessage = WalletSigner.consentProofRequestText(
bo.address,
timestamp
)
const consentMessage = createConsentMessage(bo.address, timestamp)
const signedMessage = await keySigner.wallet.signMessage(consentMessage)
const consentProofPayload = invitation.ConsentProofPayload.fromPartial({
signature: signedMessage,
Expand Down Expand Up @@ -239,10 +237,7 @@ describe('Contacts', () => {
env: 'local',
})
const timestamp = Date.now()
const consentMessage = WalletSigner.consentProofRequestText(
bo.address,
timestamp
)
const consentMessage = createConsentMessage(bo.address, timestamp)
const signedMessage = await keySigner.wallet.signMessage(consentMessage)
const consentProofPayload = invitation.ConsentProofPayload.fromPartial({
signature: signedMessage,
Expand Down Expand Up @@ -272,10 +267,7 @@ describe('Contacts', () => {
env: 'local',
})
const timestamp = Date.now()
const consentMessage = WalletSigner.consentProofRequestText(
bo.address,
timestamp + 1
)
const consentMessage = createConsentMessage(bo.address, timestamp + 1)
const signedMessage = await keySigner.wallet.signMessage(consentMessage)
const consentProofPayload = invitation.ConsentProofPayload.fromPartial({
signature: signedMessage,
Expand Down
23 changes: 23 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3154,6 +3154,16 @@ __metadata:
languageName: node
linkType: hard

"@xmtp/consent-proof-signature@npm:^0.1.2":
version: 0.1.2
resolution: "@xmtp/consent-proof-signature@npm:0.1.2"
dependencies:
"@xmtp/proto": "npm:3.56.0"