Skip to content

Commit

Permalink
Merge branch 'main' into cameronvoell/example-wallet-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronvoell committed Dec 22, 2023
2 parents f64420f + e70335a commit c00864f
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 33 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ yarn i @xmtp/react-native-sdk
In the `ios` directory, update your `Podfile` file as follows:

- Set this value: `platform :ios, '16.0'`. This is required by XMTP.
- Add this line: `pod 'secp256k1.swift', :modular_headers => true`. This is required for web3.swift.

```bash
npx pod-install
Expand Down
2 changes: 0 additions & 2 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ target 'xmtpreactnativesdkexample' do
# Flags change depending on the env values.
flags = get_default_flags()

pod 'secp256k1.swift', :modular_headers => true

# See https://github.com/margelo/react-native-quick-crypto/issues/189#issuecomment-1711561970
pod "OpenSSL-Universal", "1.1.2200"

Expand Down
14 changes: 7 additions & 7 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ PODS:
- CoinbaseWalletSDK/Client (1.0.4)
- CoinbaseWalletSDK/CrossPlatform (1.0.4):
- CoinbaseWalletSDK/Client
- CoinbaseWalletSDKExpo (1.0.7):
- CoinbaseWalletSDKExpo (1.0.10):
- CoinbaseWalletSDK/CrossPlatform (= 1.0.4)
- ExpoModulesCore
- Connect-Swift (0.3.0):
Expand All @@ -14,7 +14,7 @@ PODS:
- ExpoModulesCore
- EXConstants (14.2.1):
- ExpoModulesCore
- EXFileSystem (15.6.0):
- EXFileSystem (15.2.2):
- ExpoModulesCore
- EXFont (11.1.1):
- ExpoModulesCore
Expand Down Expand Up @@ -445,6 +445,7 @@ PODS:
- XMTPReactNative (0.1.0):
- ExpoModulesCore
- MessagePacker
- secp256k1.swift
- XMTP (= 0.7.3-alpha0)
- XMTPRust (0.3.7-beta0)
- Yoga (1.14.0)
Expand Down Expand Up @@ -512,7 +513,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`)
- secp256k1.swift
- XMTPReactNative (from `../../ios`)
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)

Expand Down Expand Up @@ -664,12 +664,12 @@ SPEC CHECKSUMS:
BigInt: 74b4d88367b0e819d9f77393549226d36faeb0d8
boost: 57d2868c099736d80fcd648bf211b4431e51a558
CoinbaseWalletSDK: ea1f37512bbc69ebe07416e3b29bf840f5cc3152
CoinbaseWalletSDKExpo: 89f8ad7f799227be7aff2b9353b7a77d37eb8283
CoinbaseWalletSDKExpo: c79420eb009f482f768c23b6768fc5b2d7c98777
Connect-Swift: d38eedc1907d440314f8d26d5a038a00cbb0f6f1
DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54
EXApplication: 2a0d9abd4feace9c6faedfe541c1dec02e3702cd
EXConstants: f348da07e21b23d2b085e270d7b74f282df1a7d9
EXFileSystem: aec89226b638b82cdd6d6c15d75a8b7f0696226d
EXFileSystem: 844e86ca9b5375486ecc4ef06d3838d5597d895d
EXFont: 6ea3800df746be7233208d80fe379b8ed74f4272
EXImageLoader: 03063370bc06ea1825713d3f55fe0455f7c88d04
Expo: 0d9f112757acc6bf32103eabccf91267780bd580
Expand Down Expand Up @@ -736,10 +736,10 @@ SPEC CHECKSUMS:
SwiftProtobuf: b02b5075dcf60c9f5f403000b3b0c202a11b6ae1
web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959
XMTP: dc02c96b475e326a4a7b3d3912cc45cf3527bd0b
XMTPReactNative: 5c1111c5bd3456e75b3fa67d1ddccabb7a01df11
XMTPReactNative: f4acdf29845869a324d9b99e2021c7050f227d99
XMTPRust: 8848a2ba761b2c961d666632f2ad27d1082faa93
Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9

PODFILE CHECKSUM: 5f3d4a00346ba8cdc06e9f714da38d292b3f8a38
PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2

COCOAPODS: 1.14.3
10 changes: 7 additions & 3 deletions example/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ test('can paginate batch messages', async () => {
} as Query,
])

await bobConversation.send('')
await delayToPropogate()

const messagesAsc: DecodedMessage[] = await alice.listBatchMessages([
{
contentTopic: bobConversation.topic,
Expand All @@ -315,8 +318,6 @@ test('can paginate batch messages', async () => {
throw Error('Unexpected messagesLimited count ' + messagesLimited.length)
}

const content: number = messagesLimited[0].content()
console.log('string', content)
if (messagesLimited[0].content() !== 'Message 4') {
throw Error(
'Unexpected messagesLimited content ' + messagesLimited[0].content()
Expand Down Expand Up @@ -350,6 +351,10 @@ test('can paginate batch messages', async () => {
throw Error('Unexpected messagesAsc content ' + messagesAsc[0].content())
}

if (messagesAsc[6].contentTypeId !== 'xmtp.org/text:1.0') {
throw Error('Unexpected messagesAsc content ' + messagesAsc[6].content())
}

return true
})

Expand Down Expand Up @@ -397,7 +402,6 @@ test('can stream messages', async () => {
)
}
if (!bobConvo.createdAt) {
console.log('bobConvo', bobConvo)
throw Error('Missing createdAt ' + bobConvo.createdAt)
}

Expand Down
1 change: 1 addition & 0 deletions ios/XMTPReactNative.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Pod::Spec.new do |s|
}

s.source_files = "**/*.{h,m,swift}"
s.dependency 'secp256k1.swift'
s.dependency "MessagePacker"
s.dependency "XMTP", "= 0.7.3-alpha0"
end
36 changes: 22 additions & 14 deletions src/lib/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,32 @@ export class Client<ContentTypes> {
'sign',
async (message: { id: string; message: string }) => {
const request: { id: string; message: string } = message
const signatureString = await signer.signMessage(request.message)
const eSig = utils.splitSignature(signatureString)
const r = hexToBytes(eSig.r)
const s = hexToBytes(eSig.s)
const sigBytes = new Uint8Array(65)
sigBytes.set(r)
sigBytes.set(s, r.length)
sigBytes[64] = eSig.recoveryParam

const signature = Buffer.from(sigBytes).toString('base64')

XMTPModule.receiveSignature(request.id, signature)
try {
const signatureString = await signer.signMessage(request.message)
const eSig = utils.splitSignature(signatureString)
const r = hexToBytes(eSig.r)
const s = hexToBytes(eSig.s)
const sigBytes = new Uint8Array(65)
sigBytes.set(r)
sigBytes.set(s, r.length)
sigBytes[64] = eSig.recoveryParam

const signature = Buffer.from(sigBytes).toString('base64')

XMTPModule.receiveSignature(request.id, signature)
} catch (e) {
const errorMessage = 'ERROR in create. User rejected signature'
console.info(errorMessage, e)
this.removeSubscription(enableSubscription)
this.removeSubscription(createSubscription)
reject(errorMessage)
}
}
)

XMTPModule.emitter.addListener('authed', async () => {
this.removeSubscription(enableSubscription)
this.removeSubscription(createSubscription)
const address = await signer.getAddress()
resolve(new Client(address, opts?.codecs || []))
})
Expand All @@ -89,8 +99,6 @@ export class Client<ContentTypes> {
Boolean(enableSubscription)
)
})()
this.removeSubscription(enableSubscription)
this.removeSubscription(createSubscription)
})
}

Expand Down
5 changes: 2 additions & 3 deletions src/lib/Conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ export class Conversation<ContentTypes> {
| undefined
): Promise<DecodedMessage<ContentTypes>[]> {
try {
console.log('message() client is', this.client)

const messages = await XMTP.listMessages(
this.client,
this.topic,
Expand Down Expand Up @@ -229,7 +227,7 @@ export class Conversation<ContentTypes> {
): () => void {
XMTP.subscribeToMessages(this.client.address, this.topic)
const hasSeen = {}
XMTP.emitter.addListener(
const messageSubscription = XMTP.emitter.addListener(
'message',
async ({
clientAddress,
Expand All @@ -253,6 +251,7 @@ export class Conversation<ContentTypes> {
)

return () => {
messageSubscription.remove()
XMTP.unsubscribeFromMessages(this.client.address, this.topic)
}
}
Expand Down
15 changes: 12 additions & 3 deletions src/lib/DecodedMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,27 @@ export class DecodedMessage<ContentTypes = any> {
const codec = this.client.codecRegistry[
this.contentTypeId
] as JSContentCodec<ContentTypes>

if (!codec) {
throw new Error(
`no content type found ${JSON.stringify(this.contentTypeId)}`
)
}
return codec.decode(encoded)
} else {
for (const codec of Object.values(this.client.codecRegistry)) {
if ('contentKey' in codec && this.nativeContent[codec.contentKey]) {
if (
('contentKey' in codec && this.nativeContent[codec.contentKey]) ||
this.nativeContent.hasOwnProperty('text')
) {
return (codec as NativeContentCodec<ContentTypes>).decode(
this.nativeContent
)
}
}

throw new Error(`no content type found ${JSON.stringify(this.nativeContent)}`)
throw new Error(
`no content type found ${JSON.stringify(this.nativeContent)}`
)
}
}
}

0 comments on commit c00864f

Please sign in to comment.