This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(pubsub): new wire format in http rpc
- Loading branch information
Showing
8 changed files
with
97 additions
and
44 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
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
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