@safetech/inheriti-client-sdk 1.17.0 → 1.17.2
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/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/inheriti-client-sdk.umd.js +186 -108
- package/dist/node.d.ts +31 -0
- package/dist/node.js +1 -0
- package/dist/sdk-types.d.ts +411 -3
- package/dist/src/elements/elements-api-port.d.ts +172 -0
- package/dist/src/elements/elements-client.d.ts +93 -0
- package/dist/src/elements/http-elements-api-port.d.ts +32 -0
- package/dist/src/elements/index.d.ts +17 -0
- package/dist/src/elements/key-vault.d.ts +19 -0
- package/dist/src/elements/master-key.d.ts +58 -0
- package/dist/src/elements/node-plan-material-reconstructor.d.ts +7 -0
- package/dist/src/elements/plan-material-reconstructor.d.ts +11 -0
- package/dist/src/elements/relay-master-key-source.d.ts +38 -0
- package/dist/src/elements/state-port.d.ts +11 -0
- package/dist/src/elements/test-doubles.d.ts +6 -0
- package/dist/src/elements/unwrap-dek.d.ts +7 -0
- package/dist/test/index.js +1 -1
- package/dist/test.d.ts +2 -184
- package/index.ts +1 -0
- package/node.ts +46 -0
- package/package.json +12 -3
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { SDKContainer } from '@safetech/inheriti-core-sdk/vanilla';
|
|
2
|
+
import type { KeyVault } from './key-vault';
|
|
3
|
+
import type { StatePort } from './state-port';
|
|
4
|
+
import type { CollectedPlanMaterial, ElementsApiPort, ExportPlanBridgeInput, GovernedRevealSession, GovernedRevealState, PlanBridgeEnvelope, StepUpReadContext } from './elements-api-port';
|
|
5
|
+
import type { PlanMaterialReconstructor } from './plan-material-reconstructor';
|
|
6
|
+
import type { MasterKeyResolver } from './master-key';
|
|
7
|
+
export interface ElementsClientOptions {
|
|
8
|
+
coreSdk: SDKContainer;
|
|
9
|
+
keyVault?: KeyVault;
|
|
10
|
+
state?: StatePort;
|
|
11
|
+
api?: ElementsApiPort;
|
|
12
|
+
reconstructor?: PlanMaterialReconstructor;
|
|
13
|
+
/**
|
|
14
|
+
* Resolves master keys per plan. A host may need several: its own Application key
|
|
15
|
+
* and a foreign organization key for each bridged plan it opens.
|
|
16
|
+
*/
|
|
17
|
+
masterKeys?: MasterKeyResolver;
|
|
18
|
+
/** The Application this client acts for; needed to wrap keys of plans it creates. */
|
|
19
|
+
applicationId?: string;
|
|
20
|
+
}
|
|
21
|
+
export default class ElementsClient {
|
|
22
|
+
private readonly coreSdk;
|
|
23
|
+
readonly keyVault: KeyVault;
|
|
24
|
+
readonly state: StatePort;
|
|
25
|
+
constructor(coreSdk: SDKContainer, options?: {
|
|
26
|
+
keyVault?: KeyVault;
|
|
27
|
+
state?: StatePort;
|
|
28
|
+
api?: ElementsApiPort;
|
|
29
|
+
reconstructor?: PlanMaterialReconstructor;
|
|
30
|
+
masterKeys?: MasterKeyResolver;
|
|
31
|
+
applicationId?: string;
|
|
32
|
+
});
|
|
33
|
+
private readonly api?;
|
|
34
|
+
private readonly reconstructor?;
|
|
35
|
+
private readonly masterKeys?;
|
|
36
|
+
private readonly applicationId?;
|
|
37
|
+
createPlan<TInput, TResult>(input: TInput): Promise<TResult>;
|
|
38
|
+
/**
|
|
39
|
+
* Configures a plan, sealing its key under the Application's master key when one
|
|
40
|
+
* exists. Supplying the key here is what makes the plan non-custodial: without it
|
|
41
|
+
* the platform unwraps the DEK and can read the plan.
|
|
42
|
+
*/
|
|
43
|
+
configurePlan<TInput extends {
|
|
44
|
+
masterKey?: string;
|
|
45
|
+
}, TResult>(input: TInput): Promise<TResult>;
|
|
46
|
+
/** The Application's own master key, when this client was given one to resolve. */
|
|
47
|
+
applicationMasterKey(): Promise<string | undefined>;
|
|
48
|
+
/**
|
|
49
|
+
* Resolves the key that opens a plan before anything is collected.
|
|
50
|
+
*
|
|
51
|
+
* Ordering matters: collecting releases the custodian share and advances the reveal,
|
|
52
|
+
* so discovering afterwards that the key is unavailable spends a one-shot release for
|
|
53
|
+
* nothing. Resolving first also keeps a single SafeKey interaction — the relay — ahead
|
|
54
|
+
* of the custodian's, instead of interleaving two device round trips.
|
|
55
|
+
*/
|
|
56
|
+
prepareReveal(planId: string): Promise<{
|
|
57
|
+
masterKeyWrapped: boolean;
|
|
58
|
+
masterKeyHex?: string;
|
|
59
|
+
}>;
|
|
60
|
+
/**
|
|
61
|
+
* The whole direct reveal in the order it must happen: hold the key, then collect,
|
|
62
|
+
* then reconstruct.
|
|
63
|
+
*/
|
|
64
|
+
revealPlan(planId: string, stepUp?: StepUpReadContext): Promise<Uint8Array>;
|
|
65
|
+
collectPlanMaterial(planId: string, stepUp?: StepUpReadContext): Promise<CollectedPlanMaterial>;
|
|
66
|
+
reconstructPlanMaterial(material: CollectedPlanMaterial): Promise<Uint8Array>;
|
|
67
|
+
/**
|
|
68
|
+
* Resolves the key that opens this plan, caching it in the vault.
|
|
69
|
+
*
|
|
70
|
+
* Fails with the reference named rather than letting an unwrap collapse into an
|
|
71
|
+
* opaque decrypt error: "you are missing the key for Business organization X" is the
|
|
72
|
+
* diagnostic that matters.
|
|
73
|
+
*/
|
|
74
|
+
resolveMasterKey(material: {
|
|
75
|
+
planId: string;
|
|
76
|
+
masterKeyWrapped?: boolean;
|
|
77
|
+
tenantId?: string;
|
|
78
|
+
sourceReference?: {
|
|
79
|
+
system: string;
|
|
80
|
+
contextId: string;
|
|
81
|
+
};
|
|
82
|
+
}): Promise<string | undefined>;
|
|
83
|
+
initializeGovernedReveal(planId: string, stepUp?: StepUpReadContext): Promise<GovernedRevealSession>;
|
|
84
|
+
getGovernedReveal(processId: string, stepUp?: StepUpReadContext): Promise<GovernedRevealState>;
|
|
85
|
+
exportPlanBridge(planId: string, input: ExportPlanBridgeInput): Promise<PlanBridgeEnvelope>;
|
|
86
|
+
importPlanBridge(envelope: PlanBridgeEnvelope): Promise<{
|
|
87
|
+
planId: string;
|
|
88
|
+
}>;
|
|
89
|
+
collectGovernedPlanMaterial(session: GovernedRevealSession, stepUp?: StepUpReadContext): Promise<CollectedPlanMaterial>;
|
|
90
|
+
reconstructGovernedPlanMaterial(session: GovernedRevealSession, material: CollectedPlanMaterial): Promise<Uint8Array>;
|
|
91
|
+
private useCase;
|
|
92
|
+
}
|
|
93
|
+
export declare function createElementsClient(options: ElementsClientOptions): ElementsClient;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { BearerTokenResolver, HttpTransport } from '@safetech/inheriti-core-sdk/node';
|
|
2
|
+
import type { CollectedPlanMaterial, ElementsApiPort, PlanKeyReference, ExportPlanBridgeInput, GovernedRevealSession, GovernedRevealState, GovernedSharesMaterial, GovernedValidatorMaterial, PlanBridgeEnvelope, StepUpReadContext } from './elements-api-port';
|
|
3
|
+
export declare class ElementsApiRequestFailed extends Error {
|
|
4
|
+
readonly status: number;
|
|
5
|
+
readonly code?: string | undefined;
|
|
6
|
+
readonly detail?: string | undefined;
|
|
7
|
+
constructor(status: number, code?: string | undefined, detail?: string | undefined);
|
|
8
|
+
get stepUpRequestId(): string | undefined;
|
|
9
|
+
}
|
|
10
|
+
export default class HttpElementsApiPort implements ElementsApiPort {
|
|
11
|
+
private readonly apiUrl;
|
|
12
|
+
private readonly environment;
|
|
13
|
+
private readonly getBearerToken;
|
|
14
|
+
private readonly transport;
|
|
15
|
+
constructor(apiUrl: string, environment: 'TEST' | 'LIVE', getBearerToken: BearerTokenResolver, transport: HttpTransport);
|
|
16
|
+
planKeyReference(planId: string): Promise<PlanKeyReference>;
|
|
17
|
+
collectPlanMaterial(planId: string, stepUp?: StepUpReadContext): Promise<CollectedPlanMaterial>;
|
|
18
|
+
initializeGovernedReveal(planId: string, stepUp?: StepUpReadContext): Promise<GovernedRevealSession>;
|
|
19
|
+
getGovernedReveal(processId: string, stepUp?: StepUpReadContext): Promise<GovernedRevealState>;
|
|
20
|
+
collectGovernedValidatorShares(processId: string, stepUp?: StepUpReadContext): Promise<GovernedValidatorMaterial>;
|
|
21
|
+
collectGovernedShares(processId: string, stepUp?: StepUpReadContext): Promise<GovernedSharesMaterial>;
|
|
22
|
+
markGovernedSharesCollected(processId: string): Promise<void>;
|
|
23
|
+
markGovernedSharesReconstructed(processId: string): Promise<void>;
|
|
24
|
+
markGovernedDataRevealed(processId: string): Promise<void>;
|
|
25
|
+
closeGovernedReveal(processId: string): Promise<void>;
|
|
26
|
+
exportPlanBridge(planId: string, input: ExportPlanBridgeInput): Promise<PlanBridgeEnvelope>;
|
|
27
|
+
importPlanBridge(envelope: PlanBridgeEnvelope): Promise<{
|
|
28
|
+
planId: string;
|
|
29
|
+
}>;
|
|
30
|
+
private request;
|
|
31
|
+
private requestWithoutResult;
|
|
32
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { default as ElementsClient, createElementsClient } from './elements-client';
|
|
2
|
+
export type { ElementsClientOptions } from './elements-client';
|
|
3
|
+
export { MemoryKeyVault } from './key-vault';
|
|
4
|
+
export type { KeyVault } from './key-vault';
|
|
5
|
+
export { MemoryStatePort } from './state-port';
|
|
6
|
+
export type { StatePort } from './state-port';
|
|
7
|
+
export type { CollectedPlanMaterial, ElementsApiPort, StepUpReadContext } from './elements-api-port';
|
|
8
|
+
export type { GovernedRevealSession, GovernedRevealState, GovernedShare, GovernedSharesMaterial, GovernedValidatorMaterial } from './elements-api-port';
|
|
9
|
+
export type { ExportPlanBridgeInput, PlanBridgeEnvelope, PlanRevealProfile } from './elements-api-port';
|
|
10
|
+
export { ElementsApiPortRequired } from './elements-api-port';
|
|
11
|
+
export type { PlanMaterialReconstructor } from './plan-material-reconstructor';
|
|
12
|
+
export { PlanMaterialReconstructorRequired } from './plan-material-reconstructor';
|
|
13
|
+
export { MasterKeyRequired, StaticMasterKeyResolver, masterKeyRefFor, masterKeyRefKey } from './master-key';
|
|
14
|
+
export type { MasterKeyRef, MasterKeyResolver } from './master-key';
|
|
15
|
+
export { unwrapDekWithMasterKey } from './unwrap-dek';
|
|
16
|
+
export { RelayMasterKeySource, MasterKeyRelayExpired, MasterKeyRelayTimedOut } from './relay-master-key-source';
|
|
17
|
+
export type { MasterKeyRelayPort, RelayMasterKeySourceOptions } from './relay-master-key-source';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { MasterKeyRef } from './master-key';
|
|
2
|
+
/**
|
|
3
|
+
* Where the host keeps master keys between operations.
|
|
4
|
+
*
|
|
5
|
+
* Keyed by master key reference rather than by Application: a host may hold its own
|
|
6
|
+
* Application key alongside a foreign organization key for each bridged plan, and those
|
|
7
|
+
* are different keys that must not collide.
|
|
8
|
+
*/
|
|
9
|
+
export interface KeyVault {
|
|
10
|
+
store(ref: MasterKeyRef, key: Uint8Array): Promise<void>;
|
|
11
|
+
load(ref: MasterKeyRef): Promise<Uint8Array | undefined>;
|
|
12
|
+
remove(ref: MasterKeyRef): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export declare class MemoryKeyVault implements KeyVault {
|
|
15
|
+
private readonly keys;
|
|
16
|
+
store(ref: MasterKeyRef, key: Uint8Array): Promise<void>;
|
|
17
|
+
load(ref: MasterKeyRef): Promise<Uint8Array | undefined>;
|
|
18
|
+
remove(ref: MasterKeyRef): Promise<void>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { MasterKeySource } from '@safetech/inheriti-core-sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Identifies which master key opens a plan.
|
|
4
|
+
*
|
|
5
|
+
* A plan's key is a property of the plan, not of the Application holding it: a bridged
|
|
6
|
+
* plan is never re-wrapped, so it stays sealed under the key of the context it came
|
|
7
|
+
* from. One host may therefore need several keys at once — its own Application key and
|
|
8
|
+
* a foreign organization key for each bridged plan.
|
|
9
|
+
*/
|
|
10
|
+
export interface MasterKeyRef {
|
|
11
|
+
system: 'INHERITI_BUSINESS' | 'INHERITI_ELEMENTS';
|
|
12
|
+
contextId: string;
|
|
13
|
+
}
|
|
14
|
+
/** Stable string form of a ref, used as the `KeyVault` key. */
|
|
15
|
+
export declare function masterKeyRefKey(ref: MasterKeyRef): string;
|
|
16
|
+
/**
|
|
17
|
+
* Resolves the master key for a given plan's key reference.
|
|
18
|
+
*
|
|
19
|
+
* Custody says how a key came into existence; a resolver says how *this* host obtains
|
|
20
|
+
* it. The two are independent, so a resolver may derive one key, read another from a
|
|
21
|
+
* KMS, and relay a third.
|
|
22
|
+
*/
|
|
23
|
+
export interface MasterKeyResolver {
|
|
24
|
+
resolve(ref: MasterKeyRef): Promise<string | undefined>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Derives which key opens a plan.
|
|
28
|
+
*
|
|
29
|
+
* A bridged plan names its source context; a locally created one is opened by the key
|
|
30
|
+
* of the Application holding it.
|
|
31
|
+
*/
|
|
32
|
+
export declare function masterKeyRefFor(material: {
|
|
33
|
+
tenantId?: string;
|
|
34
|
+
sourceReference?: {
|
|
35
|
+
system: string;
|
|
36
|
+
contextId: string;
|
|
37
|
+
};
|
|
38
|
+
}): MasterKeyRef | undefined;
|
|
39
|
+
/** Thrown when a plan is master key wrapped and no key resolves for its reference. */
|
|
40
|
+
export declare class MasterKeyRequired extends Error {
|
|
41
|
+
readonly ref: MasterKeyRef;
|
|
42
|
+
constructor(ref: MasterKeyRef);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Resolves keys from a static map of references to sources.
|
|
46
|
+
*
|
|
47
|
+
* Sources come from the Core SDK, so a passphrase-derived key and one supplied from a
|
|
48
|
+
* KMS are the same to everything downstream.
|
|
49
|
+
*/
|
|
50
|
+
export declare class StaticMasterKeyResolver implements MasterKeyResolver {
|
|
51
|
+
private readonly sources;
|
|
52
|
+
constructor(entries?: Array<{
|
|
53
|
+
ref: MasterKeyRef;
|
|
54
|
+
source: MasterKeySource;
|
|
55
|
+
}>);
|
|
56
|
+
register(ref: MasterKeyRef, source: MasterKeySource): this;
|
|
57
|
+
resolve(ref: MasterKeyRef): Promise<string | undefined>;
|
|
58
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CollectedPlanMaterial } from './elements-api-port';
|
|
2
|
+
import type { PlanMaterialReconstructor } from './plan-material-reconstructor';
|
|
3
|
+
export default class NodePlanMaterialReconstructor implements PlanMaterialReconstructor {
|
|
4
|
+
reconstruct(material: CollectedPlanMaterial, masterKeyHex?: string): Promise<Uint8Array>;
|
|
5
|
+
private decryptShare;
|
|
6
|
+
private decodeBase64;
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CollectedPlanMaterial } from './elements-api-port';
|
|
2
|
+
export interface PlanMaterialReconstructor {
|
|
3
|
+
/**
|
|
4
|
+
* `masterKeyHex` is required when the material reports `masterKeyWrapped`: the plan
|
|
5
|
+
* key comes back sealed and the platform cannot open it.
|
|
6
|
+
*/
|
|
7
|
+
reconstruct(material: CollectedPlanMaterial, masterKeyHex?: string): Promise<Uint8Array>;
|
|
8
|
+
}
|
|
9
|
+
export declare class PlanMaterialReconstructorRequired extends Error {
|
|
10
|
+
constructor();
|
|
11
|
+
}
|
|
@@ -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,11 @@
|
|
|
1
|
+
export interface StatePort {
|
|
2
|
+
set<T>(key: string, value: T): Promise<void>;
|
|
3
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
4
|
+
remove(key: string): Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
export declare class MemoryStatePort implements StatePort {
|
|
7
|
+
private readonly values;
|
|
8
|
+
set<T>(key: string, value: T): Promise<void>;
|
|
9
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
10
|
+
remove(key: string): Promise<void>;
|
|
11
|
+
}
|
|
@@ -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>;
|
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};
|
package/dist/test.d.ts
CHANGED
|
@@ -1,184 +1,2 @@
|
|
|
1
|
-
export declare const TestUtils:
|
|
2
|
-
|
|
3
|
-
PlanDataAssetInputGenerator: {
|
|
4
|
-
plainText: (props?: {
|
|
5
|
-
id?: string;
|
|
6
|
-
name?: string;
|
|
7
|
-
secret?: {
|
|
8
|
-
text: string;
|
|
9
|
-
};
|
|
10
|
-
}) => import("@safetech/inheriti-core-sdk").DataAsset;
|
|
11
|
-
onlineAccount: (props?: any) => import("@safetech/inheriti-core-sdk").DataAsset;
|
|
12
|
-
recoveryCode: (props?: any) => import("@safetech/inheriti-core-sdk").DataAsset;
|
|
13
|
-
pinCode: (props?: any) => import("@safetech/inheriti-core-sdk").DataAsset;
|
|
14
|
-
apiKey: (props?: any) => import("@safetech/inheriti-core-sdk").DataAsset;
|
|
15
|
-
privateKey: (props?: any) => import("@safetech/inheriti-core-sdk").DataAsset;
|
|
16
|
-
seedPhrase: (props?: {
|
|
17
|
-
id?: string;
|
|
18
|
-
name?: string;
|
|
19
|
-
typeLength?: number;
|
|
20
|
-
secret?: {
|
|
21
|
-
words: string[];
|
|
22
|
-
};
|
|
23
|
-
}) => import("@safetech/inheriti-core-sdk").DataAsset;
|
|
24
|
-
paymentDebitCard: (props?: any) => import("@safetech/inheriti-core-sdk").DataAsset;
|
|
25
|
-
paymentCreditCard: (props?: any) => import("@safetech/inheriti-core-sdk").DataAsset;
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
RandomElementPickerMother: {
|
|
29
|
-
new (): {};
|
|
30
|
-
from(a: any): any;
|
|
31
|
-
};
|
|
32
|
-
SharedProtectionPlan: {};
|
|
33
|
-
DataAssetInputGenerator: {
|
|
34
|
-
new (): {};
|
|
35
|
-
plainText({ id: a, name: e, secret: i }?: {
|
|
36
|
-
id?: any;
|
|
37
|
-
name?: any;
|
|
38
|
-
}): {
|
|
39
|
-
id: any;
|
|
40
|
-
type: string;
|
|
41
|
-
meta: {
|
|
42
|
-
name: any;
|
|
43
|
-
};
|
|
44
|
-
secret: any;
|
|
45
|
-
};
|
|
46
|
-
userAndPassword({ id: a, name: e, notes: i, secret: n }?: {
|
|
47
|
-
id?: any;
|
|
48
|
-
name?: any;
|
|
49
|
-
notes?: any;
|
|
50
|
-
}): {
|
|
51
|
-
id: any;
|
|
52
|
-
type: string;
|
|
53
|
-
meta: {
|
|
54
|
-
name: any;
|
|
55
|
-
notes: any;
|
|
56
|
-
};
|
|
57
|
-
secret: any;
|
|
58
|
-
};
|
|
59
|
-
recoveryCode({ id: a, name: e, notes: i, secret: n }?: {
|
|
60
|
-
id?: any;
|
|
61
|
-
name?: any;
|
|
62
|
-
notes?: any;
|
|
63
|
-
}): {
|
|
64
|
-
id: any;
|
|
65
|
-
type: string;
|
|
66
|
-
meta: {
|
|
67
|
-
name: any;
|
|
68
|
-
notes: any;
|
|
69
|
-
};
|
|
70
|
-
secret: any;
|
|
71
|
-
};
|
|
72
|
-
pinCode({ id: a, name: e, notes: i, secret: n }?: {
|
|
73
|
-
id?: any;
|
|
74
|
-
name?: any;
|
|
75
|
-
notes?: any;
|
|
76
|
-
}): {
|
|
77
|
-
id: any;
|
|
78
|
-
type: string;
|
|
79
|
-
meta: {
|
|
80
|
-
name: any;
|
|
81
|
-
notes: any;
|
|
82
|
-
};
|
|
83
|
-
secret: any;
|
|
84
|
-
};
|
|
85
|
-
apiKey({ id: a, name: e, notes: i, secret: n }?: {
|
|
86
|
-
id?: any;
|
|
87
|
-
name?: any;
|
|
88
|
-
notes?: any;
|
|
89
|
-
}): {
|
|
90
|
-
id: any;
|
|
91
|
-
type: string;
|
|
92
|
-
meta: {
|
|
93
|
-
name: any;
|
|
94
|
-
notes: any;
|
|
95
|
-
};
|
|
96
|
-
secret: any;
|
|
97
|
-
};
|
|
98
|
-
privateKey({ id: a, name: e, notes: i, secret: n }?: {
|
|
99
|
-
id?: any;
|
|
100
|
-
name?: any;
|
|
101
|
-
notes?: any;
|
|
102
|
-
}): {
|
|
103
|
-
id: any;
|
|
104
|
-
type: string;
|
|
105
|
-
meta: {
|
|
106
|
-
name: any;
|
|
107
|
-
notes: any;
|
|
108
|
-
};
|
|
109
|
-
secret: any;
|
|
110
|
-
};
|
|
111
|
-
seedPhrase({ id: a, name: e, notes: i, typeLength: n, secret: r }?: {
|
|
112
|
-
id?: any;
|
|
113
|
-
name?: any;
|
|
114
|
-
notes?: any;
|
|
115
|
-
typeLength?: any;
|
|
116
|
-
}): {
|
|
117
|
-
id: any;
|
|
118
|
-
type: string;
|
|
119
|
-
meta: {
|
|
120
|
-
name: any;
|
|
121
|
-
notes: any;
|
|
122
|
-
};
|
|
123
|
-
secret: any;
|
|
124
|
-
};
|
|
125
|
-
paymentDebitCard({ id: a, name: e, notes: i, secret: n }?: {
|
|
126
|
-
id?: any;
|
|
127
|
-
name?: any;
|
|
128
|
-
notes?: any;
|
|
129
|
-
}): {
|
|
130
|
-
id: any;
|
|
131
|
-
type: string;
|
|
132
|
-
meta: {
|
|
133
|
-
name: any;
|
|
134
|
-
notes: any;
|
|
135
|
-
};
|
|
136
|
-
secret: any;
|
|
137
|
-
};
|
|
138
|
-
pdf({ id: a, name: e }?: {
|
|
139
|
-
id?: any;
|
|
140
|
-
name?: any;
|
|
141
|
-
}): {
|
|
142
|
-
id: any;
|
|
143
|
-
type: string;
|
|
144
|
-
meta: {
|
|
145
|
-
name: any;
|
|
146
|
-
mimeType: string;
|
|
147
|
-
isMedia: boolean;
|
|
148
|
-
};
|
|
149
|
-
secret: {
|
|
150
|
-
data: string;
|
|
151
|
-
mimeType: string;
|
|
152
|
-
};
|
|
153
|
-
};
|
|
154
|
-
video({ id: a, name: e }?: {
|
|
155
|
-
id?: any;
|
|
156
|
-
name?: any;
|
|
157
|
-
}): {
|
|
158
|
-
id: any;
|
|
159
|
-
type: string;
|
|
160
|
-
meta: {
|
|
161
|
-
name: any;
|
|
162
|
-
mimeType: string;
|
|
163
|
-
isMedia: boolean;
|
|
164
|
-
};
|
|
165
|
-
secret: {
|
|
166
|
-
data: string;
|
|
167
|
-
mimeType: string;
|
|
168
|
-
};
|
|
169
|
-
};
|
|
170
|
-
paymentCreditCard({ id: a, name: e, notes: i, secret: n }?: {
|
|
171
|
-
id?: any;
|
|
172
|
-
name?: any;
|
|
173
|
-
notes?: any;
|
|
174
|
-
}): {
|
|
175
|
-
id: any;
|
|
176
|
-
type: string;
|
|
177
|
-
meta: {
|
|
178
|
-
name: any;
|
|
179
|
-
notes: any;
|
|
180
|
-
};
|
|
181
|
-
secret: any;
|
|
182
|
-
};
|
|
183
|
-
};
|
|
184
|
-
};
|
|
1
|
+
export declare const TestUtils: any;
|
|
2
|
+
export { TestKeyVault, TestStatePort } from './src/elements/test-doubles';
|
package/index.ts
CHANGED
package/node.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createNodeSharedConfigurationSdk, decodeAssetContainer } from '@safetech/inheriti-core-sdk/node';
|
|
2
|
+
import type { NodeSharedConfigurationSdkOptions } from '@safetech/inheriti-core-sdk/node';
|
|
3
|
+
import ElementsClient from './src/elements/elements-client';
|
|
4
|
+
import type { KeyVault } from './src/elements/key-vault';
|
|
5
|
+
import type { MasterKeyResolver } from './src/elements/master-key';
|
|
6
|
+
import type { StatePort } from './src/elements/state-port';
|
|
7
|
+
import HttpElementsApiPort from './src/elements/http-elements-api-port';
|
|
8
|
+
import NodePlanMaterialReconstructor from './src/elements/node-plan-material-reconstructor';
|
|
9
|
+
|
|
10
|
+
export interface NodeElementsClientOptions extends NodeSharedConfigurationSdkOptions {
|
|
11
|
+
environment: 'TEST' | 'LIVE';
|
|
12
|
+
keyVault?: KeyVault;
|
|
13
|
+
state?: StatePort;
|
|
14
|
+
/** Resolves master keys per plan reference; required to open non-custodial plans. */
|
|
15
|
+
masterKeys?: MasterKeyResolver;
|
|
16
|
+
/** The Application this client acts for; needed to wrap keys of plans it creates. */
|
|
17
|
+
applicationId?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function createNodeElementsClient(options: NodeElementsClientOptions): ElementsClient {
|
|
21
|
+
const baseTransport = options.transport ?? globalThis.fetch.bind(globalThis);
|
|
22
|
+
const transport: NonNullable<NodeSharedConfigurationSdkOptions['transport']> = (input, init) => {
|
|
23
|
+
const headers = new Headers(init?.headers);
|
|
24
|
+
headers.set('x-elements-environment', options.environment);
|
|
25
|
+
return baseTransport(input, Object.assign({}, init, { headers }));
|
|
26
|
+
};
|
|
27
|
+
const coreSdk = createNodeSharedConfigurationSdk({ apiUrl: options.apiUrl, getBearerToken: options.getBearerToken, transport, workerUrl: options.workerUrl, reconciliationConcurrency: options.reconciliationConcurrency, eventListeners: options.eventListeners });
|
|
28
|
+
const api = new HttpElementsApiPort(options.apiUrl, options.environment, options.getBearerToken, transport);
|
|
29
|
+
return new ElementsClient(coreSdk, { keyVault: options.keyVault, state: options.state, api, reconstructor: new NodePlanMaterialReconstructor(), masterKeys: options.masterKeys, applicationId: options.applicationId });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { ElementsClient };
|
|
33
|
+
export { ElementsApiRequestFailed } from './src/elements/http-elements-api-port';
|
|
34
|
+
export type { StepUpReadContext } from './src/elements/elements-api-port';
|
|
35
|
+
export { MemoryKeyVault } from './src/elements/key-vault';
|
|
36
|
+
export type { KeyVault } from './src/elements/key-vault';
|
|
37
|
+
export { MemoryStatePort } from './src/elements/state-port';
|
|
38
|
+
export type { StatePort } from './src/elements/state-port';
|
|
39
|
+
export { MasterKeyRequired, StaticMasterKeyResolver, masterKeyRefFor, masterKeyRefKey } from './src/elements/master-key';
|
|
40
|
+
export type { MasterKeyRef, MasterKeyResolver } from './src/elements/master-key';
|
|
41
|
+
export { unwrapDekWithMasterKey } from './src/elements/unwrap-dek';
|
|
42
|
+
export { RelayMasterKeySource, MasterKeyRelayExpired, MasterKeyRelayTimedOut } from './src/elements/relay-master-key-source';
|
|
43
|
+
export type { MasterKeyRelayPort } from './src/elements/relay-master-key-source';
|
|
44
|
+
export { PassphraseMasterKeySource, RawMasterKeySource, deriveMasterKey, generateHexSeed, computePassphraseVerifier } from '@safetech/inheriti-core-sdk/node';
|
|
45
|
+
export type { MasterKeySource } from '@safetech/inheriti-core-sdk/node';
|
|
46
|
+
export { decodeAssetContainer };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@safetech/inheriti-client-sdk",
|
|
3
|
-
"version": "1.17.
|
|
3
|
+
"version": "1.17.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -13,12 +13,19 @@
|
|
|
13
13
|
"./test": {
|
|
14
14
|
"import": "./dist/test/index.js",
|
|
15
15
|
"require": "./dist/test/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./node": {
|
|
18
|
+
"import": "./dist/node.js",
|
|
19
|
+
"require": "./dist/node.js"
|
|
16
20
|
}
|
|
17
21
|
},
|
|
18
22
|
"typesVersions": {
|
|
19
23
|
"*": {
|
|
20
24
|
"test": [
|
|
21
25
|
"dist/test/index.d.ts"
|
|
26
|
+
],
|
|
27
|
+
"node": [
|
|
28
|
+
"dist/node.d.ts"
|
|
22
29
|
]
|
|
23
30
|
}
|
|
24
31
|
},
|
|
@@ -26,7 +33,7 @@
|
|
|
26
33
|
"license": "MIT",
|
|
27
34
|
"dependencies": {
|
|
28
35
|
"@safetech/safekey-sdk": "^1.0.0",
|
|
29
|
-
"@safetech/inheriti-core-sdk": "
|
|
36
|
+
"@safetech/inheriti-core-sdk": "4.0.16"
|
|
30
37
|
},
|
|
31
38
|
"devDependencies": {
|
|
32
39
|
"@rollup/plugin-alias": "^5.1.1",
|
|
@@ -66,12 +73,14 @@
|
|
|
66
73
|
"publish-version": "node scripts/publish-sdk-version.js",
|
|
67
74
|
"add-patch": "node scripts/bump-version.js patch",
|
|
68
75
|
"generate-docs": "npx typedoc --json docs/docs.json",
|
|
76
|
+
"proof:elements-round-trip": "node examples/elements-round-trip.mjs",
|
|
69
77
|
"publish-npm": "node esbuild.config.js && node scripts/publish-npm.js"
|
|
70
78
|
},
|
|
71
79
|
"files": [
|
|
72
80
|
"dist",
|
|
73
81
|
"README.md",
|
|
74
82
|
"LICENSE",
|
|
75
|
-
"index.ts"
|
|
83
|
+
"index.ts",
|
|
84
|
+
"node.ts"
|
|
76
85
|
]
|
|
77
86
|
}
|