Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion protocol/bin/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ ${project.import.map(n => importMap[n] || '').join('\n')}
${project.import.map(n => `export {${n}}`).join('\n')}
export type Bool = boolean
export type Boolean = boolean
export type Bytes = Buffer
export type Bytes = Uint8Array
export type Double = number
export type Int = number
export type Int64 = number
Expand Down
2 changes: 1 addition & 1 deletion rnmodules/react-native-kb/android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ message(INFO "params: ${NODE_MODULES_DIR}")
# Specifies a path to native header files.
include_directories(
../cpp
"${NODE_MODULES_DIR}/msgpack-cxx-4.1.1/include"
"${NODE_MODULES_DIR}/msgpack-cxx-6.1.0/include"
)

set_target_properties(
Expand Down
28 changes: 13 additions & 15 deletions rnmodules/react-native-kb/cpp/react-native-kb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,19 @@ Value convertMPToJSI(Runtime &runtime, msgpack::object &o) {
case msgpack::type::BIN: {
auto ptr = o.via.bin.ptr;
int size = o.via.bin.size;
// make ArrayBuffer and copy in data
Function arrayBufferCtor =
runtime.global().getPropertyAsFunction(runtime, "ArrayBuffer");
Value ab = arrayBufferCtor.callAsConstructor(runtime, size);
Object abo = ab.getObject(runtime);
ArrayBuffer abbuf = abo.getArrayBuffer(runtime);
std::copy(ptr, ptr + size, abbuf.data(runtime));

// Wrap in Buffer like framed-msg-pack
Object bufObj = runtime.global().getPropertyAsObject(runtime, "Buffer");
Function bufFrom = bufObj.getPropertyAsFunction(runtime, "from");
Value buf = bufFrom.callWithThis(
runtime, bufObj,
std::move(ab)); // Buffer shares the memory and just wraps
return buf;

// make ArrayBuffer and copy in data
Function arrayBufferCtor =
runtime.global().getPropertyAsFunction(runtime, "ArrayBuffer");
Value ab = arrayBufferCtor.callAsConstructor(runtime, size);
Object abo = ab.getObject(runtime);
ArrayBuffer abbuf = abo.getArrayBuffer(runtime);
std::copy(ptr, ptr + size, abbuf.data(runtime));

// Wrap in Uint8Array
Function uCtor = runtime.global().getPropertyAsFunction(runtime, "Uint8Array");
Value uc = uCtor.callAsConstructor(runtime, std::move(abbuf));
return uc;
}
case msgpack::type::ARRAY: {
auto size = o.via.array.size;
Expand Down
2 changes: 1 addition & 1 deletion rnmodules/react-native-kb/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-kb",
"version": "0.1.0",
"version": "0.1.1",
"description": "misc kb",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
4 changes: 2 additions & 2 deletions rnmodules/react-native-kb/react-native-kb.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Pod::Spec.new do |s|
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
s.pod_target_xcconfig = {
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\" $(PODS_ROOT)/../../node_modules/msgpack-cxx-4.1.1/include $(PODS_ROOT)/../keybase.xcframework/ios-arm64/Keybase.framework/Headers",
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\" $(PODS_ROOT)/../../node_modules/msgpack-cxx-6.1.0/include $(PODS_ROOT)/../keybase.xcframework/ios-arm64/Keybase.framework/Headers",
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -DMSGPACK_NO_BOOST=1",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
}
Expand All @@ -37,7 +37,7 @@ Pod::Spec.new do |s|
s.dependency "ReactCommon/turbomodule/core"
else
s.pod_target_xcconfig = {
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\" $(PODS_ROOT)/../../node_modules/msgpack-cxx-4.1.1/include $(PODS_ROOT)/../keybase.xcframework/ios-arm64/Keybase.framework/Headers",
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\" $(PODS_ROOT)/../../node_modules/msgpack-cxx-6.1.0/include $(PODS_ROOT)/../keybase.xcframework/ios-arm64/Keybase.framework/Headers",
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -DMSGPACK_NO_BOOST=1",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
}
Expand Down
5 changes: 1 addition & 4 deletions shared/app/globals.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
// >>>>>>>>>>>>>>>>>>>>>>> DO NOT REORDER ANYTHING in this file <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// This is supposed to bootstrap / polyfill / fixup the app. Do NOT add things here or change things unless you really know
// what's happening
//
// Needed for purepack
// @ts-ignore
globalThis.buffer = global.Buffer = window.Buffer = require('buffer/').Buffer
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

import 'fastestsmallesttextencoderdecoder'
__FILE_SUFFIX__ = ''
__PROFILE__ = false
__HOT__ = false
2 changes: 1 addition & 1 deletion shared/chat/conversation/fwd-msg/team-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const TeamPicker = (props: Props) => {
const message = C.useChatContext(s => s.messageMap.get(ordinal))
const [pickerState, setPickerState] = React.useState<PickerState>('picker')
const [term, setTerm] = React.useState('')
const dstConvIDRef = React.useRef<Buffer | undefined>()
const dstConvIDRef = React.useRef<Uint8Array | undefined>()
const [results, setResults] = React.useState<Array<T.RPCChat.ConvSearchHit>>([])
const [waiting, setWaiting] = React.useState(false)
const [error, setError] = React.useState('')
Expand Down
2 changes: 1 addition & 1 deletion shared/chat/conversation/normal/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type Props = {
requestScrollToBottomRef: React.MutableRefObject<undefined | (() => void)>
requestScrollUpRef: React.MutableRefObject<undefined | (() => void)>
requestScrollDownRef: React.MutableRefObject<undefined | (() => void)>
onPaste: (data: Buffer) => void
onPaste: (data: Uint8Array) => void
onAttach?: (paths: Array<string>) => void
onFocusInput: () => void
onRequestScrollDown: () => void
Expand Down
3 changes: 2 additions & 1 deletion shared/common-adapters/markdown/service-decoration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
renderEmoji as renderEmojiType,
RPCToEmojiData as RPCToEmojiDataType,
} from '../../util/emoji'
import {base64ToUint8Array, uint8ArrayToString} from 'uint8array-extras'

const prefix = 'keybase://'
export const linkIsKeybaseLink = (link: string) => link.startsWith(prefix)
Expand Down Expand Up @@ -112,7 +113,7 @@ const ServiceDecoration = (p: Props) => {
// Parse JSON to get the type of the decoration
let parsed: T.RPCChat.UITextDecoration
try {
const jsonString = Buffer.from(json, 'base64').toString()
const jsonString = uint8ArrayToString(base64ToUint8Array(json))
parsed = JSON.parse(jsonString)
} catch (e) {
return null
Expand Down
3 changes: 2 additions & 1 deletion shared/common-adapters/plain-input.desktop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import pick from 'lodash/pick'
import logger from '../logger'
import {checkTextInfo} from './input.shared'
import type {InternalProps, TextInfo, Selection} from './plain-input'
import {stringToUint8Array} from 'uint8array-extras'

const maybeParseInt = (input: string | number, radix: number): number =>
typeof input === 'string' ? parseInt(input, radix) : input
Expand All @@ -30,7 +31,7 @@ class PlainInput extends React.PureComponent<InternalProps> {
_onChange = ({target: {value = ''}}) => {
if (this.props.maxBytes) {
const {maxBytes} = this.props
if (Buffer.byteLength(value) > maxBytes) {
if (stringToUint8Array(value).byteLength > maxBytes) {
return
}
}
Expand Down
3 changes: 2 additions & 1 deletion shared/common-adapters/plain-input.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {Box2} from './box'
import {checkTextInfo} from './input.shared'
import {getStyle as getTextStyle} from './text'
import {isIOS} from '../constants/platform'
import {stringToUint8Array} from 'uint8array-extras'

// A plain text input component. Handles callbacks, text styling, and auto resizing but
// adds no styling.
Expand Down Expand Up @@ -105,7 +106,7 @@ class PlainInput extends React.PureComponent<InternalProps> {
_onChangeText = (t: string) => {
if (this.props.maxBytes) {
const {maxBytes} = this.props
if (Buffer.byteLength(t) > maxBytes) {
if (stringToUint8Array(t).byteLength > maxBytes) {
return
}
}
Expand Down
3 changes: 2 additions & 1 deletion shared/constants/chat2/common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ export const allMessageTypes: Set<T.Chat.MessageType> = new Set([
'placeholder',
])

export const generateOutboxID = () => Buffer.from([...Array(8)].map(() => Math.floor(Math.random() * 256)))
export const generateOutboxID = () =>
Uint8Array.from([...Array<number>(8)], () => Math.floor(Math.random() * 256))

export const formatTextForQuoting = (text: string) =>
text
Expand Down
11 changes: 6 additions & 5 deletions shared/constants/chat2/convostate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {type StoreApi, type UseBoundStore, useStore} from 'zustand'
import * as Platform from '../platform'
import KB2 from '../../util/electron'
import NotifyPopup from '../../util/notify-popup'
import {hexToUint8Array} from 'uint8array-extras'
const {darwinCopyToChatTempUploadFile} = KB2.functions

const makeThreadSearchInfo = (): T.Chat.ThreadSearchInfo => ({
Expand Down Expand Up @@ -147,7 +148,7 @@ export type ConvoState = ConvoStore & {
restricted: boolean,
convs?: Array<string>
) => void
attachmentPasted: (data: Buffer) => void
attachmentPasted: (data: Uint8Array) => void
attachmentPreviewSelect: (ordinal: T.Chat.Ordinal) => void
attachmentUploadCanceled: (outboxIDs: Array<T.RPCChat.OutboxID>) => void
attachmentDownload: (ordinal: T.Chat.Ordinal) => void
Expand Down Expand Up @@ -553,7 +554,7 @@ const createSlice: Z.ImmerStateCreator<ConvoState> = (set, get) => {
// disable sending exploding messages if flag is false
const ephemeralLifetime = get().explodingMode
const ephemeralData = ephemeralLifetime !== 0 ? {ephemeralLifetime} : {}
const outboxIDs = paths.reduce<Array<Buffer>>((obids, p) => {
const outboxIDs = paths.reduce<Array<Uint8Array>>((obids, p) => {
obids.push(p.outboxID ? p.outboxID : Common.generateOutboxID())
return obids
}, [])
Expand All @@ -565,7 +566,7 @@ const createSlice: Z.ImmerStateCreator<ConvoState> = (set, get) => {
conversationID: T.Chat.keyToConversationID(conversationIDKey),
filename: Styles.unnormalizePath(p.path),
identifyBehavior: T.RPCGen.TLFIdentifyBehavior.chatGui,
metadata: Buffer.from([]),
metadata: new Uint8Array(),
outboxID: outboxIDs[i],
title: titles[i] ?? '',
tlfName: tlfName ?? '',
Expand Down Expand Up @@ -1055,7 +1056,7 @@ const createSlice: Z.ImmerStateCreator<ConvoState> = (set, get) => {
logger.info('bail on not logged in')
return
}
const tlfID = Buffer.from(T.Teams.teamIDToString(teamID), 'hex')
const tlfID = hexToUint8Array(T.Teams.teamIDToString(teamID))
await T.RPCChat.localMarkTLFAsReadLocalRpcPromise({tlfID})
}
C.ignorePromise(f())
Expand Down Expand Up @@ -2227,7 +2228,7 @@ const createSlice: Z.ImmerStateCreator<ConvoState> = (set, get) => {
conversationID: T.Chat.keyToConversationID(conversationIDKey),
filename: path,
identifyBehavior: T.RPCGen.TLFIdentifyBehavior.chatGui,
metadata: Buffer.from([]),
metadata: new Uint8Array(),
outboxID,
title: '',
tlfName: meta.tlfname,
Expand Down
3 changes: 2 additions & 1 deletion shared/constants/chat2/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as Meta from './meta'
import {isMobile, isPhone} from '../platform'
import * as Z from '../../util/zustand'
import * as Common from './common'
import {uint8ArrayToString} from 'uint8array-extras'

export const defaultTopReacjis = [
{name: ':+1:'},
Expand Down Expand Up @@ -1847,7 +1848,7 @@ export const _useState = Z.createZustand<State>((set, get) => {
explodingItems.forEach(i => {
try {
const {category, body} = i.item
const secondsString = Buffer.from(body).toString()
const secondsString = uint8ArrayToString(body)
const seconds = parseInt(secondsString, 10)
if (isNaN(seconds)) {
logger.warn(`Got dirty exploding mode ${secondsString} for category ${category}`)
Expand Down
5 changes: 3 additions & 2 deletions shared/constants/chat2/meta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {formatTimeForConversationList} from '../../util/timestamp'
import {globalColors} from '../../styles'
import {isPhone} from '../platform'
import type {AllowedColors} from '../../common-adapters/text'
import {base64ToUint8Array, uint8ArrayToHex} from 'uint8array-extras'

const conversationMemberStatusToMembershipType = (m: T.RPCChat.ConversationMemberStatus) => {
switch (m) {
Expand All @@ -21,8 +22,8 @@ const conversationMemberStatusToMembershipType = (m: T.RPCChat.ConversationMembe
}

// This one call handles us getting a string or a buffer
const supersededConversationIDToKey = (id: string | Buffer): string => {
return typeof id === 'string' ? Buffer.from(id, 'base64').toString('hex') : id.toString('hex')
const supersededConversationIDToKey = (id: string | Uint8Array): string => {
return typeof id === 'string' ? uint8ArrayToHex(base64ToUint8Array(id)) : uint8ArrayToHex(id)
}

export const unverifiedInboxUIItemToConversationMeta = (
Expand Down
5 changes: 2 additions & 3 deletions shared/constants/fs/platform-specific.desktop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {isWindows, isLinux, pathSep, isDarwin} from '../platform.desktop'
import logger from '../../logger'
import * as Path from '../../util/path'
import KB2 from '../../util/electron.desktop'
import {uint8ArrayToHex} from 'uint8array-extras'

const {openPathInFinder, openURL, getPathType, selectFilesToUploadDialog} = KB2.functions
const {darwinCopyToKBFSTempUploadFile, relaunchApp, uninstallKBFSDialog, uninstallDokanDialog} = KB2.functions
Expand All @@ -20,9 +21,7 @@ const _openPathInSystemFileManagerPromise = async (openPath: string, isFolder: b

const escapeBackslash = isWindows
? (pathElem: string): string =>
pathElem
.replace(/‰/g, '‰2030')
.replace(/([<>:"/\\|?*])/g, (_, c) => '‰' + Buffer.from(c).toString('hex'))
pathElem.replace(/‰/g, '‰2030').replace(/([<>:"/\\|?*])/g, (_, c) => '‰' + uint8ArrayToHex(c))
: (pathElem: string): string => pathElem

const _rebaseKbfsPathToMountLocation = (kbfsPath: T.FS.Path, mountLocation: string) =>
Expand Down
4 changes: 3 additions & 1 deletion shared/constants/gregor.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {uint8ArrayToString} from 'uint8array-extras'

export const bodyToJSON = (body?: Uint8Array) => {
if (!body) return undefined
try {
return JSON.parse(Buffer.from(body).toString())
return JSON.parse(uint8ArrayToString(body))
} catch {
return undefined
}
Expand Down
2 changes: 1 addition & 1 deletion shared/constants/teams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ export const _useState = Z.createZustand<State>((set, get) => {
const pushState = await T.RPCGen.gregorGetStateRpcPromise(undefined, teamWaitingKey(teamID))
const item = pushState.items?.find(i => i.item?.category === chosenChannelsGregorKey)
let teams: Array<string> = []
let msgID: Buffer | undefined
let msgID: Uint8Array | undefined
if (item?.item?.body) {
const body = item.item.body
msgID = item.md?.msgID
Expand Down
9 changes: 5 additions & 4 deletions shared/constants/types/chat2/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as RPCTypes from '../rpc-gen'
import * as _Message from './message'
import type * as Meta from './meta'
import type * as RPCChatTypes from '../rpc-chat-gen'
import {uint8ArrayToHex, hexToUint8Array} from 'uint8array-extras'

export type PaymentConfirmInfo = {
error?: RPCTypes.Status
Expand Down Expand Up @@ -193,16 +194,16 @@ export type RenderMessageType =
| 'attachment:video'

export const conversationIDToKey = (conversationID: RPCChatTypes.ConversationID): Common.ConversationIDKey =>
Common.stringToConversationIDKey(Buffer.from(conversationID).toString('hex'))
Common.stringToConversationIDKey(uint8ArrayToHex(conversationID))

export const keyToConversationID = (key: Common.ConversationIDKey): RPCChatTypes.ConversationID =>
Buffer.from(Common.conversationIDKeyToString(key), 'hex')
hexToUint8Array(Common.conversationIDKeyToString(key))

export const rpcOutboxIDToOutboxID = (outboxID: RPCChatTypes.OutboxID): _Message.OutboxID =>
_Message.stringToOutboxID(outboxID.toString('hex'))
_Message.stringToOutboxID(uint8ArrayToHex(outboxID))

export const outboxIDToRpcOutboxID = (outboxID: _Message.OutboxID): RPCChatTypes.OutboxID =>
Buffer.from(_Message.outboxIDToString(outboxID), 'hex')
hexToUint8Array(_Message.outboxIDToString(outboxID))

export * from './message'
export * from './common'
Expand Down
2 changes: 1 addition & 1 deletion shared/constants/types/rpc-chat-gen.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion shared/constants/types/rpc-gen.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion shared/constants/types/rpc-gregor-gen.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion shared/constants/types/rpc-stellar-gen.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion shared/constants/whats-new.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type * as T from './types'
import * as Z from '../util/zustand'
import {uint8ArrayToString} from 'uint8array-extras'

/*
* IMPORTANT:
Expand Down Expand Up @@ -108,7 +109,7 @@ export const _useState = Z.createZustand<State>((set, get) => {
updateLastSeen: lastSeenItem => {
if (lastSeenItem) {
const {body} = lastSeenItem.item
const pushStateLastSeenVersion = Buffer.from(body).toString()
const pushStateLastSeenVersion = uint8ArrayToString(body)
const lastSeenVersion = pushStateLastSeenVersion || noVersion
// Default to 0.0.0 (noVersion) if user has never marked a version as seen
set(s => {
Expand Down
2 changes: 1 addition & 1 deletion shared/desktop/app/ipctypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ export type Action =
| {type: 'clipboardAvailableFormats'}
| {type: 'installCachedDokan'}
| {type: 'uninstallDokan'; payload: {execPath: string}}
| {type: 'engineSend'; payload: {buf: Buffer}}
| {type: 'engineSend'; payload: {buf: Uint8Array}}
1 change: 0 additions & 1 deletion shared/desktop/renderer/globals.desktop.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
window.Buffer = require('buffer/').Buffer
import {enableMapSet} from 'immer'
enableMapSet()
export {}
Loading