-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(pubsub): multibase in pubsub http rpc (#3922)
This PR aims to restore interop with go-ipfs by applying the same changes as in ipfs/kubo#8183 TLDR is that we clean up and unify the API. BREAKING CHANGE: We had to make breaking changes to `pubsub` commands sent over HTTP RPC to fix data corruption caused by topic names and payload bytes that included `\n`. More details in ipfs/kubo#7939 and ipfs/kubo#8183
- Loading branch information
Showing
8 changed files
with
65 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' | ||
import { toString as uint8ArrayToString } from 'uint8arrays/to-string' | ||
import { base64url } from 'multiformats/bases/base64' | ||
|
||
/* HTTP RPC: | ||
* - wraps binary data in multibase. base64url is used to avoid issues | ||
* when a binary data is passed as search param in URL. | ||
* Historical context: https://github.com/ipfs/go-ipfs/issues/7939 | ||
* Multibase wrapping introduced in: https://github.com/ipfs/go-ipfs/pull/8183 | ||
*/ | ||
|
||
/** | ||
* @param {Array<string>} strings | ||
* @returns {Array<string>} strings | ||
*/ | ||
const rpcArrayToTextArray = strings => { | ||
if (Array.isArray(strings)) { | ||
return strings.map(rpcToText) | ||
} | ||
return strings | ||
} | ||
|
||
/** | ||
* @param {string} mb | ||
* @returns {string} | ||
*/ | ||
const rpcToText = mb => uint8ArrayToString(rpcToBytes(mb)) | ||
|
||
/** | ||
* @param {string} mb | ||
* @returns {Uint8Array} | ||
*/ | ||
const rpcToBytes = mb => base64url.decode(mb) | ||
|
||
/** | ||
* @param {string} text | ||
* @returns {string} | ||
*/ | ||
const textToUrlSafeRpc = text => base64url.encode(uint8ArrayFromString(text)) | ||
|
||
export { rpcArrayToTextArray, rpcToText, rpcToBytes, textToUrlSafeRpc } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters