GitHub image
webnative
‚ĆėK
Exports
Readme
Functions
3
initialise
Docs
Import
Tests
3
References
2

Check if we're authenticated, process any lobby query-parameters present in the URL, and initiate the user's file system if authenticated (can be disabled).

See loadFileSystem if you want to load the user's file system yourself. NOTE: Only works on the main/ui thread, as it uses window.location.

function initialise(
options: {
permissions?: Permissions
autoRemoveUrlParams?: boolean
loadFileSystem?: boolean
rootKey?: string
}
): Promise<State>
isSupported
Docs
Import
Tests
3
References
2
function isSupported(): Promise<boolean>
initialize
Docs
Import
Tests
3
References
2

Check if we're authenticated, process any lobby query-parameters present in the URL, and initiate the user's file system if authenticated (can be disabled).

See loadFileSystem if you want to load the user's file system yourself. NOTE: Only works on the main/ui thread, as it uses window.location.

function initialize(
options: {
permissions?: Permissions
autoRemoveUrlParams?: boolean
loadFileSystem?: boolean
rootKey?: string
}
): Promise<State>
Enums
2
Scenario
Docs
Import
Tests
3
References
2
enum Scenario {
NotAuthorised = "NOT_AUTHORISED",
AuthSucceeded = "AUTH_SUCCEEDED",
AuthCancelled = "AUTH_CANCELLED",
Continuation  = "CONTINUATION",
}
InitialisationError
Docs
Import
Tests
3
References
2
enum InitialisationError {
InsecureContext    = "INSECURE_CONTEXT",
UnsupportedBrowser = "UNSUPPORTED_BROWSER",
}
object
1
fs
Docs
Import
Tests
3
References
2
{

Creates a file system with an empty public tree & an empty private tree at the root.

empty: (opts?: NewFileSystemOptions) => Promise<FileSystem>

Loads an existing file system from a CID.

fromCID: (cid: string, opts?: FileSystemOptions) => Promise<FileSystem>
}
Namespaces
9
apps
index
Docs
Import
Tests
3
References
2

Get A list of all of your apps and their associated domain names

function index(): Promise<App[]>
create
Docs
Import
Tests
3
References
2

Creates a new app, assigns an initial subdomain, and sets an asset placeholder

function create(

Subdomain to create the fission app with

subdomain: string
): Promise<App>
deleteByDomain
Docs
Import
Tests
3
References
2

Destroy app by any associated domain

function deleteByDomain(

The domain associated with the app we want to delete

domain: string
): Promise<void>
publish
Docs
Import
Tests
3
References
2

Updates an app by CID

function publish(domain: string, cid: string): Promise<void>
App
Docs
Import
Tests
3
References
2
type App = { domains: string[], insertedAt: string, modifiedAt: string }
dataRoot
lookup
Docs
Import
Tests
3
References
2

Get the CID of a user's data root. First check Fission server, then check DNS

function lookup(

The username of the user that we want to get the data root of.

username: string
): Promise<string>
lookupOnFisson
Docs
Import
Tests
3
References
2

Get the CID of a user's data root from the Fission server.

function lookupOnFisson(

The username of the user that we want to get the data root of.

username: string
): Promise<string>
update
Docs
Import
Tests
3
References
2

Update a user's data root.

function update(

The CID of the data root.

cid: string,

The proof to use in the UCAN sent to the API.

proof: string
): Promise<{ success: boolean }>
did
root
Docs
Import
Tests
3
References
2

Get the root write-key DID for a user. Stored at _did.${username}.${endpoints.user}

function root(username: string): Promise<string>
ownRoot
Docs
Import
Tests
3
References
2

Get a user's own root write-key DID.

function ownRoot(): Promise<string>
exchange
Docs
Import
Tests
3
References
2

Create a DID based on the exchange key-pair.

function exchange(): Promise<string>
write
Docs
Import
Tests
3
References
2

Create a DID based on the write key-pair.

function write(): Promise<string>
ucan
Docs
Import
Tests
3
References
2

Create a DID based on the write key-pair.

function ucan(): Promise<string>
publicKeyToDid
Docs
Import
Tests
3
References
2

Convert a base64 public key to a DID (did:key).

function publicKeyToDid(publicKey: string, type: KeyType): string
didToPublicKey
Docs
Import
Tests
3
References
2

Convert a DID (did:key) to a base64 public key.

function didToPublicKey(did: string): { publicKey: string, type: KeyType }
KeyType
Docs
Import
Tests
3
References
2
enum KeyType {
RSA     = "rsa",
Edwards = "ed25519",
BLS     = "bls12-381",
}
verifySignedData
Docs
Import
Tests
3
References
2

Verify the signature of some data (string, ArrayBuffer or Uint8Array), given a DID.

function verifySignedData(
_: { charSize?: number, data: string, did: string, signature: string }
): Promise<boolean>
errors
NoPermissionError
Docs
Import
Tests
3
References
2
class NoPermissionError {
constructor(message: string): NoPermissionError
}
lobby
createAccount
Docs
Import
Tests
3
References
2

Create a user account.

function createAccount(
userProps: { email: string, username: string }
): Promise<{ success: boolean }>
resendVerificationEmail
Docs
Import
Tests
3
References
2

Ask the fission server to send another verification email to the user currently logged in.

Throws if the user is not logged in.

function resendVerificationEmail(): Promise<{ success: boolean }>
storeFileSystemRootKey
Docs
Import
Tests
3
References
2

Store the read key for the root PrivateTree (ie. /private)

function storeFileSystemRootKey(key: string): Promise<void>
isUsernameAvailable
Docs
Import
Tests
3
References
2

Check if a username is available.

function isUsernameAvailable(username: string): Promise<boolean>
isUsernameValid
Docs
Import
Tests
3
References
2

Check if a username is valid.

function isUsernameValid(username: string): boolean
path
directory
Docs
Import
Tests
3
References
2

Utility function to create a DirectoryPath

function directory(args: Path): DirectoryPath
file
Docs
Import
Tests
3
References
2

Utility function to create a FilePath

function file(args: Path): FilePath
root
Docs
Import
Tests
3
References
2

Utility function to create a root DirectoryPath

function root(): DirectoryPath
fromPosix
Docs
Import
Tests
3
References
2

Transform a string into a DistinctivePath.

Directories should have the format path/to/dir/ and files should have the format path/to/file.

Leading forward slashes are removed too, so you can pass absolute paths.

function fromPosix(path: string): DistinctivePath
toPosix
Docs
Import
Tests
3
References
2

Transform a DistinctivePath into a string.

Directories will have the format path/to/dir/ and files will have the format path/to/file.

function toPosix(path: DistinctivePath, _?: { absolute: boolean }): string
combine
Docs
Import
Tests
3
References
2

Combine two DistinctivePaths.

function combine(a: DirectoryPath, b: FilePath): FilePath+2
isBranch
Docs
Import
Tests
3
References
2

Is this DistinctivePath of the given Branch?

function isBranch(branch: Branch, path: DistinctivePath): boolean
isDirectory
Docs
Import
Tests
3
References
2

Is this DistinctivePath a directory?

function isDirectory(path: DistinctivePath): boolean
isFile
Docs
Import
Tests
3
References
2

Is this DistinctivePath a file?

function isFile(path: DistinctivePath): boolean
isRootDirectory
Docs
Import
Tests
3
References
2

Is this DirectoryPath a root directory?

function isRootDirectory(path: DirectoryPath): boolean
isSameBranch
Docs
Import
Tests
3
References
2

Check if two DistinctivePath have the same Branch.

function isSameBranch(a: DistinctivePath, b: DistinctivePath): boolean
isSameKind
Docs
Import
Tests
3
References
2

Check if two DistinctivePath are of the same kind.

function isSameKind(a: DistinctivePath, b: DistinctivePath): boolean
kind
Docs
Import
Tests
3
References
2

What Kind of path are we dealing with?

function kind(path: DistinctivePath): Kind
map
Docs
Import
Tests
3
References
2

Map a DistinctivePath.

function map(fn: (p: Path) => Path, path: DistinctivePath): DistinctivePath
parent
Docs
Import
Tests
3
References
2

Get the parent directory of a DistinctivePath.

function parent(path: DistinctivePath): DirectoryPath
removeBranch
Docs
Import
Tests
3
References
2

Remove the Branch of a DistinctivePath (ie. the top-level directory)

function removeBranch(path: DistinctivePath): DistinctivePath
unwrap
Docs
Import
Tests
3
References
2

Unwrap a DistinctivePath.

function unwrap(path: DistinctivePath): Path
log
Docs
Import
Tests
3
References
2

Render a raw Path to a string for logging purposes.

function log(path: Path): string
Branch
Docs
Import
Tests
3
References
2
enum Branch {
Public     = "public",
Pretty     = "p",
Private    = "private",
PrivateLog = "privateLog",
Version    = "version",
}
Kind
Docs
Import
Tests
3
References
2
enum Kind {
Directory = "directory",
File      = "file",
}
Path
Docs
Import
Tests
3
References
2
type Path = string[]
DirectoryPath
Docs
Import
Tests
3
References
2
type DirectoryPath = { directory: Path }
FilePath
Docs
Import
Tests
3
References
2
type FilePath = { file: Path }
DistinctivePath
Docs
Import
Tests
3
References
2

The primarily used type for paths.

type DistinctivePath = DirectoryPath | FilePath
setup
debug
Docs
Import
Tests
3
References
2

Toggle debug mode.

Only adds a few console.logs at this moment.

function debug(_: { enabled: boolean }): boolean
shouldPin
Docs
Import
Tests
3
References
2

Configure whether webnative should aggressively pin everything, or pin nothing at all.

function shouldPin(_: { enabled: boolean }): boolean
endpoints
Docs
Import
Tests
3
References
2

Override endpoints.

You can override each of these, no need to provide them all here.

api Location of the Fission API (default https://runfission.com) lobby Location of the authentication lobby. (default https://auth.fission.codes) user User's domain to use, will be prefixed by username. (default fission.name)

function endpoints(e: Partial<Endpoints>): Endpoints
setDependencies
Docs
Import
Tests
3
References
2
function setDependencies(fns: Partial<Dependencies>): Dependencies
ucan
dictionary
compile
Docs
Import
Tests
3
References
2

Given a list of UCANs, generate a dictionary. The key will be in the form of ${resourceKey}:${resourceValue}

function compile(ucans: string[]): Record<string, string>
resourceLabel
Docs
Import
Tests
3
References
2

Creates the label for a given resource in the UCAN dictionary

function resourceLabel(rsc: Resource): string
filesystemPrefix
Docs
Import
Tests
3
References
2

Lookup the prefix for a filesystem key in the dictionary.

function filesystemPrefix(username: string): string
lookup
Docs
Import
Tests
3
References
2

Look up a UCAN by label

function lookup(label: string): string
lookupAppUcan
Docs
Import
Tests
3
References
2

Look up a UCAN for a platform app.

function lookupAppUcan(domain: string): Promise<string>
lookupFilesystemUcan
Docs
Import
Tests
3
References
2

Look up a UCAN with a file system path.

function lookupFilesystemUcan(path: DirectoryPath | FilePath | "*"): Promise<string>
WNFS_PREFIX
Docs
Import
Tests
3
References
2
"wnfs"
SessionKey
Docs
Import
Tests
3
References
2
type SessionKey = { sessionKey: string }
Fact
Docs
Import
Tests
3
References
2
type Fact = Record<string, string> | SessionKey
Resource
Docs
Import
Tests
3
References
2
type Resource = "*" | Record<string, string>
Potency
Docs
Import
Tests
3
References
2
type Potency = string | Record<string, unknown>
UcanHeader
Docs
Import
Tests
3
References
2
type UcanHeader = { alg: string, typ: string, uav: string }
UcanPayload
Docs
Import
Tests
3
References
2
type UcanPayload = {
aud: string
exp: number
fct: Fact[]
iss: string
nbf: number
prf: string
ptc: Potency
}
Ucan
Docs
Import
Tests
3
References
2
type Ucan = { header: UcanHeader, payload: UcanPayload, signature: string }
build
Docs
Import
Tests
3
References
2

Create a UCAN, User Controlled Authorization Networks, JWT. This JWT can be used for authorization.

Header

alg, Algorithm, the type of signature. typ, Type, the type of this data structure, JWT. uav, UCAN version.

Payload

aud, Audience, the ID of who it's intended for. exp, Expiry, unix timestamp of when the jwt is no longer valid. iss, Issuer, the ID of who sent this. nbf, Not Before, unix timestamp of when the jwt becomes valid. prf, Proof, an optional nested token with equal or greater privileges. ptc, Potency, which rights come with the token. rsc, Resource, the involved resource.

function build(
_: {
addSignature?: boolean
audience: string
facts?: Fact[]
issuer?: string
lifetimeInSeconds?: number
expiration?: number
potency?: Potency
proof?: string
resource?: Resource
}
): Promise<Ucan>
decode
Docs
Import
Tests
3
References
2

Try to decode a UCAN. Will throw if it fails.

function decode(

The encoded UCAN to decode

ucan: string
): Ucan
encode
Docs
Import
Tests
3
References
2

Encode a UCAN.

function encode(

The UCAN to encode

ucan: Ucan
): string
encodeHeader
Docs
Import
Tests
3
References
2

Encode the header of a UCAN.

function encodeHeader(

The UcanHeader to encode

header: UcanHeader
): string
encodePayload
Docs
Import
Tests
3
References
2

Encode the payload of a UCAN.

function encodePayload(

The UcanPayload to encode

payload: UcanPayload
): string
isExpired
Docs
Import
Tests
3
References
2

Check if a UCAN is expired.

function isExpired(

The UCAN to validate

ucan: Ucan
): boolean
isValid
Docs
Import
Tests
3
References
2

Check if a UCAN is valid.

function isValid(

The decoded UCAN

ucan: Ucan
): Promise<boolean>
rootIssuer
Docs
Import
Tests
3
References
2

Given a UCAN, lookup the root issuer.

Throws when given an improperly formatted UCAN. This could be a nested UCAN (ie. proof).

function rootIssuer(

A UCAN.

ucan: string,
level?: number
): string
sign
Docs
Import
Tests
3
References
2

Generate UCAN signature.

function sign(header: UcanHeader, payload: UcanPayload): Promise<string>
dns
lookupTxtRecord
Docs
Import
Tests
3
References
2

Lookup a DNS TXT record.

Race lookups to Google & Cloudflare, return the first to finish

function lookupTxtRecord(

The domain to get the TXT record from.

domain: string
): Promise<string>
googleLookup
Docs
Import
Tests
3
References
2

Lookup DNS TXT record using Google DNS-over-HTTPS

function googleLookup(

The domain to get the TXT record from.

domain: string
): Promise<string>
cloudflareLookup
Docs
Import
Tests
3
References
2

Lookup DNS TXT record using Cloudflare DNS-over-HTTPS

function cloudflareLookup(

The domain to get the TXT record from.

domain: string
): Promise<string>
dnsOverHttps
Docs
Import
Tests
3
References
2

Lookup a DNS TXT record.

If there are multiple records, they will be joined together. Records are sorted by a decimal prefix before they are joined together. Prefixes have a format of 001; ‚Üí 999;

function dnsOverHttps(

The DNS-over-HTTPS endpoint to hit.

url: string
): Promise<string>
lookupDnsLink
Docs
Import
Tests
3
References
2

Lookup a DNSLink.

function lookupDnsLink(

The domain to get the DNSLink from.

domain: string
): Promise<string>
Type Aliases
5
State
Docs
Import
Tests
3
References
2
NotAuthorised
Docs
Import
Tests
3
References
2
type NotAuthorised = {
scenario: import("/lib/index").Scenario.NotAuthorised
permissions: Permissions
authenticated: false
}
AuthSucceeded
Docs
Import
Tests
3
References
2
type AuthSucceeded = {
scenario: import("/lib/index").Scenario.AuthSucceeded
permissions: Permissions
authenticated: true
newUser: boolean
throughLobby: true
username: string
}
AuthCancelled
Docs
Import
Tests
3
References
2
type AuthCancelled = {
scenario: import("/lib/index").Scenario.AuthCancelled
permissions: Permissions
authenticated: false
cancellationReason: string
throughLobby: true
}
Continuation
Docs
Import
Tests
3
References
2
type Continuation = {
scenario: import("/lib/index").Scenario.Continuation
permissions: Permissions
authenticated: true
newUser: false
throughLobby: false
username: string
}
Description
Fission Webnative SDK
Install
yarn add webnative
Copy
Details
Apache-2.0 License
12 Dependencies
Native TypeScript Package
Metrics
Weekly Downloads