Skip to content

Commit

Permalink
hack pass
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Sep 26, 2024
1 parent 0d96f56 commit 0897c65
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 36 deletions.
14 changes: 7 additions & 7 deletions example2/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ PODS:
- hermes-engine (0.74.5):
- hermes-engine/Pre-built (= 0.74.5)
- hermes-engine/Pre-built (0.74.5)
- LibXMTP (0.5.8-beta5)
- LibXMTP (0.5.9-alpha0)
- Logging (1.0.0)
- MessagePacker (0.4.7)
- RCT-Folly (2024.01.01.00):
Expand Down Expand Up @@ -1245,16 +1245,16 @@ PODS:
- GenericJSON (~> 2.0)
- Logging (~> 1.0.0)
- secp256k1.swift (~> 0.1)
- XMTP (0.15.0-alpha0):
- XMTP (0.15.0-alpha1):
- Connect-Swift (= 0.12.0)
- GzipSwift
- LibXMTP (= 0.5.8-beta5)
- LibXMTP (= 0.5.9-alpha0)
- web3.swift
- XMTPReactNative (0.1.0):
- ExpoModulesCore
- MessagePacker
- secp256k1.swift
- XMTP (= 0.15.0-alpha0)
- XMTP (= 0.15.0-alpha1)
- Yoga (0.0.0)

DEPENDENCIES:
Expand Down Expand Up @@ -1500,7 +1500,7 @@ SPEC CHECKSUMS:
glog: fdfdfe5479092de0c4bdbebedd9056951f092c4f
GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa
hermes-engine: 8c1577f3fdb849cbe7729c2e7b5abc4b845e88f8
LibXMTP: ee1591fdb51bc6cc690c1a9ba10792ccc2104328
LibXMTP: d8e8c8f805bc7b0d0e0b9f3346e8923589a75b8a
Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26
MessagePacker: ab2fe250e86ea7aedd1a9ee47a37083edd41fd02
RCT-Folly: 02617c592a293bd6d418e0a88ff4ee1f88329b47
Expand Down Expand Up @@ -1557,8 +1557,8 @@ SPEC CHECKSUMS:
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
SwiftProtobuf: 407a385e97fd206c4fbe880cc84123989167e0d1
web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959
XMTP: 934d57cbfa3c13450587e63490efb9426e1353b4
XMTPReactNative: c95ed3393330dec9d6adede024f4fb3b2bd1a659
XMTP: def2117c6fab71a96dc59231ddbc9195e6cbcf0b
XMTPReactNative: a6ca07a03cc62951bf11177d9c7c6c6ab9989de8
Yoga: 950bbfd7e6f04790fdb51149ed51df41f329fcc8

PODFILE CHECKSUM: a292fb2731dc26bc955814869c5350d272bed6fa
Expand Down
2 changes: 2 additions & 0 deletions example2/ios/smartwalletexpo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = smartwalletexpo/smartwalletexpo.entitlements;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = FY4NZR34Z3;
ENABLE_BITCODE = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
Expand Down Expand Up @@ -371,6 +372,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = smartwalletexpo/smartwalletexpo.entitlements;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = FY4NZR34Z3;
INFOPLIST_FILE = smartwalletexpo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down
2 changes: 1 addition & 1 deletion example2/src/components/section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Button from "./button";

type SectionProps = {
title: string;
result?: string | Error | null;
result?: any;
onPress?: () => Promise<string | void> | string | void;
buttonLabel?: string;
};
Expand Down
22 changes: 19 additions & 3 deletions example2/src/hooks/useCreateClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,30 @@ export const useCreateClient = (walletClient: WalletClient | undefined) => {
signMessage: (message: string) =>
walletClient.signMessage({ message, account }),
}
console.log('hi 4');

return () => {
const dbEncryptionKey = crypto.getRandomValues(new Uint8Array(32))
return Client.createOrBuild(signer, {


return async () => {
console.log('Client create or bhuld');
try {

const foo = await Client.createOrBuild(signer, {
env: 'dev',
appVersion,
codecs: supportedCodecs,
dbEncryptionKey,
})
console.log({foo})
return foo
} catch (e) {
console.log({e});

} finally {
console.log('finally something');

}


}
}
6 changes: 5 additions & 1 deletion example2/src/wagmiDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export default function WagmiDemo() {
onPress={() => {
disconnect({ connector: connectors[0] })
reset()
void client?.deleteLocalDatabase()
}}
/>
<Section
Expand All @@ -110,9 +111,12 @@ export default function WagmiDemo() {
<Section
key="useCreateClient"
title="useCreateClient"
result={client?.address ?? 'No client created'}
result={client?.address ?? "MOOOOO"}
onPress={async () => {
console.log('hi there');

const client = await createClient()
console.log(client?.address)
setClient(client)
}}
/>
Expand Down
13 changes: 5 additions & 8 deletions ios/ReactNativeSigner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,8 @@ class ReactNativeSigner: NSObject, XMTP.SigningKey {
return
}

guard let signatureData = Data(base64Encoded: Data(signature.utf8)), signatureData.count == 65 else {
continuation.resume(throwing: Error.invalidSignature)
continuations.removeValue(forKey: id)
return
}

let signature = XMTP.Signature.with {
$0.ecdsaCompact.bytes = signatureData[0 ..< 64]
$0.ecdsaCompact.recovery = UInt32(signatureData[64])
$0.ecdsaCompact.bytes = signature.hexToData
}

continuation.resume(returning: signature)
Expand All @@ -49,18 +42,22 @@ class ReactNativeSigner: NSObject, XMTP.SigningKey {

func sign(_ data: Data) async throws -> XMTP.Signature {
let request = SignatureRequest(message: String(data: data, encoding: .utf8)!)
print("about to send sign event")

module.sendEvent("sign", [
"id": request.id,
"message": request.message,
])

return try await withCheckedThrowingContinuation { continuation in
print("about to hit continuation")
continuations[request.id] = continuation
}
}

func sign(message: String) async throws -> XMTP.Signature {
print("HOWDY")
print(message)
return try await sign(Data(message.utf8))
}
}
Expand Down
2 changes: 1 addition & 1 deletion ios/Wrappers/AuthParamsWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct AuthParamsWrapper {
let chainId: UInt64
let blockNumber: UInt64?

init(environment: String, appVersion: String?, enableV3: Bool, dbDirectory: String?, historySyncUrl: String?, isSmartContractWallet: Bool, chainId: UInt64, blockNumber: UInt64) {
init(environment: String, appVersion: String?, enableV3: Bool, dbDirectory: String?, historySyncUrl: String?, isSmartContractWallet: Bool, chainId: UInt64, blockNumber: UInt64?) {
self.environment = environment
self.appVersion = appVersion
self.enableV3 = enableV3
Expand Down
2 changes: 2 additions & 0 deletions ios/XMTPModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ public class XMTPModule: Module {
let client = try await XMTP.Client.createOrBuild(account: signer, options: options)
await self.clientsManager.updateClient(key: client.inboxID, client: client)
self.signer = nil
print("LOPI")
print(client.address)
self.sendEvent("authedV3", try ClientWrapper.encodeToObj(client))
}

Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ export async function createOrBuild(
dbDirectory?: string | undefined,
historySyncUrl?: string | undefined,
isSmartContractWallet?: boolean | undefined,
chainId?: bigint | undefined,
blockNumber?: bigint | undefined
chainId?: number | undefined,
blockNumber?: number | undefined
) {
const encryptionKey = dbEncryptionKey
? Array.from(dbEncryptionKey)
Expand Down Expand Up @@ -1271,8 +1271,8 @@ interface AuthParams {
dbDirectory?: string
historySyncUrl?: string
isSmartContractWallet?: boolean
chainId?: bigint
blockNumber?: bigint
chainId?: number
blockNumber?: number
}

interface CreateGroupParams {
Expand Down
14 changes: 3 additions & 11 deletions src/lib/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,19 +329,10 @@ export class Client<
'sign',
async (message: { id: string; message: string }) => {
const request: { id: string; message: string } = message
console.log("incoming request")
try {
const signatureString = await signer.signMessage(request.message)
const eSig = 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')

await XMTPModule.receiveSignature(request.id, signature)
await XMTPModule.receiveSignature(request.id, signatureString)
} catch (e) {
const errorMessage = 'ERROR in create. User rejected signature'
console.info(errorMessage, e)
Expand Down Expand Up @@ -379,6 +370,7 @@ export class Client<
)
}
)
console.log("Howdy")
await XMTPModule.createOrBuild(
await signer.getAddress(),
options.env,
Expand Down

0 comments on commit 0897c65

Please sign in to comment.