Skip to content

Commit

Permalink
feat: Consent Proofs
Browse files Browse the repository at this point in the history
Added handling for creating consent proofs
Added ethers
Added tests
  • Loading branch information
Alex Risch authored and Alex Risch committed May 7, 2024
1 parent e315881 commit df430d5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 37 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ repositories {
dependencies {
implementation project(':expo-modules-core')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
implementation "org.xmtp:android:0.11.1"
implementation "org.xmtp:android:0.11.2"
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.facebook.react:react-native:0.71.3'
implementation "com.daveanthonythomas.moshipack:moshipack:1.0.1"
Expand Down
14 changes: 6 additions & 8 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ PODS:
- GenericJSON (~> 2.0)
- Logging (~> 1.0.0)
- secp256k1.swift (~> 0.1)
- XMTP (0.10.8):
- XMTP (0.10.9):
- Connect-Swift (= 0.12.0)
- GzipSwift
- LibXMTP (= 0.4.4-beta5)
Expand All @@ -454,7 +454,7 @@ PODS:
- ExpoModulesCore
- MessagePacker
- secp256k1.swift
- XMTP (= 0.10.8)
- XMTP (= 0.10.9)
- Yoga (1.14.0)

DEPENDENCIES:
Expand Down Expand Up @@ -522,7 +522,6 @@ DEPENDENCIES:
- "RNCAsyncStorage (from `../node_modules/@react-native-async-storage/async-storage`)"
- RNScreens (from `../node_modules/react-native-screens`)
- RNSVG (from `../node_modules/react-native-svg`)
- XMTP (from `/Users/alexrisch/ios/xmtp-ios`)
- XMTPReactNative (from `../../ios`)
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)

Expand All @@ -544,6 +543,7 @@ SPEC REPOS:
- secp256k1.swift
- SwiftProtobuf
- web3.swift
- XMTP

EXTERNAL SOURCES:
boost:
Expand Down Expand Up @@ -668,8 +668,6 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native-screens"
RNSVG:
:path: "../node_modules/react-native-svg"
XMTP:
:path: "/Users/alexrisch/ios/xmtp-ios"
XMTPReactNative:
:path: "../../ios"
Yoga:
Expand Down Expand Up @@ -753,10 +751,10 @@ SPEC CHECKSUMS:
secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634
SwiftProtobuf: 407a385e97fd206c4fbe880cc84123989167e0d1
web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959
XMTP: 1bee03b6a541f811f8199b254ef3a8ce09b85bdb
XMTPReactNative: 655fdf39d8481ce474bbbfc7d63af0c55cee0e54
XMTP: 5efac5f69327cc6a4ad5b1f1fb9624b9e8355efe
XMTPReactNative: 5c4baec31d5ef83e5e5a35c33c31e70524db620e
Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9

PODFILE CHECKSUM: b1a17a26fef9b207a68bf254156a4e8e034432c8
PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2

COCOAPODS: 1.15.2
47 changes: 21 additions & 26 deletions example/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { sha256 } from '@noble/hashes/sha256'
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 { PrivateKeyAccount, toHex } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { createWalletClient, custom, PrivateKeyAccount, toHex } from 'viem'

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

View workflow job for this annotation

GitHub Actions / lint

'createWalletClient' is defined but never used

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

View workflow job for this annotation

GitHub Actions / lint

'custom' is defined but never used

Check warning on line 9 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'

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

View workflow job for this annotation

GitHub Actions / lint

'generatePrivateKey' is defined but never used
import { DecodedMessage } from 'xmtp-react-native-sdk/lib/DecodedMessage'

import {
Expand Down Expand Up @@ -1678,39 +1679,26 @@ test('can handle complex streaming setup with messages from self', async () => {
})

test('can send and receive consent proofs', async () => {
const bo = await Client.createRandom({ env: 'local' })
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.createRandom({ env: 'local' })
const alix = await Client.create(alixWallet, { env: 'local' })
await delayToPropogate()

const timestamp = Date.now()
const consentMessage =
'XMTP : Grant inbox consent to sender\n' +
'\n' +
`Current Time: ${timestamp}\n` +
`Current Time: ${new Date(timestamp).toUTCString()}\n` +
`From Address: ${bo.address}\n` +
'\n' +
'For more info: https://xmtp.org/signatures/'
const data = sha256(consentMessage)
const signature = await alix.sign(data, {
kind: 'identity',
})
const sig = signatureProto.Signature.decode(signature)
console.log('sig', sig)
if (!sig.ecdsaCompact) {
throw new Error('signature should have ecdsaCompact')
}
const r = toHex(sig.ecdsaCompact?.bytes.slice(0, 32))
const s = toHex(sig.ecdsaCompact?.bytes.slice(32, 64))
const v =
sig.ecdsaCompact?.recovery < 27
? sig.ecdsaCompact?.recovery + 27
: sig.ecdsaCompact?.recovery
const test = r + s.substring(2) + v.toString(16)

const sig = await alixWallet.signMessage(consentMessage)
const consentProof = invitation.ConsentProofPayload.fromPartial({
payloadVersion:
invitation.ConsentProofPayloadVersion.CONSENT_PROOF_PAYLOAD_VERSION_1,
signature: test,
signature: sig,
timestamp,
})

Expand All @@ -1719,9 +1707,16 @@ test('can send and receive consent proofs', async () => {
undefined,
consentProof
)
assert(!!boConvo.consentProof, 'consentProof should exist')
const alixConvo = (await alix.conversations.list())[0]
assert(!!alixConvo.consentProof, 'consentProof should exist')
await delayToPropogate()
assert(!!boConvo?.consentProof, 'bo consentProof should exist')
const convos = await alix.conversations.list()
const alixConvo = convos.find((convo) => convo.topic === boConvo.topic)
await delayToPropogate()
assert(!!alixConvo?.consentProof, ' alix consentProof should not exist')
await delayToPropogate()
await alix.contacts.refreshConsentList()
const isAllowed = await alix.contacts.isAllowed(bo.address)
assert(isAllowed, 'bo should be allowed')
return true
})

Expand Down
2 changes: 1 addition & 1 deletion example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4215,7 +4215,7 @@

"@ethersproject/shims@^5.7.0":
version "5.7.0"
resolved "https://registry.npmjs.org/@ethersproject/shims/-/shims-5.7.0.tgz"
resolved "https://registry.yarnpkg.com/@ethersproject/shims/-/shims-5.7.0.tgz#ee32e543418595774029c5ea6123ea8995e7e154"
integrity sha512-WeDptc6oAprov5CCN2LJ/6/+dC9gTonnkdAtLepm/7P5Z+3PRxS5NpfVWmOMs1yE4Vitl2cU8bOPWC0GvGSbVg==

"@ethersproject/[email protected]", "@ethersproject/signing-key@^5.7.0":
Expand Down
2 changes: 1 addition & 1 deletion ios/XMTPReactNative.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ Pod::Spec.new do |s|
s.source_files = "**/*.{h,m,swift}"
s.dependency 'secp256k1.swift'
s.dependency "MessagePacker"
s.dependency "XMTP", "= 0.10.8"
s.dependency "XMTP", "= 0.10.9"
end

0 comments on commit df430d5

Please sign in to comment.