@nexys/zk-store 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -2
- package/dist/api-schema.d.ts +2162 -0
- package/dist/api.d.ts +77 -0
- package/dist/crypto.d.ts +29 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +936 -0
- package/dist/index.js.map +15 -0
- package/dist/shares.d.ts +72 -0
- package/dist/tree.d.ts +18 -0
- package/dist/types.d.ts +91 -0
- package/dist/utils.d.ts +8 -0
- package/dist/vault.d.ts +43 -0
- package/package.json +47 -4
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { components, paths } from "./api-schema";
|
|
2
|
+
/** The API's request and response types, generated from openapi.json. */
|
|
3
|
+
export type Schemas = components["schemas"];
|
|
4
|
+
/**
|
|
5
|
+
* Typed client for the backend: paths, parameters, bodies and responses are
|
|
6
|
+
* checked against `api-schema.ts` (regenerate with `bun run gen:api`).
|
|
7
|
+
* Reassigned by `configure`, so read it at call time.
|
|
8
|
+
*/
|
|
9
|
+
export declare let client: import("openapi-fetch").Client<paths, `${string}/${string}`>;
|
|
10
|
+
export type ClientOptions = {
|
|
11
|
+
/** The zk-store server, e.g. `https://zk.example.com`. Default `http://localhost:8080`. */
|
|
12
|
+
baseUrl?: string;
|
|
13
|
+
/** A `fetch` to use instead of the global one (tests, proxies, retries). */
|
|
14
|
+
fetch?: (request: Request) => Promise<Response>;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Points the client at a server. Call once before anything else; a web app
|
|
18
|
+
* on another origin needs the server to allow it (`CORS_ORIGINS`).
|
|
19
|
+
*/
|
|
20
|
+
export declare function configure(options: ClientOptions): void;
|
|
21
|
+
/** The server this client talks to. */
|
|
22
|
+
export declare function getBaseUrl(): string;
|
|
23
|
+
/** An error carrying the server's message when it sent one. */
|
|
24
|
+
export declare function apiError(what: string, response: Response, error?: {
|
|
25
|
+
error?: string;
|
|
26
|
+
}): Error;
|
|
27
|
+
export declare function vaultAuth(): Record<string, string>;
|
|
28
|
+
/** Opens a session for the vault `proof` belongs to, creating it if new. */
|
|
29
|
+
export declare function openVault(proof: Uint8Array, credentialToken?: string): Promise<string>;
|
|
30
|
+
/**
|
|
31
|
+
* Moves the vault to a new key. Afterwards the old key's proof and every
|
|
32
|
+
* session opened with it stop working, and all devices except `keep` are
|
|
33
|
+
* signed out for good.
|
|
34
|
+
*/
|
|
35
|
+
export declare function rotateVault(newProof: Uint8Array, keep: string[]): Promise<string[]>;
|
|
36
|
+
export declare function closeVault(): void;
|
|
37
|
+
/** Thrown when a conditional write loses a race with another device. */
|
|
38
|
+
export declare class ConflictError extends Error {
|
|
39
|
+
constructor();
|
|
40
|
+
}
|
|
41
|
+
/** What a write expects the blob's current version to be. */
|
|
42
|
+
export type Expect = {
|
|
43
|
+
absent: true;
|
|
44
|
+
} | {
|
|
45
|
+
etag: string;
|
|
46
|
+
};
|
|
47
|
+
export declare function getBlobVersioned(id: string): Promise<{
|
|
48
|
+
data: Uint8Array;
|
|
49
|
+
etag: string;
|
|
50
|
+
} | null>;
|
|
51
|
+
export declare function getBlob(id: string): Promise<Uint8Array | null>;
|
|
52
|
+
export declare function putBlob(id: string, data: Uint8Array, expect?: Expect): Promise<void>;
|
|
53
|
+
export declare function deleteBlob(id: string): Promise<void>;
|
|
54
|
+
/** Revokes one of this vault's devices. */
|
|
55
|
+
export declare function revokeCredential(credentialId: string): Promise<void>;
|
|
56
|
+
export declare function getRecoveryBlob(recoveryId: string): Promise<Uint8Array | null>;
|
|
57
|
+
export declare function putRecoveryBlob(recoveryId: string, data: Uint8Array): Promise<void>;
|
|
58
|
+
export declare function deleteRecoveryBlob(recoveryId: string): Promise<void>;
|
|
59
|
+
export declare function createInvite(wrappedUserKey: Uint8Array): Promise<string>;
|
|
60
|
+
export declare function createCheckoutSession(): Promise<Schemas["CheckoutResponse"]>;
|
|
61
|
+
export declare function getSubscriptionStatus(): Promise<Schemas["SubscriptionStatus"]>;
|
|
62
|
+
export declare function getHealth(): Promise<Schemas["HealthResponse"]>;
|
|
63
|
+
/** Options for `navigator.credentials.create()`, plus the challenge id. */
|
|
64
|
+
export declare function registerOptions(): Promise<Schemas["RegistrationChallenge"]>;
|
|
65
|
+
/** Finishes a passkey registration; returns a credential token. */
|
|
66
|
+
export declare function register(challengeId: string, attestation: Record<string, unknown>): Promise<Schemas["RegisterResponse"]>;
|
|
67
|
+
/** Options for `navigator.credentials.get()`, plus the challenge id. */
|
|
68
|
+
export declare function authenticateOptions(): Promise<Schemas["AuthenticationChallenge"]>;
|
|
69
|
+
/** Finishes a passkey sign-in; returns a credential token and the wrapped key. */
|
|
70
|
+
export declare function authenticate(challengeId: string, assertion: Record<string, unknown>): Promise<Schemas["AuthenticateResponse"]>;
|
|
71
|
+
/** Stores this device's wrapped `userKey`, with the credential's own token. */
|
|
72
|
+
export declare function setWrappedKey(credentialId: string, credentialToken: string, wrapped: Uint8Array): Promise<void>;
|
|
73
|
+
/** The invite, or `null` once it's gone or expired. */
|
|
74
|
+
export declare function getInvite(inviteId: string): Promise<Schemas["InviteView"] | null>;
|
|
75
|
+
export declare function claimInvite(inviteId: string): Promise<void>;
|
|
76
|
+
/** Server-Sent Events for an invite (`EventSource` can't go through `client`). */
|
|
77
|
+
export declare function inviteEventsUrl(inviteId: string): string;
|
package/dist/crypto.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Where to load the crypto module's `.wasm` from, or its bytes. */
|
|
2
|
+
export type WasmSource = string | URL | Response | BufferSource | WebAssembly.Module;
|
|
3
|
+
/**
|
|
4
|
+
* Loads the WASM crypto module. Call once, and wait for it, before using the
|
|
5
|
+
* client.
|
|
6
|
+
*
|
|
7
|
+
* With no argument the `.wasm` is loaded next to `@nexys/zk-store-crypto`'s
|
|
8
|
+
* JS (`new URL(..., import.meta.url)`), which Vite, webpack 5 and Bun's
|
|
9
|
+
* bundler all handle. Pass a URL when you serve the file yourself, or the
|
|
10
|
+
* bytes on a server runtime.
|
|
11
|
+
*/
|
|
12
|
+
export declare function ensureCryptoReady(wasm?: WasmSource): Promise<void>;
|
|
13
|
+
export declare function generateKey(): Uint8Array;
|
|
14
|
+
export declare function generateUserKey(): Uint8Array;
|
|
15
|
+
export declare function generateRecoveryPhrase(): string;
|
|
16
|
+
export declare function getRecoveryId(phrase: string): Promise<string>;
|
|
17
|
+
/** Normalizes a 12-word phrase and checks its BIP39 checksum. */
|
|
18
|
+
export declare function normalizeRecoveryPhrase(input: string): string | null;
|
|
19
|
+
/** Proof of holding `userKey` that opens a vault session on the server. */
|
|
20
|
+
export declare function vaultProof(userKeyRaw: Uint8Array): Uint8Array;
|
|
21
|
+
export declare function toBase64(buffer: ArrayBuffer | Uint8Array): string;
|
|
22
|
+
export declare function fromBase64(base64: string): Uint8Array;
|
|
23
|
+
export declare function deriveRecoveryKey(phrase: string): Promise<CryptoKey>;
|
|
24
|
+
export declare function deriveKey(ikm: ArrayBuffer, info: string): Promise<CryptoKey>;
|
|
25
|
+
export declare function wrapKey(keyToWrap: Uint8Array, wrappingKey: CryptoKey): Promise<Uint8Array>;
|
|
26
|
+
export declare function unwrapKey(wrappedKey: Uint8Array, unwrappingKey: CryptoKey): Promise<Uint8Array>;
|
|
27
|
+
export declare function encrypt(data: ArrayBuffer, key: CryptoKey): Promise<Uint8Array>;
|
|
28
|
+
export declare function decrypt(data: Uint8Array, key: CryptoKey): Promise<ArrayBuffer>;
|
|
29
|
+
export declare function importKey(raw: Uint8Array): Promise<CryptoKey>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { createVault, unlockWithKey, unlockWithRecoveryPhrase, Vault } from "./vault";
|
|
2
|
+
export * from "./api";
|
|
3
|
+
export * from "./crypto";
|
|
4
|
+
export * from "./tree";
|
|
5
|
+
export * from "./shares";
|
|
6
|
+
export * from "./utils";
|
|
7
|
+
export type * from "./types";
|
|
8
|
+
export type { components, paths } from "./api-schema";
|