@tinycloud/web-sdk 2.11.0-beta.9 → 2.11.0
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/dist/credentials/browser.d.ts +33 -0
- package/dist/credentials/index.d.ts +8 -0
- package/dist/credentials/interpreter.d.ts +20 -0
- package/dist/credentials/renderer.d.ts +23 -0
- package/dist/credentials/service.d.ts +25 -0
- package/dist/credentials/storage.d.ts +21 -0
- package/dist/credentials/transport.d.ts +37 -0
- package/dist/credentials/types.d.ts +126 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +1 -1
- package/dist/modules/tcw.d.ts +18 -1
- package/dist/openkey-session.d.ts +4 -2
- package/package.json +4 -4
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { CredentialFlowDescriptor } from "@tinycloud/sdk-core";
|
|
2
|
+
import type { CredentialInteractionAdapter, CredentialRedirectResumeState, CredentialRedirectStore } from "./types";
|
|
3
|
+
interface BrowserSurface {
|
|
4
|
+
readonly opener: Window;
|
|
5
|
+
open(url: string): Window | null;
|
|
6
|
+
redirect(url: string): void;
|
|
7
|
+
}
|
|
8
|
+
/** Exact-origin, locator-only browser interaction. Messages are non-secret wake signals. */
|
|
9
|
+
export declare class BrowserCredentialInteraction implements CredentialInteractionAdapter {
|
|
10
|
+
private readonly surface;
|
|
11
|
+
readonly kind: "popup" | "redirect";
|
|
12
|
+
constructor(kind?: "popup" | "redirect", surface?: BrowserSurface);
|
|
13
|
+
start(input: {
|
|
14
|
+
interaction: CredentialFlowDescriptor["interaction"];
|
|
15
|
+
locator: string;
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
}): Promise<{
|
|
18
|
+
wake: () => Promise<any>;
|
|
19
|
+
close: () => any;
|
|
20
|
+
closed: () => boolean;
|
|
21
|
+
}>;
|
|
22
|
+
}
|
|
23
|
+
/** Request-scoped redirect continuation. It stores no TinyCloud session or key material. */
|
|
24
|
+
export declare class BrowserCredentialRedirectStore implements CredentialRedirectStore {
|
|
25
|
+
private readonly storage;
|
|
26
|
+
private readonly key;
|
|
27
|
+
constructor(storage?: Pick<Storage, "getItem" | "setItem" | "removeItem">, key?: string);
|
|
28
|
+
load(): Promise<CredentialRedirectResumeState | undefined>;
|
|
29
|
+
save(state: CredentialRedirectResumeState): Promise<void>;
|
|
30
|
+
clear(): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type CredentialFlowDescriptor, type CredentialProgressEvent, type CredentialRequirement } from "@tinycloud/sdk-core";
|
|
2
|
+
import type { CredentialAcquisitionTransport, CredentialSigningAdapter, PrimitiveStepHandler } from "./types";
|
|
3
|
+
/** Finite step interpreter. Dispatch is exclusively by registered primitive and version. */
|
|
4
|
+
export declare function interpretCredentialFlow(input: {
|
|
5
|
+
readonly descriptor: CredentialFlowDescriptor;
|
|
6
|
+
readonly requirement: CredentialRequirement;
|
|
7
|
+
readonly requestId: string;
|
|
8
|
+
readonly verifier: string;
|
|
9
|
+
readonly holderDid: string;
|
|
10
|
+
readonly descriptorDigest: string;
|
|
11
|
+
readonly requirementDigest: string;
|
|
12
|
+
readonly openerOrigin: string;
|
|
13
|
+
readonly transport: CredentialAcquisitionTransport;
|
|
14
|
+
readonly signing: CredentialSigningAdapter;
|
|
15
|
+
readonly handlers?: Partial<Record<"collect_input" | "mailbox_otp", PrimitiveStepHandler>>;
|
|
16
|
+
readonly signal?: AbortSignal;
|
|
17
|
+
readonly onProgress?: (event: CredentialProgressEvent) => void;
|
|
18
|
+
readonly onWait?: () => Promise<void>;
|
|
19
|
+
}): Promise<void>;
|
|
20
|
+
//# sourceMappingURL=interpreter.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CredentialFlowDescriptor, CredentialUxState } from "@tinycloud/sdk-core";
|
|
2
|
+
export interface CredentialRendererModel {
|
|
3
|
+
readonly title: string;
|
|
4
|
+
readonly description: string;
|
|
5
|
+
readonly consent: string;
|
|
6
|
+
readonly fields: readonly {
|
|
7
|
+
readonly id: string;
|
|
8
|
+
readonly label: string;
|
|
9
|
+
readonly required: true;
|
|
10
|
+
readonly inputMode: "email" | "text";
|
|
11
|
+
}[];
|
|
12
|
+
readonly steps: readonly {
|
|
13
|
+
readonly id: string;
|
|
14
|
+
readonly primitive: string;
|
|
15
|
+
readonly title: string;
|
|
16
|
+
readonly description: string;
|
|
17
|
+
}[];
|
|
18
|
+
readonly stateLabels: Readonly<Record<"progress" | "success" | "recovery", string>>;
|
|
19
|
+
readonly state: CredentialUxState;
|
|
20
|
+
}
|
|
21
|
+
/** Shared descriptor-driven UX model. Dispatch is only by the finite primitive registry. */
|
|
22
|
+
export declare function renderCredentialDescriptor(descriptor: CredentialFlowDescriptor, state?: CredentialUxState): CredentialRendererModel;
|
|
23
|
+
//# sourceMappingURL=renderer.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type CredentialFlowDescriptor, type CredentialIssuerMetadata, type CredentialRequirement, type IssuedCredentialEnvelope, type StoredCredentialRecord, type VerifiedCredential } from "@tinycloud/sdk-core";
|
|
2
|
+
import { OpenCredentialsHttpTransport } from "./transport";
|
|
3
|
+
import type { CredentialClient, CredentialsAcquireOptions, CredentialsEnsureOptions, CredentialsEnsureResult, CredentialsOperationOptions } from "./types";
|
|
4
|
+
export declare class CredentialsService {
|
|
5
|
+
private readonly client;
|
|
6
|
+
constructor(client: CredentialClient);
|
|
7
|
+
private descriptor;
|
|
8
|
+
find(requirementValue: CredentialRequirement, options?: CredentialsOperationOptions): Promise<StoredCredentialRecord | undefined>;
|
|
9
|
+
verify(envelope: IssuedCredentialEnvelope, input: {
|
|
10
|
+
readonly descriptor: CredentialFlowDescriptor;
|
|
11
|
+
readonly requirement: CredentialRequirement;
|
|
12
|
+
readonly transport?: OpenCredentialsHttpTransport;
|
|
13
|
+
readonly issuerMetadata?: CredentialIssuerMetadata;
|
|
14
|
+
readonly fetch?: typeof fetch;
|
|
15
|
+
readonly signal?: AbortSignal;
|
|
16
|
+
readonly now?: Date;
|
|
17
|
+
}): Promise<VerifiedCredential>;
|
|
18
|
+
store(verified: VerifiedCredential, requirementValue: CredentialRequirement, options?: CredentialsOperationOptions): Promise<{
|
|
19
|
+
readonly record: StoredCredentialRecord;
|
|
20
|
+
readonly receipt: import("@tinycloud/sdk-core").CredentialStorageReceipt;
|
|
21
|
+
}>;
|
|
22
|
+
acquire(requirementValue: CredentialRequirement, options: CredentialsAcquireOptions): Promise<VerifiedCredential>;
|
|
23
|
+
ensure(requirementValue: CredentialRequirement, options: CredentialsEnsureOptions): Promise<CredentialsEnsureResult>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type CredentialRequirement, type CredentialStorageReceipt, type IKVService, type StoredCredentialRecord, type VerifiedCredential } from "@tinycloud/sdk-core";
|
|
2
|
+
export declare function findStoredCredential(input: {
|
|
3
|
+
readonly kv: IKVService;
|
|
4
|
+
readonly requirement: CredentialRequirement;
|
|
5
|
+
readonly holderDid: string;
|
|
6
|
+
readonly ownerDid: string;
|
|
7
|
+
readonly now?: Date;
|
|
8
|
+
}): Promise<StoredCredentialRecord | undefined>;
|
|
9
|
+
export declare function storeCredential(input: {
|
|
10
|
+
readonly kv: IKVService;
|
|
11
|
+
readonly verified: VerifiedCredential;
|
|
12
|
+
readonly requirement: CredentialRequirement;
|
|
13
|
+
readonly requirementDigest: string;
|
|
14
|
+
readonly activeHolderDid: string;
|
|
15
|
+
readonly activeOwnerDid: string;
|
|
16
|
+
readonly now?: Date;
|
|
17
|
+
}): Promise<{
|
|
18
|
+
readonly record: StoredCredentialRecord;
|
|
19
|
+
readonly receipt: CredentialStorageReceipt;
|
|
20
|
+
}>;
|
|
21
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type CredentialFlowDescriptor, type CredentialHolderBinding, type CredentialIssuerMetadata, type CredentialRequirement, type IssuedCredentialEnvelope } from "@tinycloud/sdk-core";
|
|
2
|
+
import type { CredentialAcquisitionTransport, CredentialRequestState, PrimitiveStepResult } from "./types";
|
|
3
|
+
export declare class OpenCredentialsHttpTransport implements CredentialAcquisitionTransport {
|
|
4
|
+
private readonly descriptor;
|
|
5
|
+
private readonly fetchFn;
|
|
6
|
+
private readonly nonces;
|
|
7
|
+
private readonly bindings;
|
|
8
|
+
constructor(descriptor: CredentialFlowDescriptor, fetchFn?: typeof fetch);
|
|
9
|
+
private url;
|
|
10
|
+
private request;
|
|
11
|
+
create(input: {
|
|
12
|
+
descriptor: CredentialFlowDescriptor;
|
|
13
|
+
descriptorDigest: string;
|
|
14
|
+
requirement: CredentialRequirement;
|
|
15
|
+
requirementDigest: string;
|
|
16
|
+
holderDid: string;
|
|
17
|
+
openerOrigin: string;
|
|
18
|
+
completionVerifierChallenge: string;
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
}): Promise<{
|
|
21
|
+
requestId: string;
|
|
22
|
+
locator: string;
|
|
23
|
+
expiresAt: string;
|
|
24
|
+
correlationId: string;
|
|
25
|
+
}>;
|
|
26
|
+
private proofStep;
|
|
27
|
+
state(id: string, verifier: string, signal?: AbortSignal): Promise<CredentialRequestState>;
|
|
28
|
+
beginStep(id: string, verifier: string, stepId: "collect_input" | "mailbox_otp", signal?: AbortSignal): Promise<void>;
|
|
29
|
+
submitStep(id: string, verifier: string, stepId: string, proof: PrimitiveStepResult, signal?: AbortSignal): Promise<void>;
|
|
30
|
+
holderBinding(id: string, verifier: string, signal?: AbortSignal): Promise<CredentialHolderBinding>;
|
|
31
|
+
submitHolderSignature(id: string, verifier: string, signature: string, signal?: AbortSignal): Promise<void>;
|
|
32
|
+
issue(id: string, verifier: string, signal?: AbortSignal): Promise<void>;
|
|
33
|
+
result(id: string, verifier: string, signal?: AbortSignal): Promise<IssuedCredentialEnvelope>;
|
|
34
|
+
issuerMetadata(signal?: AbortSignal): Promise<CredentialIssuerMetadata>;
|
|
35
|
+
checkStatus(status: IssuedCredentialEnvelope["status"], _signal?: AbortSignal): Promise<boolean>;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { ClientSession, CredentialFlowDescriptor, CredentialHolderBinding, CredentialIssuerMetadata, CredentialProgressEvent, CredentialRequirement, CredentialStorageReceipt, IssuedCredentialEnvelope, IKVService, StoredCredentialRecord, VerifiedCredential } from "@tinycloud/sdk-core";
|
|
2
|
+
export interface CredentialClient {
|
|
3
|
+
readonly sessionDid: string;
|
|
4
|
+
readonly credentialHolderDid: string;
|
|
5
|
+
readonly credentialHolderKid: string;
|
|
6
|
+
session(): ClientSession | undefined;
|
|
7
|
+
signSessionBytes(bytes: Uint8Array): Promise<Uint8Array>;
|
|
8
|
+
autoSignCredentialBytes?(bytes: Uint8Array): Promise<Uint8Array | undefined>;
|
|
9
|
+
approveCredentialBytes?(bytes: Uint8Array): Promise<Uint8Array>;
|
|
10
|
+
ensureOwnedSpaceHosted(name: string): Promise<string>;
|
|
11
|
+
credentialSpaceOwnerDid(spaceId: string): string;
|
|
12
|
+
kvForSpace(spaceId: string): IKVService;
|
|
13
|
+
}
|
|
14
|
+
export interface CredentialSigningAdapter {
|
|
15
|
+
/** Return undefined when the existing exact-request auto-sign policy does not apply. */
|
|
16
|
+
readonly autoSign?: (binding: CredentialHolderBinding, bytes: Uint8Array, signal?: AbortSignal) => Promise<Uint8Array | undefined>;
|
|
17
|
+
/** Invoke the normal OpenKey approval surface. */
|
|
18
|
+
readonly requestApproval?: (binding: CredentialHolderBinding, bytes: Uint8Array, signal?: AbortSignal) => Promise<Uint8Array>;
|
|
19
|
+
}
|
|
20
|
+
export type PrimitiveStepResult = Readonly<Record<string, string | boolean>>;
|
|
21
|
+
export type PrimitiveStepHandler = (input: {
|
|
22
|
+
readonly descriptor: CredentialFlowDescriptor;
|
|
23
|
+
readonly requirement: CredentialRequirement;
|
|
24
|
+
readonly stepId: string;
|
|
25
|
+
readonly constraints: Readonly<Record<string, unknown>>;
|
|
26
|
+
readonly signal?: AbortSignal;
|
|
27
|
+
}) => Promise<PrimitiveStepResult>;
|
|
28
|
+
export interface CredentialInteractionAdapter {
|
|
29
|
+
readonly kind: "popup" | "redirect" | "headless";
|
|
30
|
+
start(input: {
|
|
31
|
+
readonly interaction: CredentialFlowDescriptor["interaction"];
|
|
32
|
+
readonly locator: string;
|
|
33
|
+
readonly signal?: AbortSignal;
|
|
34
|
+
}): Promise<{
|
|
35
|
+
readonly wake: () => Promise<void>;
|
|
36
|
+
readonly close: () => void;
|
|
37
|
+
readonly closed: () => boolean;
|
|
38
|
+
}>;
|
|
39
|
+
}
|
|
40
|
+
export interface CredentialRedirectResumeState {
|
|
41
|
+
readonly type: "TinyCloudCredentialRedirectResume";
|
|
42
|
+
readonly version: 1;
|
|
43
|
+
readonly requestId: string;
|
|
44
|
+
readonly locator: string;
|
|
45
|
+
readonly verifier: string;
|
|
46
|
+
readonly expiresAt: string;
|
|
47
|
+
readonly correlationId: string;
|
|
48
|
+
readonly holderDid: string;
|
|
49
|
+
readonly descriptorDigest: string;
|
|
50
|
+
readonly requirementDigest: string;
|
|
51
|
+
readonly openerOrigin: string;
|
|
52
|
+
}
|
|
53
|
+
export interface CredentialRedirectStore {
|
|
54
|
+
load(): Promise<CredentialRedirectResumeState | undefined>;
|
|
55
|
+
save(state: CredentialRedirectResumeState): Promise<void>;
|
|
56
|
+
clear(): Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
export interface CredentialRequestState {
|
|
59
|
+
readonly type: "OpenCredentialsAcquisitionState";
|
|
60
|
+
readonly version: 1;
|
|
61
|
+
readonly requestId: string;
|
|
62
|
+
readonly transitionId: string;
|
|
63
|
+
readonly state: "pending" | "ready_to_issue" | "issued" | "complete" | "expired" | "canceled" | "issuer_unready";
|
|
64
|
+
readonly nextStep?: {
|
|
65
|
+
readonly id: string;
|
|
66
|
+
readonly type: "collect_input" | "mailbox_otp" | "holder_signature";
|
|
67
|
+
readonly version: 1;
|
|
68
|
+
readonly constraints: Readonly<Record<string, unknown>>;
|
|
69
|
+
};
|
|
70
|
+
readonly retryAfterMs?: number;
|
|
71
|
+
readonly correlationId: string;
|
|
72
|
+
}
|
|
73
|
+
export interface CredentialAcquisitionTransport {
|
|
74
|
+
create(input: {
|
|
75
|
+
readonly descriptor: CredentialFlowDescriptor;
|
|
76
|
+
readonly descriptorDigest: string;
|
|
77
|
+
readonly requirement: CredentialRequirement;
|
|
78
|
+
readonly requirementDigest: string;
|
|
79
|
+
readonly holderDid: string;
|
|
80
|
+
readonly openerOrigin: string;
|
|
81
|
+
readonly completionVerifierChallenge: string;
|
|
82
|
+
readonly signal?: AbortSignal;
|
|
83
|
+
}): Promise<{
|
|
84
|
+
readonly requestId: string;
|
|
85
|
+
readonly locator: string;
|
|
86
|
+
readonly expiresAt: string;
|
|
87
|
+
readonly correlationId: string;
|
|
88
|
+
}>;
|
|
89
|
+
state(requestId: string, verifier: string, signal?: AbortSignal): Promise<CredentialRequestState>;
|
|
90
|
+
beginStep(requestId: string, verifier: string, stepId: "collect_input" | "mailbox_otp", signal?: AbortSignal): Promise<void>;
|
|
91
|
+
submitStep(requestId: string, verifier: string, stepId: string, proof: PrimitiveStepResult, signal?: AbortSignal): Promise<void>;
|
|
92
|
+
holderBinding(requestId: string, verifier: string, signal?: AbortSignal): Promise<CredentialHolderBinding>;
|
|
93
|
+
submitHolderSignature(requestId: string, verifier: string, signature: string, signal?: AbortSignal): Promise<void>;
|
|
94
|
+
issue(requestId: string, verifier: string, signal?: AbortSignal): Promise<void>;
|
|
95
|
+
result(requestId: string, verifier: string, signal?: AbortSignal): Promise<IssuedCredentialEnvelope>;
|
|
96
|
+
issuerMetadata(signal?: AbortSignal): Promise<CredentialIssuerMetadata>;
|
|
97
|
+
checkStatus(status: IssuedCredentialEnvelope["status"], signal?: AbortSignal): Promise<boolean>;
|
|
98
|
+
}
|
|
99
|
+
export interface CredentialsOperationOptions {
|
|
100
|
+
readonly descriptor?: CredentialFlowDescriptor;
|
|
101
|
+
readonly discoveryUrl?: string;
|
|
102
|
+
readonly fetch?: typeof fetch;
|
|
103
|
+
readonly signal?: AbortSignal;
|
|
104
|
+
readonly timeoutMs?: number;
|
|
105
|
+
readonly onProgress?: (event: CredentialProgressEvent) => void;
|
|
106
|
+
readonly now?: () => Date;
|
|
107
|
+
}
|
|
108
|
+
export interface CredentialsAcquireOptions extends CredentialsOperationOptions {
|
|
109
|
+
readonly interaction?: "popup" | "redirect" | "headless";
|
|
110
|
+
readonly browser?: CredentialInteractionAdapter;
|
|
111
|
+
readonly transport?: CredentialAcquisitionTransport;
|
|
112
|
+
readonly signing?: CredentialSigningAdapter;
|
|
113
|
+
readonly stepHandlers?: Partial<Record<"collect_input" | "mailbox_otp", PrimitiveStepHandler>>;
|
|
114
|
+
readonly openerOrigin?: string;
|
|
115
|
+
/** Same-origin, request-scoped persistence used to resume a full-page redirect. */
|
|
116
|
+
readonly redirectStore?: CredentialRedirectStore;
|
|
117
|
+
}
|
|
118
|
+
export interface CredentialsEnsureOptions extends CredentialsAcquireOptions {
|
|
119
|
+
}
|
|
120
|
+
export interface CredentialsEnsureResult {
|
|
121
|
+
readonly status: "reused" | "acquired";
|
|
122
|
+
readonly credential: VerifiedCredential;
|
|
123
|
+
readonly record: StoredCredentialRecord;
|
|
124
|
+
readonly receipt?: CredentialStorageReceipt;
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=types.d.ts.map
|