@safetech/inheriti-client-sdk 1.17.1 → 1.17.3
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 +9 -0
- package/dist/browser.d.ts +23 -0
- package/dist/browser.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/inheriti-client-sdk.umd.js +141 -83
- package/dist/node.d.ts +22 -1
- package/dist/node.js +1 -1
- package/dist/sdk-types.d.ts +906 -16
- package/dist/src/auth/inheriti-client-provider.d.ts +1 -1
- package/dist/src/elements/core-plan-material-builder.d.ts +40 -0
- package/dist/src/elements/elements-api-port.d.ts +116 -1
- package/dist/src/elements/elements-client.d.ts +104 -4
- package/dist/src/elements/guided-plan-creator.d.ts +47 -0
- package/dist/src/elements/http-elements-api-port.d.ts +18 -1
- package/dist/src/elements/index.d.ts +15 -1
- package/dist/src/elements/key-vault.d.ts +14 -6
- package/dist/src/elements/master-key.d.ts +58 -0
- package/dist/src/elements/node-plan-material-reconstructor.d.ts +1 -1
- package/dist/src/elements/plan-material-reconstructor.d.ts +5 -1
- package/dist/src/elements/plan-operation-codec.d.ts +4 -0
- package/dist/src/elements/plan-operations.d.ts +160 -0
- package/dist/src/elements/polling-shared-plan-event-listener.d.ts +29 -0
- package/dist/src/elements/relay-master-key-source.d.ts +38 -0
- package/dist/src/elements/reveal-session-operations.d.ts +13 -0
- package/dist/src/elements/scoped-reveal.d.ts +44 -0
- package/dist/src/elements/unwrap-dek.d.ts +7 -0
- package/dist/src/operator-auth/defaults.d.ts +9 -0
- package/dist/src/operator-auth/errors.d.ts +11 -0
- package/dist/src/operator-auth/http-operator-auth-transport.d.ts +16 -0
- package/dist/src/operator-auth/index.d.ts +7 -0
- package/dist/src/operator-auth/operator-auth-client.d.ts +35 -0
- package/dist/src/operator-auth/operator-session-controller.d.ts +10 -0
- package/dist/src/operator-auth/ports.d.ts +53 -0
- package/dist/src/operator-auth/types.d.ts +77 -0
- package/dist/test/index.js +1 -1
- package/docs/docs.json +18331 -0
- package/docs/elements-shared-mode.md +28 -0
- package/docs/operator-auth.md +76 -0
- package/docs/plan-operations.md +41 -0
- package/index.ts +1 -0
- package/node.ts +36 -3
- package/package.json +14 -3
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
export declare const CANONICAL_PLAN_ASSET_TYPES: readonly ["PLAIN-TEXT", "USER-PSWD", "RECOVERY-CODE", "PIN-CODE", "API-KEY", "PRIVATE-KEY", "SEED-PHRASE", "PAYMENT-DEBIT-CARD", "PAYMENT-CREDIT-CARD", "DOCUMENT", "IMAGE", "VIDEO"];
|
|
2
|
+
export type CanonicalPlanAssetType = (typeof CANONICAL_PLAN_ASSET_TYPES)[number];
|
|
3
|
+
export declare const CANONICAL_STRUCTURED_ASSET_FIELDS: Readonly<Record<Exclude<CanonicalPlanAssetType, 'DOCUMENT' | 'IMAGE' | 'VIDEO'>, readonly string[]>>;
|
|
4
|
+
export type CompatibleValue<T extends string> = T | {
|
|
5
|
+
readonly kind: 'UNKNOWN';
|
|
6
|
+
readonly raw: string;
|
|
7
|
+
};
|
|
8
|
+
export type PlanStatus = CompatibleValue<'DRAFT' | 'ACTIVE' | 'CONFIGURED' | 'ARCHIVED'>;
|
|
9
|
+
export type PlanGovernanceMode = CompatibleValue<'DIRECT' | 'GOVERNED'>;
|
|
10
|
+
export type PlanParticipantRelationship = 'OWNER' | 'MERGER' | 'MODERATOR' | 'CUSTODIAN' | 'ALLOW' | 'DENY';
|
|
11
|
+
export interface PlanAssetSummary {
|
|
12
|
+
count: number;
|
|
13
|
+
types: CompatibleValue<CanonicalPlanAssetType>[];
|
|
14
|
+
}
|
|
15
|
+
export interface PlanSummary {
|
|
16
|
+
id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
status: PlanStatus;
|
|
20
|
+
createdAt: string;
|
|
21
|
+
configuredAt?: string;
|
|
22
|
+
assetSummary: PlanAssetSummary;
|
|
23
|
+
governance: {
|
|
24
|
+
mode: PlanGovernanceMode;
|
|
25
|
+
minimumApprovals: number;
|
|
26
|
+
};
|
|
27
|
+
participantSummary: {
|
|
28
|
+
owners: number;
|
|
29
|
+
mergers: number;
|
|
30
|
+
moderators: number;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export interface PlanPage {
|
|
34
|
+
items: PlanSummary[];
|
|
35
|
+
nextCursor: string | null;
|
|
36
|
+
}
|
|
37
|
+
export interface ListPlansInput {
|
|
38
|
+
cursor?: string;
|
|
39
|
+
limit?: number;
|
|
40
|
+
status?: readonly string[];
|
|
41
|
+
assetType?: CanonicalPlanAssetType;
|
|
42
|
+
namePrefix?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface PlanDetail extends PlanSummary {
|
|
45
|
+
assets: Array<{
|
|
46
|
+
id: string;
|
|
47
|
+
/** Developer-defined stable address. Older plans may not have one and fall back to `id`. */
|
|
48
|
+
code?: string;
|
|
49
|
+
type: CompatibleValue<CanonicalPlanAssetType>;
|
|
50
|
+
name: string;
|
|
51
|
+
isBinary: boolean;
|
|
52
|
+
fieldNames: string[];
|
|
53
|
+
matchOrigins?: string[];
|
|
54
|
+
}>;
|
|
55
|
+
participants: Array<{
|
|
56
|
+
id: string;
|
|
57
|
+
displayName: string;
|
|
58
|
+
relationships: CompatibleValue<PlanParticipantRelationship>[];
|
|
59
|
+
lifecycle: CompatibleValue<'ACTIVE' | 'REVOKED'>;
|
|
60
|
+
}>;
|
|
61
|
+
revealPolicy: {
|
|
62
|
+
masterKeyRelease: CompatibleValue<'REQUIRED'>;
|
|
63
|
+
custodian: CompatibleValue<'FORCE' | 'BYPASS'>;
|
|
64
|
+
};
|
|
65
|
+
source: {
|
|
66
|
+
kind: 'NATIVE';
|
|
67
|
+
} | {
|
|
68
|
+
kind: 'BRIDGED';
|
|
69
|
+
system: CompatibleValue<'INHERITI_BUSINESS'>;
|
|
70
|
+
status: CompatibleValue<'IN_SYNC' | 'RECONCILIATION_REQUIRED'>;
|
|
71
|
+
} | {
|
|
72
|
+
kind: 'UNKNOWN';
|
|
73
|
+
raw: string;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export interface IntegrationPlanAssetDeclaration {
|
|
77
|
+
clientAssetRef: string;
|
|
78
|
+
type: CanonicalPlanAssetType;
|
|
79
|
+
name: string;
|
|
80
|
+
fieldNames?: readonly string[];
|
|
81
|
+
isBinary: boolean;
|
|
82
|
+
fileName?: string;
|
|
83
|
+
mimeType?: string;
|
|
84
|
+
size?: number;
|
|
85
|
+
}
|
|
86
|
+
export interface NativePlanParticipant {
|
|
87
|
+
clientParticipantRef: string;
|
|
88
|
+
/** Routing only. It is not identity or evidence of a SafeID/SafeKey account. */
|
|
89
|
+
routingEmail: string;
|
|
90
|
+
displayName: string;
|
|
91
|
+
relationships: readonly PlanParticipantRelationship[];
|
|
92
|
+
}
|
|
93
|
+
export interface StartPlanCreationInput {
|
|
94
|
+
idempotencyKey: string;
|
|
95
|
+
name: string;
|
|
96
|
+
description?: string;
|
|
97
|
+
assets: readonly IntegrationPlanAssetDeclaration[];
|
|
98
|
+
participants: readonly NativePlanParticipant[];
|
|
99
|
+
policy?: {
|
|
100
|
+
governance?: 'DIRECT' | 'GOVERNED';
|
|
101
|
+
minimumApprovals?: number;
|
|
102
|
+
masterKeyRelease?: 'REQUIRED';
|
|
103
|
+
custodian?: 'FORCE' | 'BYPASS';
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
export declare const PLAN_CREATION_SERVER_STAGES: readonly ["VALIDATED", "PLAN_CREATED", "PARTICIPANTS_PERSISTED", "STORAGE_PREPARED", "AWAITING_ENCRYPTED_MATERIAL", "VALIDATOR_SHARES_DISTRIBUTED", "CONFIGURED", "COMPLETED"];
|
|
107
|
+
export type PlanCreationServerStage = (typeof PLAN_CREATION_SERVER_STAGES)[number];
|
|
108
|
+
export type PlanCreationOutcome = 'IN_PROGRESS' | 'COMPLETED' | 'CANCELED' | 'FAILED_RETRYABLE' | 'FAILED_TERMINAL' | 'RECONCILIATION_REQUIRED';
|
|
109
|
+
export interface PlanCreationProgress {
|
|
110
|
+
operationId: string;
|
|
111
|
+
stage: CompatibleValue<PlanCreationServerStage>;
|
|
112
|
+
outcome: CompatibleValue<PlanCreationOutcome>;
|
|
113
|
+
planId?: string;
|
|
114
|
+
lastErrorCode?: string;
|
|
115
|
+
participants?: Array<{
|
|
116
|
+
clientParticipantRef: string;
|
|
117
|
+
planParticipantId: string;
|
|
118
|
+
relationships: PlanParticipantRelationship[];
|
|
119
|
+
}>;
|
|
120
|
+
}
|
|
121
|
+
export interface EncryptedPlanMaterial {
|
|
122
|
+
protectionProtocol?: 'SSDP_PLUS_V1' | 'SSDP_PLUS_V2';
|
|
123
|
+
validatorShares?: readonly EncryptedPlanShard[];
|
|
124
|
+
dataShards: readonly EncryptedPlanShard[];
|
|
125
|
+
backupShards: readonly EncryptedPlanShard[];
|
|
126
|
+
encryptedKey?: string;
|
|
127
|
+
assetsMetadata?: Readonly<Record<string, {
|
|
128
|
+
type: CanonicalPlanAssetType;
|
|
129
|
+
meta: {
|
|
130
|
+
name: string;
|
|
131
|
+
notes?: string;
|
|
132
|
+
};
|
|
133
|
+
}>>;
|
|
134
|
+
custodianShard?: {
|
|
135
|
+
keyShard: EncryptedPlanShard;
|
|
136
|
+
dataShard: EncryptedPlanShard;
|
|
137
|
+
};
|
|
138
|
+
operation?: 'DRAFT' | 'FINALIZE';
|
|
139
|
+
}
|
|
140
|
+
export interface EncryptedPlanShard {
|
|
141
|
+
id: string;
|
|
142
|
+
data?: string;
|
|
143
|
+
}
|
|
144
|
+
export type GuidedCreateLocalStage = 'VALIDATING_ASSETS' | 'ENCRYPTING' | 'GENERATING_SHARES';
|
|
145
|
+
export interface GuidedCreateCheckpoint {
|
|
146
|
+
idempotencyKey: string;
|
|
147
|
+
operationId: string;
|
|
148
|
+
declarationHash: string;
|
|
149
|
+
serverStage: CompatibleValue<PlanCreationServerStage>;
|
|
150
|
+
}
|
|
151
|
+
export declare class InvalidPlanDeclaration extends Error {
|
|
152
|
+
readonly code: string;
|
|
153
|
+
constructor(code: string);
|
|
154
|
+
}
|
|
155
|
+
export declare class InvalidPlanMaterial extends Error {
|
|
156
|
+
readonly code: string;
|
|
157
|
+
constructor(code: string);
|
|
158
|
+
}
|
|
159
|
+
export declare function validatePlanCreationMaterial(material: EncryptedPlanMaterial): void;
|
|
160
|
+
export declare function validatePlanCreationInput(input: StartPlanCreationInput): void;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ProcessReconciliationOwnership, ProcessRuntimeEnvironment, SharedPlanEventHandlers, SharedPlanEventListener } from '@safetech/inheriti-core-sdk/shared-configuration';
|
|
2
|
+
import type { ElementsApiPort } from './elements-api-port';
|
|
3
|
+
/** Elements adapter for Core's transport-neutral event port. Scheduling remains owned by Core's mature loop. */
|
|
4
|
+
export declare class PollingSharedPlanEventListener implements SharedPlanEventListener {
|
|
5
|
+
private readonly api;
|
|
6
|
+
private readonly subscriptions;
|
|
7
|
+
private readonly loop;
|
|
8
|
+
constructor(api: ElementsApiPort, environment?: ProcessRuntimeEnvironment, ownership?: ProcessReconciliationOwnership, random?: () => number);
|
|
9
|
+
refreshConnection(): void;
|
|
10
|
+
subscribe(processId: string, handlers: SharedPlanEventHandlers): void;
|
|
11
|
+
unsubscribe(processId: string): void;
|
|
12
|
+
}
|
|
13
|
+
/** Cross-host runtime: browsers regain work on online/visibility events; Node uses timer-only recovery. */
|
|
14
|
+
export declare class HostProcessRuntimeEnvironment implements ProcessRuntimeEnvironment {
|
|
15
|
+
visibility(): 'visible' | 'hidden';
|
|
16
|
+
isOnline(): boolean;
|
|
17
|
+
now(): number;
|
|
18
|
+
schedule(callback: () => void, delayMs: number): () => void;
|
|
19
|
+
onRecovery(callback: () => void): () => void;
|
|
20
|
+
}
|
|
21
|
+
/** One host process owns its own polling; Core's loop still enforces one active lease per subscription. */
|
|
22
|
+
export declare class LocalProcessReconciliationOwnership implements ProcessReconciliationOwnership {
|
|
23
|
+
join(_processId: string, handlers: Parameters<ProcessReconciliationOwnership['join']>[1]): {
|
|
24
|
+
isOwner: () => boolean;
|
|
25
|
+
requestReconciliation: () => void;
|
|
26
|
+
publishReconciled: () => undefined;
|
|
27
|
+
leave: () => void;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { MasterKeySource } from '@safetech/inheriti-core-sdk';
|
|
2
|
+
export interface MasterKeyRelayPort {
|
|
3
|
+
startRelaySession(clientPublicKey: string): Promise<{
|
|
4
|
+
sessionId: string;
|
|
5
|
+
expiresAt: string | Date;
|
|
6
|
+
}>;
|
|
7
|
+
readRelaySession(sessionId: string): Promise<{
|
|
8
|
+
status: 'PENDING' | 'DELIVERED' | 'EXPIRED';
|
|
9
|
+
sealedMasterKey?: string;
|
|
10
|
+
}>;
|
|
11
|
+
}
|
|
12
|
+
export declare class MasterKeyRelayTimedOut extends Error {
|
|
13
|
+
readonly sessionId: string;
|
|
14
|
+
constructor(sessionId: string);
|
|
15
|
+
}
|
|
16
|
+
export declare class MasterKeyRelayExpired extends Error {
|
|
17
|
+
readonly sessionId: string;
|
|
18
|
+
constructor(sessionId: string);
|
|
19
|
+
}
|
|
20
|
+
export interface RelayMasterKeySourceOptions {
|
|
21
|
+
api: MasterKeyRelayPort;
|
|
22
|
+
/** How long to wait for the device before giving up. Defaults to the session lifetime. */
|
|
23
|
+
timeoutMs?: number;
|
|
24
|
+
pollIntervalMs?: number;
|
|
25
|
+
sleep?: (ms: number) => Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Obtains the master key from the device holding it.
|
|
29
|
+
*
|
|
30
|
+
* Elements has no websocket layer, so the host polls. The key is sealed to an ephemeral
|
|
31
|
+
* public key generated here and never leaves this process in the clear: the private half
|
|
32
|
+
* is not persisted, so a relayed key cannot be replayed from stored state.
|
|
33
|
+
*/
|
|
34
|
+
export declare class RelayMasterKeySource implements MasterKeySource {
|
|
35
|
+
private readonly options;
|
|
36
|
+
constructor(options: RelayMasterKeySourceOptions);
|
|
37
|
+
resolve(): Promise<string>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AuthorizeRevealActionInput, ElementsApiPort, RevealAction } from './elements-api-port';
|
|
2
|
+
export declare function authorizeActionWhenOpen(api: ElementsApiPort, revealId: string, input: AuthorizeRevealActionInput): Promise<RevealAction>;
|
|
3
|
+
/**
|
|
4
|
+
* Resolves the plan key before the material is released, where the caller's credential can.
|
|
5
|
+
*
|
|
6
|
+
* The key reference lives on `/shared-plans`, which takes an Application or Account credential. A
|
|
7
|
+
* host drives a reveal with the *operator* credential it gets at sign-in, and that route refuses it —
|
|
8
|
+
* so requiring this step made a reveal impossible from any integration host. It stays a fail-fast for
|
|
9
|
+
* the callers that can make the call, and is skipped for the ones that cannot: the released material
|
|
10
|
+
* carries its own key reference, so reconstruction resolves the key from that either way. Any other
|
|
11
|
+
* failure is still the caller's to see.
|
|
12
|
+
*/
|
|
13
|
+
export declare function releaseMaterialAfterKeyResolution(api: ElementsApiPort, revealId: string, materialVersion: string, prepareReveal: (planId: string) => Promise<unknown>): Promise<unknown>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type ElementsClient from './elements-client';
|
|
2
|
+
import type { RevealActionType, RevealCloseReason, RevealMode, RevealSession } from './elements-api-port';
|
|
3
|
+
export type AssetFieldSelector = string | {
|
|
4
|
+
asset: string;
|
|
5
|
+
field: string;
|
|
6
|
+
};
|
|
7
|
+
export interface RevealFieldOptions {
|
|
8
|
+
action?: Exclude<RevealActionType, 'EXPORT_ASSET'>;
|
|
9
|
+
origin?: string;
|
|
10
|
+
idempotencyKey?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface OpenRevealOptions {
|
|
13
|
+
mode?: RevealMode;
|
|
14
|
+
idempotencyKey?: string;
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
pollIntervalMs?: number;
|
|
17
|
+
onSession?: (session: RevealSession) => void;
|
|
18
|
+
}
|
|
19
|
+
export interface RevealHandle {
|
|
20
|
+
readonly session: RevealSession;
|
|
21
|
+
readonly material: Uint8Array;
|
|
22
|
+
readonly closed: boolean;
|
|
23
|
+
field<TValue = unknown>(selector: AssetFieldSelector, options?: RevealFieldOptions): Promise<TValue>;
|
|
24
|
+
close(reason?: RevealCloseReason): Promise<void>;
|
|
25
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
export declare class RevealHandleClosed extends Error {
|
|
28
|
+
readonly code = "reveal_handle_closed";
|
|
29
|
+
constructor();
|
|
30
|
+
}
|
|
31
|
+
export declare class RevealFieldAccessError extends Error {
|
|
32
|
+
readonly code: 'asset_selector_invalid' | 'asset_not_found' | 'asset_field_not_found' | 'action_not_allowed' | 'asset_decoder_required' | 'asset_value_invalid';
|
|
33
|
+
constructor(code: 'asset_selector_invalid' | 'asset_not_found' | 'asset_field_not_found' | 'action_not_allowed' | 'asset_decoder_required' | 'asset_value_invalid');
|
|
34
|
+
}
|
|
35
|
+
export declare function openScopedReveal(client: ElementsClient, planId: string, options?: OpenRevealOptions): Promise<RevealHandle>;
|
|
36
|
+
export declare class RevealAuthorizationEnded extends Error {
|
|
37
|
+
readonly stage: RevealSession['stage'];
|
|
38
|
+
readonly code = "reveal_authorization_ended";
|
|
39
|
+
constructor(stage: RevealSession['stage']);
|
|
40
|
+
}
|
|
41
|
+
export declare function parseAssetFieldSelector(selector: AssetFieldSelector): {
|
|
42
|
+
asset: string;
|
|
43
|
+
field: string;
|
|
44
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opens a plan key that was sealed under a master key.
|
|
3
|
+
*
|
|
4
|
+
* The wrap is AES-GCM with a 12-byte prefixed IV, matching the Core SDK's
|
|
5
|
+
* `wrapKeyWithMasterKeyThenRsa`; the platform only ever removed the outer RSA layer.
|
|
6
|
+
*/
|
|
7
|
+
export declare function unwrapDekWithMasterKey(wrappedDekBase64: string, masterKeyHex?: string): Promise<string>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { OAuthClock, OAuthCrypto } from './ports';
|
|
2
|
+
export declare class WebOAuthCrypto implements OAuthCrypto {
|
|
3
|
+
randomUrlSafe(byteLength: number): string;
|
|
4
|
+
sha256UrlSafe(value: string): Promise<string>;
|
|
5
|
+
}
|
|
6
|
+
export declare class SystemOAuthClock implements OAuthClock {
|
|
7
|
+
now(): number;
|
|
8
|
+
sleep(milliseconds: number, signal?: AbortSignal): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class OperatorAuthError extends Error {
|
|
2
|
+
readonly code: string;
|
|
3
|
+
constructor(code: string, message?: string);
|
|
4
|
+
}
|
|
5
|
+
export declare class OperatorReauthenticationRequired extends OperatorAuthError {
|
|
6
|
+
constructor(message?: string);
|
|
7
|
+
}
|
|
8
|
+
export declare class OAuthProtocolError extends OperatorAuthError {
|
|
9
|
+
constructor(code: string, message?: string);
|
|
10
|
+
}
|
|
11
|
+
export declare function oauthErrorCode(error: unknown): string | undefined;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { OperatorAuthTransport } from './ports';
|
|
2
|
+
import type { DeviceAuthorization, OAuthTokenResponse, OidcDiscoveryDocument } from './types';
|
|
3
|
+
export type OAuthHttpTransport = (input: URL | RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
4
|
+
/** Standard public-client OAuth/OIDC transport. Confidential BFFs should inject their own transport. */
|
|
5
|
+
export declare class HttpOperatorAuthTransport implements OperatorAuthTransport {
|
|
6
|
+
private readonly http;
|
|
7
|
+
constructor(http?: OAuthHttpTransport);
|
|
8
|
+
discover(issuer: string): Promise<OidcDiscoveryDocument>;
|
|
9
|
+
exchangeAuthorizationCode(input: Parameters<OperatorAuthTransport['exchangeAuthorizationCode']>[0]): Promise<OAuthTokenResponse>;
|
|
10
|
+
startDeviceAuthorization(input: Parameters<OperatorAuthTransport['startDeviceAuthorization']>[0]): Promise<DeviceAuthorization>;
|
|
11
|
+
pollDeviceToken(input: Parameters<OperatorAuthTransport['pollDeviceToken']>[0]): Promise<OAuthTokenResponse>;
|
|
12
|
+
refresh(input: Parameters<OperatorAuthTransport['refresh']>[0]): Promise<OAuthTokenResponse>;
|
|
13
|
+
private token;
|
|
14
|
+
private form;
|
|
15
|
+
private json;
|
|
16
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { OAuthClock, OAuthCrypto, OAuthTransactionStore, OperatorAuthTransport, OperatorSessionStore, OperatorTokenValidator } from './ports';
|
|
2
|
+
import type { DeviceTransaction, OperatorAuthConfiguration, OperatorSession } from './types';
|
|
3
|
+
export interface OperatorAuthClientOptions {
|
|
4
|
+
configuration: OperatorAuthConfiguration;
|
|
5
|
+
transport: OperatorAuthTransport;
|
|
6
|
+
tokenValidator: OperatorTokenValidator;
|
|
7
|
+
sessions: OperatorSessionStore;
|
|
8
|
+
transactions: OAuthTransactionStore;
|
|
9
|
+
crypto?: OAuthCrypto;
|
|
10
|
+
clock?: OAuthClock;
|
|
11
|
+
}
|
|
12
|
+
export declare class OperatorAuthClient {
|
|
13
|
+
private readonly options;
|
|
14
|
+
private readonly crypto;
|
|
15
|
+
private readonly clock;
|
|
16
|
+
private discovery?;
|
|
17
|
+
private refreshFlight?;
|
|
18
|
+
constructor(options: OperatorAuthClientOptions);
|
|
19
|
+
beginAuthorizationCode(): Promise<{
|
|
20
|
+
authorizationUrl: string;
|
|
21
|
+
expiresAt: number;
|
|
22
|
+
}>;
|
|
23
|
+
completeAuthorizationCode(callbackUrl: string): Promise<OperatorSession>;
|
|
24
|
+
beginDeviceAuthorization(): Promise<DeviceTransaction>;
|
|
25
|
+
pollDeviceAuthorization(signal?: AbortSignal): Promise<OperatorSession>;
|
|
26
|
+
getAccessToken(): Promise<string | undefined>;
|
|
27
|
+
refresh(): Promise<OperatorSession>;
|
|
28
|
+
clear(): Promise<void>;
|
|
29
|
+
private performRefresh;
|
|
30
|
+
private getDiscovery;
|
|
31
|
+
private transactionKey;
|
|
32
|
+
private acceptTokens;
|
|
33
|
+
private assertPrincipal;
|
|
34
|
+
private assertIdentity;
|
|
35
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { OperatorSessionControlPort, OperatorSessionStore } from './ports';
|
|
2
|
+
import type { OperatorSessionSummary } from './types';
|
|
3
|
+
export declare class OperatorSessionController {
|
|
4
|
+
private readonly control;
|
|
5
|
+
private readonly local;
|
|
6
|
+
constructor(control: OperatorSessionControlPort, local: OperatorSessionStore);
|
|
7
|
+
list(): Promise<readonly OperatorSessionSummary[]>;
|
|
8
|
+
revoke(sessionId: string): Promise<void>;
|
|
9
|
+
logout(): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { DeviceAuthorization, OAuthTokenResponse, OAuthTransaction, OidcDiscoveryDocument, OperatorSession, OperatorSessionSummary, ValidatedOperatorToken } from './types';
|
|
2
|
+
export interface OperatorAuthTransport {
|
|
3
|
+
discover(issuer: string): Promise<OidcDiscoveryDocument>;
|
|
4
|
+
exchangeAuthorizationCode(input: {
|
|
5
|
+
tokenEndpoint: string;
|
|
6
|
+
clientId: string;
|
|
7
|
+
code: string;
|
|
8
|
+
codeVerifier: string;
|
|
9
|
+
redirectUri: string;
|
|
10
|
+
}): Promise<OAuthTokenResponse>;
|
|
11
|
+
startDeviceAuthorization(input: {
|
|
12
|
+
endpoint: string;
|
|
13
|
+
clientId: string;
|
|
14
|
+
scopes: readonly string[];
|
|
15
|
+
}): Promise<DeviceAuthorization>;
|
|
16
|
+
pollDeviceToken(input: {
|
|
17
|
+
tokenEndpoint: string;
|
|
18
|
+
clientId: string;
|
|
19
|
+
deviceCode: string;
|
|
20
|
+
}): Promise<OAuthTokenResponse>;
|
|
21
|
+
refresh(input: {
|
|
22
|
+
tokenEndpoint: string;
|
|
23
|
+
clientId: string;
|
|
24
|
+
refreshToken: string;
|
|
25
|
+
}): Promise<OAuthTokenResponse>;
|
|
26
|
+
}
|
|
27
|
+
export interface OperatorTokenValidator {
|
|
28
|
+
validateAccessToken(accessToken: string): Promise<ValidatedOperatorToken>;
|
|
29
|
+
validateIdToken?(idToken: string): Promise<ValidatedOperatorToken>;
|
|
30
|
+
}
|
|
31
|
+
export interface OperatorSessionStore {
|
|
32
|
+
load(): Promise<OperatorSession | undefined>;
|
|
33
|
+
save(session: OperatorSession): Promise<void>;
|
|
34
|
+
clear(): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
export interface OAuthTransactionStore {
|
|
37
|
+
load(key: string): Promise<OAuthTransaction | undefined>;
|
|
38
|
+
save(key: string, transaction: OAuthTransaction): Promise<void>;
|
|
39
|
+
remove(key: string): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
export interface OAuthClock {
|
|
42
|
+
now(): number;
|
|
43
|
+
sleep(milliseconds: number, signal?: AbortSignal): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
export interface OAuthCrypto {
|
|
46
|
+
randomUrlSafe(byteLength: number): string;
|
|
47
|
+
sha256UrlSafe(value: string): Promise<string>;
|
|
48
|
+
}
|
|
49
|
+
export interface OperatorSessionControlPort {
|
|
50
|
+
list(): Promise<readonly OperatorSessionSummary[]>;
|
|
51
|
+
revoke(sessionId: string): Promise<void>;
|
|
52
|
+
logout(sessionId: string): Promise<void>;
|
|
53
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export type ElementsEnvironment = 'TEST' | 'LIVE';
|
|
2
|
+
export interface OidcDiscoveryDocument {
|
|
3
|
+
issuer: string;
|
|
4
|
+
authorizationEndpoint: string;
|
|
5
|
+
tokenEndpoint: string;
|
|
6
|
+
deviceAuthorizationEndpoint?: string;
|
|
7
|
+
endSessionEndpoint?: string;
|
|
8
|
+
revocationEndpoint?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface OperatorAuthConfiguration {
|
|
11
|
+
issuer: string;
|
|
12
|
+
clientId: string;
|
|
13
|
+
audience: string;
|
|
14
|
+
environment: ElementsEnvironment;
|
|
15
|
+
redirectUri: string;
|
|
16
|
+
scopes: readonly string[];
|
|
17
|
+
}
|
|
18
|
+
export interface OAuthTokenResponse {
|
|
19
|
+
accessToken: string;
|
|
20
|
+
refreshToken?: string;
|
|
21
|
+
idToken?: string;
|
|
22
|
+
tokenType: string;
|
|
23
|
+
expiresInSeconds: number;
|
|
24
|
+
refreshExpiresInSeconds?: number;
|
|
25
|
+
scope?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface ValidatedOperatorToken {
|
|
28
|
+
issuer: string;
|
|
29
|
+
audience: string | readonly string[];
|
|
30
|
+
authorizedParty: string;
|
|
31
|
+
environment: ElementsEnvironment;
|
|
32
|
+
subject: string;
|
|
33
|
+
sessionId: string;
|
|
34
|
+
tokenId: string;
|
|
35
|
+
scopes: readonly string[];
|
|
36
|
+
nonce?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface OperatorSession {
|
|
39
|
+
accessToken: string;
|
|
40
|
+
refreshToken?: string;
|
|
41
|
+
idToken?: string;
|
|
42
|
+
tokenType: 'Bearer';
|
|
43
|
+
expiresAt: number;
|
|
44
|
+
refreshExpiresAt?: number;
|
|
45
|
+
principal: ValidatedOperatorToken;
|
|
46
|
+
}
|
|
47
|
+
export interface AuthorizationTransaction {
|
|
48
|
+
kind: 'authorization-code';
|
|
49
|
+
state: string;
|
|
50
|
+
nonce: string;
|
|
51
|
+
codeVerifier: string;
|
|
52
|
+
redirectUri: string;
|
|
53
|
+
expiresAt: number;
|
|
54
|
+
}
|
|
55
|
+
export interface DeviceAuthorization {
|
|
56
|
+
deviceCode: string;
|
|
57
|
+
userCode: string;
|
|
58
|
+
verificationUri: string;
|
|
59
|
+
verificationUriComplete?: string;
|
|
60
|
+
expiresInSeconds: number;
|
|
61
|
+
intervalSeconds?: number;
|
|
62
|
+
}
|
|
63
|
+
export interface DeviceTransaction extends DeviceAuthorization {
|
|
64
|
+
kind: 'device-code';
|
|
65
|
+
expiresAt: number;
|
|
66
|
+
nextPollAt: number;
|
|
67
|
+
consumed: boolean;
|
|
68
|
+
}
|
|
69
|
+
export type OAuthTransaction = AuthorizationTransaction | DeviceTransaction;
|
|
70
|
+
export interface OperatorSessionSummary {
|
|
71
|
+
id: string;
|
|
72
|
+
createdAt: string;
|
|
73
|
+
lastSeenAt?: string;
|
|
74
|
+
current: boolean;
|
|
75
|
+
clientId: string;
|
|
76
|
+
environment: ElementsEnvironment;
|
|
77
|
+
}
|
package/dist/test/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{TestUtils as
|
|
1
|
+
import{TestUtils as d}from"@safetech/inheriti-core-sdk/test";import{DataAssetBuilder as r}from"@safetech/inheriti-core-sdk";function a(e){return`${e.system}:${e.contextId}`}var n=class{keys=new Map;async store(t,s){this.keys.set(a(t),s.slice())}async load(t){return this.keys.get(a(t))?.slice()}async remove(t){this.keys.delete(a(t))}};var i=class{values=new Map;async set(t,s){this.values.set(t,s)}async get(t){return this.values.get(t)}async remove(t){this.values.delete(t)}};var o=class extends n{},c=class extends i{};var y=["abandon","ability","able","about","above","absent","absorb","abstract","absurd","abuse","access","accident","account","accuse","achieve","acid","acoustic","acquire","across","act","action","actor","actress","actual","adapt","add","addict","address","adjust","admit","adult","advance","advice","aerobic","afford","afraid","again","agent","agree","ahead","aim","air","airport","aisle","alarm","album","alcohol","alert"],u={plainText:e=>r.plainText({name:e?.name??"Plain text asset",id:e?.id,secret:e?.secret??{text:"Sample plain text"}}),onlineAccount:e=>r.userAndPassword({name:e?.name??"Online account",id:e?.id,secret:e?.secret??{appOrWebsite:"example.com",email:"user@example.com",username:"sampleuser",password:"SamplePass123!"}}),recoveryCode:e=>r.recoveryCode({name:e?.name??"Recovery code",id:e?.id,secret:e?.secret??{appOrWebsite:"example.com",code:"XXXX-XXXX-XXXX-XXXX"}}),pinCode:e=>r.pinCode({name:e?.name??"PIN code",id:e?.id,secret:e?.secret??{deviceOrApp:"My Device",code:"1234"}}),apiKey:e=>r.apiKey({name:e?.name??"API key",id:e?.id,secret:e?.secret??{app:"My App",apiKey:"sk-sample-api-key-12345"}}),privateKey:e=>r.privateKey({name:e?.name??"Private key",id:e?.id,secret:e?.secret??{publicAddress:"0x0000000000000000000000000000000000000000",privateKey:"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"}}),seedPhrase:e=>{let t=e?.typeLength??12,s=e?.secret?.words??Array.from({length:t},(f,m)=>y[m%y.length]);return r.seedPhrase({name:e?.name??"Seed phrase",id:e?.id,secret:{words:s}})},paymentDebitCard:e=>r.paymentDebitCard({name:e?.name??"Debit card",id:e?.id,secret:e?.secret??{cardNumber:"4111 1111 1111 1111",expiryDate:"12/28"}}),paymentCreditCard:e=>r.paymentCreditCard({name:e?.name??"Credit card",id:e?.id,secret:e?.secret??{cardNumber:"4111 1111 1111 1111",expiryDate:"12/28"}})},M={...d,ProtectionPlan:{...d.ProtectionPlan,PlanDataAssetInputGenerator:u}};export{o as TestKeyVault,c as TestStatePort,M as TestUtils};
|