JSLib Reference Manual / Exports
JSLib Reference Manual#
Table of contents#
Namespaces#
Classes#
Interfaces#
Type Aliases#
Variables#
Functions#
Type Aliases#
ChannelMessageTypes#
Ƭ ChannelMessageTypes: "ack" | "keys" | "invalid" | "ready" | "encrypted"
SB384Hash#
Ƭ SB384Hash: string
SBChannelId#
Ƭ SBChannelId: SB384Hash
SBObjectType#
Ƭ SBObjectType: "f" | "p" | "b" | "t"
SBUserId#
Ƭ SBUserId: SB384Hash
Variables#
SB#
• SB: Object
Type declaration#
sbCrypto#
• Const sbCrypto: SBCrypto
This is the GLOBAL SBCrypto object, which is instantiated immediately upon loading the jslib library.
You should use this guy, not instantiate your own.
version#
• Const version: "1.1.25 (pre) build 02"
Functions#
arrayBuffer32ToBase62#
▸ arrayBuffer32ToBase62(buffer): string
arrayBuffer32ToBase62 converts an ArrayBuffer32 to a base62 encoded string.
Parameters#
Name |
Type |
Description |
|---|---|---|
|
|
ArrayBuffer32 |
Returns#
string
base62 encoded string
arrayBufferToBase64#
▸ arrayBufferToBase64(buffer, variant?): string
Standardized ‘btoa()’-like function, e.g., takes a binary string (‘b’) and returns a Base64 encoded version (‘a’ used to be short for ‘ascii’).
Parameters#
Name |
Type |
Default value |
Description |
|---|---|---|---|
|
|
|
binary string |
|
|
|
‘b64’ or ‘url’ |
Returns#
string
returns Base64 encoded string
assemblePayload#
▸ assemblePayload(data): BodyInit | null
Assemble payload. This creates a single binary (wire) format of an arbitrary set of (named) binary objects.
Parameters#
Name |
Type |
|---|---|
|
Returns#
BodyInit | null
base62ToArrayBuffer32#
▸ base62ToArrayBuffer32(s): ArrayBuffer
base62ToArrayBuffer32 converts a base62 encoded string to an ArrayBuffer32.
Parameters#
Name |
Type |
Description |
|---|---|---|
|
|
base62 encoded string |
Returns#
ArrayBuffer
ArrayBuffer32
base62ToBase64#
▸ base62ToBase64(s): string
base62ToBase64 converts a base62 encoded string to a base64 encoded string.
Parameters#
Name |
Type |
Description |
|---|---|---|
|
|
base62 encoded string |
Returns#
string
base64 encoded string
Throws
Error if the string is not a valid base62 encoded string
base64ToArrayBuffer#
▸ base64ToArrayBuffer(str): Uint8Array
Standardized ‘atob()’ function, e.g. takes the a Base64 encoded
input and decodes it. Note: always returns Uint8Array.
Accepts both regular Base64 and the URL-friendly variant,
where + => -, / => _, and the padding character is omitted.
Parameters#
Name |
Type |
Description |
|---|---|---|
|
|
string in either regular or URL-friendly representation. |
Returns#
Uint8Array
returns decoded binary result
base64ToBase62#
▸ base64ToBase62(s): string
base64ToBase62 converts a base64 encoded string to a base62 encoded string.
Parameters#
Name |
Type |
Description |
|---|---|---|
|
|
base64 encoded string |
Returns#
string
base62 encoded string
Throws
Error if the string is not a valid base64 encoded string
cleanBase32mi#
▸ cleanBase32mi(s): string
This function disambiguates strings that are known to be ‘base32mi’ type. Below is the list of base32 characters, and the disambiguation table. base32mi is designed to be human-friendly, so this function can be safely called anywhere you have human input - including as an event on an input field that immediately makes any correction.
You can think of the translation either in terms of many-to-one (all entered characters that map to a specific base32mi character), or as a one-to-one correspondence (where ‘.’ means ‘no change’).
Parameters#
Name |
Type |
|---|---|
|
|
Returns#
string
Example
'base32mi': '0123456789abcdefyhEjkLmNHpFrRTUW'
Disambiguation transformations:
[OoQD] -> '0'
[lIiJ] -> '1'
[Zz] -> '2'
[A] -> '4'
[Ss] -> '5'
[G] -> '6'
[t] -> '7'
[B] -> '8'
[gq] -> '9'
[C] -> 'c'
[Y] -> 'y'
[KxX] -> 'k'
[M] -> 'm'
[n] -> 'N'
[P] -> 'p'
[uvV] -> 'U'
[w] -> 'W'
0123456789abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ
................9.1..1.N0.9.57UUk.248c0EF6.11kLm.0p0.5..Uky2
compareBuffers#
▸ compareBuffers(a, b): boolean
Compare buffers
Parameters#
Name |
Type |
|---|---|
|
|
|
|
Returns#
boolean
decodeB64Url#
▸ decodeB64Url(input): string
Decode b64 URL
Parameters#
Name |
Type |
|---|---|
|
|
Returns#
string
encodeB64Url#
▸ encodeB64Url(input): string
Encode into b64 URL
Parameters#
Name |
Type |
|---|---|
|
|
Returns#
string
encryptedContentsMakeBinary#
▸ encryptedContentsMakeBinary(o): EncryptedContentsBin
Force EncryptedContents object to binary (interface supports either string or arrays). String contents implies base64 encoding.
Parameters#
Name |
Type |
|---|---|
|
Returns#
extractPayload#
▸ extractPayload(payload): SBPayload
Extract payload - this decodes from our binary (wire) format to a JS object. This provides a binary encoding of any JSON, and it allows some elements of the JSON to be raw (binary).
Parameters#
Name |
Type |
|---|---|
|
|
Returns#
getRandomValues#
▸ getRandomValues(buffer): Uint8Array
Fills buffer with random data
Parameters#
Name |
Type |
|---|---|
|
|
Returns#
Uint8Array
isBase62Encoded#
▸ isBase62Encoded(value): value is Base62Encoded
Parameters#
Name |
Type |
|---|---|
|
|
Returns#
value is Base62Encoded
jsonParseWrapper#
▸ jsonParseWrapper(str, loc): any
There are many problems with JSON parsing, adding a wrapper to capture more info. The ‘loc’ parameter should be a (unique) string that allows you to find the usage in the code; one approach is the line number in the file (at some point).
Parameters#
Name |
Type |
|---|---|
|
|
|
|
Returns#
any
partition#
▸ partition(str, n): void
Partition
Parameters#
Name |
Type |
|---|---|
|
|
|
|
Returns#
void
simpleRand256#
▸ simpleRand256(): number
Returns random number
Returns#
number
integer 0..255
simpleRandomString#
▸ simpleRandomString(n, code): string
Returns a random string in requested encoding
Parameters#
Name |
Type |
|---|---|
|
|
|
|
Returns#
string
random string
base32mi: 0123456789abcdefyhEjkLmNHpFrRTUW