@safetech/inheriti-client-sdk 1.17.1 → 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/node.d.ts CHANGED
@@ -2,11 +2,16 @@ import { decodeAssetContainer } from '@safetech/inheriti-core-sdk/node';
2
2
  import type { NodeSharedConfigurationSdkOptions } from '@safetech/inheriti-core-sdk/node';
3
3
  import ElementsClient from './src/elements/elements-client';
4
4
  import type { KeyVault } from './src/elements/key-vault';
5
+ import type { MasterKeyResolver } from './src/elements/master-key';
5
6
  import type { StatePort } from './src/elements/state-port';
6
7
  export interface NodeElementsClientOptions extends NodeSharedConfigurationSdkOptions {
7
8
  environment: 'TEST' | 'LIVE';
8
9
  keyVault?: KeyVault;
9
10
  state?: StatePort;
11
+ /** Resolves master keys per plan reference; required to open non-custodial plans. */
12
+ masterKeys?: MasterKeyResolver;
13
+ /** The Application this client acts for; needed to wrap keys of plans it creates. */
14
+ applicationId?: string;
10
15
  }
11
16
  export declare function createNodeElementsClient(options: NodeElementsClientOptions): ElementsClient;
12
17
  export { ElementsClient };
@@ -16,4 +21,11 @@ export { MemoryKeyVault } from './src/elements/key-vault';
16
21
  export type { KeyVault } from './src/elements/key-vault';
17
22
  export { MemoryStatePort } from './src/elements/state-port';
18
23
  export type { StatePort } from './src/elements/state-port';
24
+ export { MasterKeyRequired, StaticMasterKeyResolver, masterKeyRefFor, masterKeyRefKey } from './src/elements/master-key';
25
+ export type { MasterKeyRef, MasterKeyResolver } from './src/elements/master-key';
26
+ export { unwrapDekWithMasterKey } from './src/elements/unwrap-dek';
27
+ export { RelayMasterKeySource, MasterKeyRelayExpired, MasterKeyRelayTimedOut } from './src/elements/relay-master-key-source';
28
+ export type { MasterKeyRelayPort } from './src/elements/relay-master-key-source';
29
+ export { PassphraseMasterKeySource, RawMasterKeySource, deriveMasterKey, generateHexSeed, computePassphraseVerifier } from '@safetech/inheriti-core-sdk/node';
30
+ export type { MasterKeySource } from '@safetech/inheriti-core-sdk/node';
19
31
  export { decodeAssetContainer };
package/dist/node.js CHANGED
@@ -1 +1 @@
1
- import{createNodeSharedConfigurationSdk as S,decodeAssetContainer as B}from"@safetech/inheriti-core-sdk/node";var u=class{keys=new Map;async store(e,t){this.keys.set(e,t.slice())}async load(e){return this.keys.get(e)?.slice()}async remove(e){this.keys.delete(e)}};var m=class{values=new Map;async set(e,t){this.values.set(e,t)}async get(e){return this.values.get(e)}async remove(e){this.values.delete(e)}};var l=class extends Error{constructor(){super("elements_api_port_required"),this.name="ElementsApiPortRequired"}};var P=class extends Error{constructor(){super("plan_material_reconstructor_required"),this.name="PlanMaterialReconstructorRequired"}};var h=class{constructor(e,t={}){this.coreSdk=e;this.keyVault=t.keyVault??new u,this.state=t.state??new m,this.api=t.api,this.reconstructor=t.reconstructor}keyVault;state;api;reconstructor;createPlan(e){return this.useCase("CreateSharedProtectionPlanUseCase",e)}configurePlan(e){return this.useCase("ConfigureSharedProtectionPlanUseCase",e)}collectPlanMaterial(e,t){if(!this.api)throw new l;return t?this.api.collectPlanMaterial(e,t):this.api.collectPlanMaterial(e)}reconstructPlanMaterial(e){if(!this.reconstructor)throw new P;return this.reconstructor.reconstruct(e)}initializeGovernedReveal(e,t){if(!this.api)throw new l;return t?this.api.initializeGovernedReveal(e,t):this.api.initializeGovernedReveal(e)}getGovernedReveal(e,t){if(!this.api)throw new l;return t?this.api.getGovernedReveal(e,t):this.api.getGovernedReveal(e)}exportPlanBridge(e,t){if(!this.api)throw new l;return this.api.exportPlanBridge(e,t)}importPlanBridge(e){if(!this.api)throw new l;return this.api.importPlanBridge(e)}async collectGovernedPlanMaterial(e,t){if(!this.api)throw new l;let r=t?await this.api.collectGovernedValidatorShares(e.processId,t):await this.api.collectGovernedValidatorShares(e.processId),s=t?await this.api.collectGovernedShares(e.processId,t):await this.api.collectGovernedShares(e.processId);await this.api.markGovernedSharesCollected(e.processId);let n=r.validatorShares.map(i=>Object.assign({},i,{shareType:"VALIDATOR_SHARD"})),o=s.dataShards.map(i=>Object.assign({},i,{shareType:"DATA_SHARD"})),p=s.backupShards.map(i=>Object.assign({},i,{shareType:"BACKUP_SHARD"})),c=s.keyShards.map(i=>Object.assign({},i,{shareType:"CUSTODIAN_KEY_SHARD"}));return{planId:e.planId,mergeThreshold:e.mergeThreshold,planKey:s.dek||r.dek,shares:n.concat(o,p,c),verifiedStorageLayerTypes:[]}}async reconstructGovernedPlanMaterial(e,t){let r=await this.reconstructPlanMaterial(t);if(!this.api)throw new l;return await this.api.markGovernedSharesReconstructed(e.processId),await this.api.markGovernedDataRevealed(e.processId),await this.api.closeGovernedReveal(e.processId),r}useCase(e,t){return this.coreSdk.getService(e).execute(t)}};var d=class extends Error{constructor(t,r,s){super(r??`elements_api_request_failed_${t}`);this.status=t;this.code=r;this.detail=s;this.name="ElementsApiRequestFailed"}get stepUpRequestId(){return this.code==="step_up_approval_required"?this.detail:void 0}},v=class{constructor(e,t,r,s){this.apiUrl=e;this.environment=t;this.getBearerToken=r;this.transport=s}async collectPlanMaterial(e,t){return this.request(`shared-plans/${encodeURIComponent(e)}/material/collect`,"POST",void 0,t)}initializeGovernedReveal(e,t){return this.request(`shared-plans/${encodeURIComponent(e)}/governed-reveal`,"POST",void 0,t)}getGovernedReveal(e,t){return this.request(`shared-plans/governed-reveal/${encodeURIComponent(e)}`,"GET",void 0,t)}collectGovernedValidatorShares(e,t){return this.request(`shared-plans/governed-reveal/${encodeURIComponent(e)}/validator-shares`,"POST",void 0,t)}collectGovernedShares(e,t){return this.request(`shared-plans/governed-reveal/${encodeURIComponent(e)}/shares`,"POST",void 0,t)}markGovernedSharesCollected(e){return this.requestWithoutResult(`shared-plans/governed-reveal/${encodeURIComponent(e)}/shares-collected`)}markGovernedSharesReconstructed(e){return this.requestWithoutResult(`shared-plans/governed-reveal/${encodeURIComponent(e)}/shares-reconstructed`)}markGovernedDataRevealed(e){return this.requestWithoutResult(`shared-plans/governed-reveal/${encodeURIComponent(e)}/data-revealed`)}closeGovernedReveal(e){return this.requestWithoutResult(`shared-plans/governed-reveal/${encodeURIComponent(e)}/close`)}exportPlanBridge(e,t){return this.request(`shared-plans/${encodeURIComponent(e)}/bridge/export`,"POST",t)}importPlanBridge(e){return this.request("shared-plans/bridge/import","POST",{envelope:e})}async request(e,t,r,s){let n=await this.getBearerToken(),o=new Headers({"x-elements-environment":this.environment});n&&o.set("authorization",`Bearer ${n}`),s?.requestId&&o.set("x-elements-step-up-request",s.requestId),r&&o.set("content-type","application/json");let p=this.apiUrl.endsWith("/")?this.apiUrl:`${this.apiUrl}/`,c=await this.transport(new URL(e,p),{method:t,headers:o,body:r?JSON.stringify(r):void 0}),i=await c.json();if(!c.ok)throw new d(c.status,i.name??i.message,i.description);if(!i.ok||!i.result)throw new d(c.status);return i.result}async requestWithoutResult(e){let t=await this.getBearerToken(),r=new Headers({"x-elements-environment":this.environment});t&&r.set("authorization",`Bearer ${t}`);let s=this.apiUrl.endsWith("/")?this.apiUrl:`${this.apiUrl}/`,n=await this.transport(new URL(e,s),{method:"POST",headers:r});if(!n.ok)throw new d(n.status);if(!(await n.json()).ok)throw new d(n.status)}};import{createConfiguredSsdpV2Processor as y}from"@safetech/inheriti-core-sdk/node";var g=class{async reconstruct(e){let t=await crypto.subtle.importKey("raw",this.decodeBase64(e.planKey),{name:"AES-GCM"},!1,["decrypt"]),r=[],s=[];for(let n of e.shares){let o=await this.decryptShare(n.data,t);n.shareType==="VALIDATOR_SHARD"?s.push(o):r.push(o)}return y().reconstruct(r,{planId:e.planId,threshold:e.mergeThreshold,keyShares:s}).result}async decryptShare(e,t){let r=e.indexOf(":");if(r<1)throw new Error("invalid_encrypted_plan_share");let s=this.decodeBase64(e.slice(0,r)),n=this.decodeBase64(e.slice(r+1)),o=await crypto.subtle.decrypt({name:"AES-GCM",iv:s},t,n);return new TextDecoder().decode(o)}decodeBase64(e){let t=atob(e),r=new ArrayBuffer(t.length),s=new Uint8Array(r);for(let n=0;n<t.length;n+=1)s[n]=t.charCodeAt(n);return r}};function q(a){let e=a.transport??globalThis.fetch.bind(globalThis),t=(n,o)=>{let p=new Headers(o?.headers);return p.set("x-elements-environment",a.environment),e(n,Object.assign({},o,{headers:p}))},r=S({apiUrl:a.apiUrl,getBearerToken:a.getBearerToken,transport:t,workerUrl:a.workerUrl,reconciliationConcurrency:a.reconciliationConcurrency,eventListeners:a.eventListeners}),s=new v(a.apiUrl,a.environment,a.getBearerToken,t);return new h(r,{keyVault:a.keyVault,state:a.state,api:s,reconstructor:new g})}export{d as ElementsApiRequestFailed,h as ElementsClient,u as MemoryKeyVault,m as MemoryStatePort,q as createNodeElementsClient,B as decodeAssetContainer};
1
+ import{createNodeSharedConfigurationSdk as b,decodeAssetContainer as te}from"@safetech/inheriti-core-sdk/node";function c(r){return`${r.system}:${r.contextId}`}function K(r){return r.sourceReference?{system:r.sourceReference.system,contextId:r.sourceReference.contextId}:r.tenantId?{system:"INHERITI_ELEMENTS",contextId:r.tenantId}:void 0}var u=class extends Error{constructor(t){super(`master_key_required:${c(t)}`);this.ref=t;this.name="MasterKeyRequired"}},I=class{sources=new Map;constructor(e=[]){for(let t of e)this.register(t.ref,t.source)}register(e,t){return this.sources.set(c(e),t),this}async resolve(e){return this.sources.get(c(e))?.resolve()}};var y=class{keys=new Map;async store(e,t){this.keys.set(c(e),t.slice())}async load(e){return this.keys.get(c(e))?.slice()}async remove(e){this.keys.delete(c(e))}};var h=class{values=new Map;async set(e,t){this.values.set(e,t)}async get(e){return this.values.get(e)}async remove(e){this.values.delete(e)}};var p=class extends Error{constructor(){super("elements_api_port_required"),this.name="ElementsApiPortRequired"}};var R=class extends Error{constructor(){super("plan_material_reconstructor_required"),this.name="PlanMaterialReconstructorRequired"}};var g=class{constructor(e,t={}){this.coreSdk=e;this.keyVault=t.keyVault??new y,this.state=t.state??new h,this.api=t.api,this.reconstructor=t.reconstructor,this.masterKeys=t.masterKeys,this.applicationId=t.applicationId}keyVault;state;api;reconstructor;masterKeys;applicationId;createPlan(e){return this.useCase("CreateSharedProtectionPlanUseCase",e)}async configurePlan(e){let t=e.masterKey??await this.applicationMasterKey(),a=t?Object.assign({},e,{masterKey:t}):e;return this.useCase("ConfigureSharedProtectionPlanUseCase",a)}async applicationMasterKey(){if(!this.applicationId)return;let e={system:"INHERITI_ELEMENTS",contextId:this.applicationId},t=await this.keyVault.load(e);if(t)return E(t);let a=await this.masterKeys?.resolve(e);return a&&await this.keyVault.store(e,x(a)),a}async prepareReveal(e){if(!this.api)throw new p;let t=await this.api.planKeyReference(e);return t.masterKeyWrapped?{masterKeyWrapped:!0,masterKeyHex:await this.resolveMasterKey(t)}:{masterKeyWrapped:!1}}async revealPlan(e,t){await this.prepareReveal(e);let a=await this.collectPlanMaterial(e,t);return this.reconstructPlanMaterial(a)}collectPlanMaterial(e,t){if(!this.api)throw new p;return t?this.api.collectPlanMaterial(e,t):this.api.collectPlanMaterial(e)}async reconstructPlanMaterial(e){if(!this.reconstructor)throw new R;return this.reconstructor.reconstruct(e,await this.resolveMasterKey(e))}async resolveMasterKey(e){if(!e.masterKeyWrapped)return;let t=K(e);if(!t)throw new u({system:"INHERITI_ELEMENTS",contextId:e.planId});let a=await this.keyVault.load(t);if(a)return E(a);let s=await this.masterKeys?.resolve(t);if(!s)throw new u(t);return await this.keyVault.store(t,x(s)),s}initializeGovernedReveal(e,t){if(!this.api)throw new p;return t?this.api.initializeGovernedReveal(e,t):this.api.initializeGovernedReveal(e)}getGovernedReveal(e,t){if(!this.api)throw new p;return t?this.api.getGovernedReveal(e,t):this.api.getGovernedReveal(e)}exportPlanBridge(e,t){if(!this.api)throw new p;return this.api.exportPlanBridge(e,t)}importPlanBridge(e){if(!this.api)throw new p;return this.api.importPlanBridge(e)}async collectGovernedPlanMaterial(e,t){if(!this.api)throw new p;await this.resolveMasterKey({planId:e.planId,masterKeyWrapped:e.masterKeyWrapped,tenantId:e.tenantId,sourceReference:e.sourceReference});let a=t?await this.api.collectGovernedValidatorShares(e.processId,t):await this.api.collectGovernedValidatorShares(e.processId),s=t?await this.api.collectGovernedShares(e.processId,t):await this.api.collectGovernedShares(e.processId);await this.api.markGovernedSharesCollected(e.processId);let n=a.validatorShares.map(d=>Object.assign({},d,{shareType:"VALIDATOR_SHARD"})),o=s.dataShards.map(d=>Object.assign({},d,{shareType:"DATA_SHARD"})),i=s.backupShards.map(d=>Object.assign({},d,{shareType:"BACKUP_SHARD"})),l=s.keyShards.map(d=>Object.assign({},d,{shareType:"CUSTODIAN_KEY_SHARD"}));return{planId:e.planId,mergeThreshold:e.mergeThreshold,planKey:s.dek||a.dek,shares:n.concat(o,i,l),verifiedStorageLayerTypes:[],masterKeyWrapped:e.masterKeyWrapped,tenantId:e.tenantId,sourceReference:e.sourceReference}}async reconstructGovernedPlanMaterial(e,t){let a=await this.reconstructPlanMaterial(t);if(!this.api)throw new p;return await this.api.markGovernedSharesReconstructed(e.processId),await this.api.markGovernedDataRevealed(e.processId),await this.api.closeGovernedReveal(e.processId),a}useCase(e,t){return this.coreSdk.getService(e).execute(t)}};function x(r){let e=r.match(/.{2}/g);if(!e||e.length*2!==r.length)throw new Error("invalid_master_key_material");return new Uint8Array(e.map(t=>parseInt(t,16)))}function E(r){return Array.from(r).map(e=>e.toString(16).padStart(2,"0")).join("")}var m=class extends Error{constructor(t,a,s){super(a??`elements_api_request_failed_${t}`);this.status=t;this.code=a;this.detail=s;this.name="ElementsApiRequestFailed"}get stepUpRequestId(){return this.code==="step_up_approval_required"?this.detail:void 0}},f=class{constructor(e,t,a,s){this.apiUrl=e;this.environment=t;this.getBearerToken=a;this.transport=s}planKeyReference(e){return this.request(`shared-plans/${encodeURIComponent(e)}/material/key-reference`,"GET")}async collectPlanMaterial(e,t){return this.request(`shared-plans/${encodeURIComponent(e)}/material/collect`,"POST",void 0,t)}initializeGovernedReveal(e,t){return this.request(`shared-plans/${encodeURIComponent(e)}/governed-reveal`,"POST",void 0,t)}getGovernedReveal(e,t){return this.request(`shared-plans/governed-reveal/${encodeURIComponent(e)}`,"GET",void 0,t)}collectGovernedValidatorShares(e,t){return this.request(`shared-plans/governed-reveal/${encodeURIComponent(e)}/validator-shares`,"POST",void 0,t)}collectGovernedShares(e,t){return this.request(`shared-plans/governed-reveal/${encodeURIComponent(e)}/shares`,"POST",void 0,t)}markGovernedSharesCollected(e){return this.requestWithoutResult(`shared-plans/governed-reveal/${encodeURIComponent(e)}/shares-collected`)}markGovernedSharesReconstructed(e){return this.requestWithoutResult(`shared-plans/governed-reveal/${encodeURIComponent(e)}/shares-reconstructed`)}markGovernedDataRevealed(e){return this.requestWithoutResult(`shared-plans/governed-reveal/${encodeURIComponent(e)}/data-revealed`)}closeGovernedReveal(e){return this.requestWithoutResult(`shared-plans/governed-reveal/${encodeURIComponent(e)}/close`)}exportPlanBridge(e,t){return this.request(`shared-plans/${encodeURIComponent(e)}/bridge/export`,"POST",t)}importPlanBridge(e){return this.request("shared-plans/bridge/import","POST",{envelope:e})}async request(e,t,a,s){let n=await this.getBearerToken(),o=new Headers({"x-elements-environment":this.environment});n&&o.set("authorization",`Bearer ${n}`),s?.requestId&&o.set("x-elements-step-up-request",s.requestId),a&&o.set("content-type","application/json");let i=this.apiUrl.endsWith("/")?this.apiUrl:`${this.apiUrl}/`,l=await this.transport(new URL(e,i),{method:t,headers:o,body:a?JSON.stringify(a):void 0}),d=await l.json();if(!l.ok)throw new m(l.status,d.name??d.message,d.description);if(!d.ok||!d.result)throw new m(l.status);return d.result}async requestWithoutResult(e){let t=await this.getBearerToken(),a=new Headers({"x-elements-environment":this.environment});t&&a.set("authorization",`Bearer ${t}`);let s=this.apiUrl.endsWith("/")?this.apiUrl:`${this.apiUrl}/`,n=await this.transport(new URL(e,s),{method:"POST",headers:a});if(!n.ok)throw new m(n.status);if(!(await n.json()).ok)throw new m(n.status)}};import{createConfiguredSsdpV2Processor as U}from"@safetech/inheriti-core-sdk/node";async function M(r,e){if(!e)throw new Error("master_key_required");let t=T(e),a=await crypto.subtle.importKey("raw",t,{name:"AES-GCM"},!1,["decrypt"]),s=k(r),n=s.slice(0,12),o=s.slice(12),i=await crypto.subtle.decrypt({name:"AES-GCM",iv:n},a,o);return C(new Uint8Array(i))}function T(r){let e=r.match(/.{2}/g);if(!e||e.length*2!==r.length)throw new Error("invalid_master_key_material");return new Uint8Array(e.map(t=>parseInt(t,16)))}function k(r){let e=atob(r),t=new Uint8Array(e.length);for(let a=0;a<e.length;a+=1)t[a]=e.charCodeAt(a);return t}function C(r){let e="";for(let t of r)e+=String.fromCharCode(t);return btoa(e)}var v=class{async reconstruct(e,t){let a=e.masterKeyWrapped?await M(e.planKey,t):e.planKey,s=await crypto.subtle.importKey("raw",this.decodeBase64(a),{name:"AES-GCM"},!1,["decrypt"]),n=[],o=[];for(let i of e.shares){let l=await this.decryptShare(i.data,s);i.shareType==="VALIDATOR_SHARD"?o.push(l):n.push(l)}return U().reconstruct(n,{planId:e.planId,threshold:e.mergeThreshold,keyShares:o}).result}async decryptShare(e,t){let a=e.indexOf(":");if(a<1)throw new Error("invalid_encrypted_plan_share");let s=this.decodeBase64(e.slice(0,a)),n=this.decodeBase64(e.slice(a+1)),o=await crypto.subtle.decrypt({name:"AES-GCM",iv:s},t,n);return new TextDecoder().decode(o)}decodeBase64(e){let t=atob(e),a=new ArrayBuffer(t.length),s=new Uint8Array(a);for(let n=0;n<t.length;n+=1)s[n]=t.charCodeAt(n);return a}};import{decryptRSAOAEP as A,generateRSAOAEPKeyPair as G}from"@safetech/inheriti-core-sdk";var P=class extends Error{constructor(t){super("master_key_relay_timed_out");this.sessionId=t;this.name="MasterKeyRelayTimedOut"}},S=class extends Error{constructor(t){super("master_key_relay_expired");this.sessionId=t;this.name="MasterKeyRelayExpired"}},w=class{constructor(e){this.options=e}async resolve(){let{publicKeyBase64:e,privateKey:t}=await G(),a=await this.options.api.startRelaySession(e),s=this.options.pollIntervalMs??2e3,n=Date.now()+(this.options.timeoutMs??600*1e3),o=this.options.sleep??(i=>new Promise(l=>setTimeout(l,i)));for(;Date.now()<n;){let i=await this.options.api.readRelaySession(a.sessionId);if(i.status==="DELIVERED"&&i.sealedMasterKey){let l=(await A(i.sealedMasterKey,t)).trim().toLowerCase();if(!/^[0-9a-f]{64}$/.test(l))throw new Error("invalid_master_key_material");return l}if(i.status==="EXPIRED")throw new S(a.sessionId);await o(s)}throw new P(a.sessionId)}};import{PassphraseMasterKeySource as ye,RawMasterKeySource as he,deriveMasterKey as ge,generateHexSeed as fe,computePassphraseVerifier as ve}from"@safetech/inheriti-core-sdk/node";function ne(r){let e=r.transport??globalThis.fetch.bind(globalThis),t=(n,o)=>{let i=new Headers(o?.headers);return i.set("x-elements-environment",r.environment),e(n,Object.assign({},o,{headers:i}))},a=b({apiUrl:r.apiUrl,getBearerToken:r.getBearerToken,transport:t,workerUrl:r.workerUrl,reconciliationConcurrency:r.reconciliationConcurrency,eventListeners:r.eventListeners}),s=new f(r.apiUrl,r.environment,r.getBearerToken,t);return new g(a,{keyVault:r.keyVault,state:r.state,api:s,reconstructor:new v,masterKeys:r.masterKeys,applicationId:r.applicationId})}export{m as ElementsApiRequestFailed,g as ElementsClient,S as MasterKeyRelayExpired,P as MasterKeyRelayTimedOut,u as MasterKeyRequired,y as MemoryKeyVault,h as MemoryStatePort,ye as PassphraseMasterKeySource,he as RawMasterKeySource,w as RelayMasterKeySource,I as StaticMasterKeyResolver,ve as computePassphraseVerifier,ne as createNodeElementsClient,te as decodeAssetContainer,ge as deriveMasterKey,fe as generateHexSeed,K as masterKeyRefFor,c as masterKeyRefKey,M as unwrapDekWithMasterKey};
@@ -1,6 +1,6 @@
1
1
  import { SDKContainer } from '@safetech/inheriti-core-sdk/vanilla';
2
2
  export { SDKContainer } from '@safetech/inheriti-core-sdk/vanilla';
3
- import { ValidEnv, AuthClientProps } from '@safetech/inheriti-core-sdk';
3
+ import { ValidEnv, AuthClientProps, MasterKeySource } from '@safetech/inheriti-core-sdk';
4
4
  export * from '@safetech/inheriti-core-sdk';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  import { ReactNode } from 'react';
@@ -56,16 +56,81 @@ declare function getAvailableEnvs(): {
56
56
  demoKeyApiUrl: string;
57
57
  };
58
58
 
59
+ /**
60
+ * Identifies which master key opens a plan.
61
+ *
62
+ * A plan's key is a property of the plan, not of the Application holding it: a bridged
63
+ * plan is never re-wrapped, so it stays sealed under the key of the context it came
64
+ * from. One host may therefore need several keys at once — its own Application key and
65
+ * a foreign organization key for each bridged plan.
66
+ */
67
+ interface MasterKeyRef {
68
+ system: 'INHERITI_BUSINESS' | 'INHERITI_ELEMENTS';
69
+ contextId: string;
70
+ }
71
+ /** Stable string form of a ref, used as the `KeyVault` key. */
72
+ declare function masterKeyRefKey(ref: MasterKeyRef): string;
73
+ /**
74
+ * Resolves the master key for a given plan's key reference.
75
+ *
76
+ * Custody says how a key came into existence; a resolver says how *this* host obtains
77
+ * it. The two are independent, so a resolver may derive one key, read another from a
78
+ * KMS, and relay a third.
79
+ */
80
+ interface MasterKeyResolver {
81
+ resolve(ref: MasterKeyRef): Promise<string | undefined>;
82
+ }
83
+ /**
84
+ * Derives which key opens a plan.
85
+ *
86
+ * A bridged plan names its source context; a locally created one is opened by the key
87
+ * of the Application holding it.
88
+ */
89
+ declare function masterKeyRefFor(material: {
90
+ tenantId?: string;
91
+ sourceReference?: {
92
+ system: string;
93
+ contextId: string;
94
+ };
95
+ }): MasterKeyRef | undefined;
96
+ /** Thrown when a plan is master key wrapped and no key resolves for its reference. */
97
+ declare class MasterKeyRequired extends Error {
98
+ readonly ref: MasterKeyRef;
99
+ constructor(ref: MasterKeyRef);
100
+ }
101
+ /**
102
+ * Resolves keys from a static map of references to sources.
103
+ *
104
+ * Sources come from the Core SDK, so a passphrase-derived key and one supplied from a
105
+ * KMS are the same to everything downstream.
106
+ */
107
+ declare class StaticMasterKeyResolver implements MasterKeyResolver {
108
+ private readonly sources;
109
+ constructor(entries?: Array<{
110
+ ref: MasterKeyRef;
111
+ source: MasterKeySource;
112
+ }>);
113
+ register(ref: MasterKeyRef, source: MasterKeySource): this;
114
+ resolve(ref: MasterKeyRef): Promise<string | undefined>;
115
+ }
116
+
117
+ /**
118
+ * Where the host keeps master keys between operations.
119
+ *
120
+ * Keyed by master key reference rather than by Application: a host may hold its own
121
+ * Application key alongside a foreign organization key for each bridged plan, and those
122
+ * are different keys that must not collide.
123
+ */
59
124
  interface KeyVault {
60
- store(applicationId: string, key: Uint8Array): Promise<void>;
61
- load(applicationId: string): Promise<Uint8Array | undefined>;
62
- remove(applicationId: string): Promise<void>;
125
+ store(ref: MasterKeyRef, key: Uint8Array): Promise<void>;
126
+ load(ref: MasterKeyRef): Promise<Uint8Array | undefined>;
127
+ remove(ref: MasterKeyRef): Promise<void>;
63
128
  }
64
129
  declare class MemoryKeyVault implements KeyVault {
65
130
  private readonly keys;
66
- store(applicationId: string, key: Uint8Array): Promise<void>;
67
- load(applicationId: string): Promise<Uint8Array | undefined>;
68
- remove(applicationId: string): Promise<void>;
131
+ store(ref: MasterKeyRef, key: Uint8Array): Promise<void>;
132
+ load(ref: MasterKeyRef): Promise<Uint8Array | undefined>;
133
+ remove(ref: MasterKeyRef): Promise<void>;
69
134
  }
70
135
 
71
136
  interface StatePort {
@@ -91,8 +156,30 @@ interface CollectedPlanMaterial {
91
156
  data: string;
92
157
  }>;
93
158
  verifiedStorageLayerTypes: string[];
159
+ /** True when `planKey` is still sealed under a master key and must be unwrapped. */
160
+ masterKeyWrapped?: boolean;
161
+ /** The tenant holding the plan. With no source reference, this names the key. */
162
+ tenantId?: string;
163
+ /** Present when the plan came from another system, whose key still opens it. */
164
+ sourceReference?: {
165
+ system: string;
166
+ planId: string;
167
+ contextId: string;
168
+ };
169
+ }
170
+ /** Metadata naming the key that opens a plan, without collecting anything. */
171
+ interface PlanKeyReference {
172
+ planId: string;
173
+ masterKeyWrapped: boolean;
174
+ tenantId: string;
175
+ sourceReference?: {
176
+ system: string;
177
+ planId: string;
178
+ contextId: string;
179
+ };
94
180
  }
95
181
  interface ElementsApiPort {
182
+ planKeyReference(planId: string): Promise<PlanKeyReference>;
96
183
  collectPlanMaterial(planId: string, stepUp?: StepUpReadContext): Promise<CollectedPlanMaterial>;
97
184
  initializeGovernedReveal(planId: string, stepUp?: StepUpReadContext): Promise<GovernedRevealSession>;
98
185
  getGovernedReveal(processId: string, stepUp?: StepUpReadContext): Promise<GovernedRevealState>;
@@ -195,6 +282,14 @@ interface GovernedRevealSession {
195
282
  planId: string;
196
283
  mergeThreshold: number;
197
284
  status?: string;
285
+ /** Same key signalling the direct collection route returns, for the governed path. */
286
+ masterKeyWrapped?: boolean;
287
+ tenantId?: string;
288
+ sourceReference?: {
289
+ system: string;
290
+ planId: string;
291
+ contextId: string;
292
+ };
198
293
  }
199
294
  interface GovernedRevealState {
200
295
  id: string;
@@ -224,7 +319,11 @@ declare class ElementsApiPortRequired extends Error {
224
319
  }
225
320
 
226
321
  interface PlanMaterialReconstructor {
227
- reconstruct(material: CollectedPlanMaterial): Promise<Uint8Array>;
322
+ /**
323
+ * `masterKeyHex` is required when the material reports `masterKeyWrapped`: the plan
324
+ * key comes back sealed and the platform cannot open it.
325
+ */
326
+ reconstruct(material: CollectedPlanMaterial, masterKeyHex?: string): Promise<Uint8Array>;
228
327
  }
229
328
  declare class PlanMaterialReconstructorRequired extends Error {
230
329
  constructor();
@@ -236,6 +335,13 @@ interface ElementsClientOptions {
236
335
  state?: StatePort;
237
336
  api?: ElementsApiPort;
238
337
  reconstructor?: PlanMaterialReconstructor;
338
+ /**
339
+ * Resolves master keys per plan. A host may need several: its own Application key
340
+ * and a foreign organization key for each bridged plan it opens.
341
+ */
342
+ masterKeys?: MasterKeyResolver;
343
+ /** The Application this client acts for; needed to wrap keys of plans it creates. */
344
+ applicationId?: string;
239
345
  }
240
346
  declare class ElementsClient {
241
347
  private readonly coreSdk;
@@ -246,13 +352,59 @@ declare class ElementsClient {
246
352
  state?: StatePort;
247
353
  api?: ElementsApiPort;
248
354
  reconstructor?: PlanMaterialReconstructor;
355
+ masterKeys?: MasterKeyResolver;
356
+ applicationId?: string;
249
357
  });
250
358
  private readonly api?;
251
359
  private readonly reconstructor?;
360
+ private readonly masterKeys?;
361
+ private readonly applicationId?;
252
362
  createPlan<TInput, TResult>(input: TInput): Promise<TResult>;
253
- configurePlan<TInput, TResult>(input: TInput): Promise<TResult>;
363
+ /**
364
+ * Configures a plan, sealing its key under the Application's master key when one
365
+ * exists. Supplying the key here is what makes the plan non-custodial: without it
366
+ * the platform unwraps the DEK and can read the plan.
367
+ */
368
+ configurePlan<TInput extends {
369
+ masterKey?: string;
370
+ }, TResult>(input: TInput): Promise<TResult>;
371
+ /** The Application's own master key, when this client was given one to resolve. */
372
+ applicationMasterKey(): Promise<string | undefined>;
373
+ /**
374
+ * Resolves the key that opens a plan before anything is collected.
375
+ *
376
+ * Ordering matters: collecting releases the custodian share and advances the reveal,
377
+ * so discovering afterwards that the key is unavailable spends a one-shot release for
378
+ * nothing. Resolving first also keeps a single SafeKey interaction — the relay — ahead
379
+ * of the custodian's, instead of interleaving two device round trips.
380
+ */
381
+ prepareReveal(planId: string): Promise<{
382
+ masterKeyWrapped: boolean;
383
+ masterKeyHex?: string;
384
+ }>;
385
+ /**
386
+ * The whole direct reveal in the order it must happen: hold the key, then collect,
387
+ * then reconstruct.
388
+ */
389
+ revealPlan(planId: string, stepUp?: StepUpReadContext): Promise<Uint8Array>;
254
390
  collectPlanMaterial(planId: string, stepUp?: StepUpReadContext): Promise<CollectedPlanMaterial>;
255
391
  reconstructPlanMaterial(material: CollectedPlanMaterial): Promise<Uint8Array>;
392
+ /**
393
+ * Resolves the key that opens this plan, caching it in the vault.
394
+ *
395
+ * Fails with the reference named rather than letting an unwrap collapse into an
396
+ * opaque decrypt error: "you are missing the key for Business organization X" is the
397
+ * diagnostic that matters.
398
+ */
399
+ resolveMasterKey(material: {
400
+ planId: string;
401
+ masterKeyWrapped?: boolean;
402
+ tenantId?: string;
403
+ sourceReference?: {
404
+ system: string;
405
+ contextId: string;
406
+ };
407
+ }): Promise<string | undefined>;
256
408
  initializeGovernedReveal(planId: string, stepUp?: StepUpReadContext): Promise<GovernedRevealSession>;
257
409
  getGovernedReveal(processId: string, stepUp?: StepUpReadContext): Promise<GovernedRevealState>;
258
410
  exportPlanBridge(planId: string, input: ExportPlanBridgeInput): Promise<PlanBridgeEnvelope>;
@@ -265,5 +417,51 @@ declare class ElementsClient {
265
417
  }
266
418
  declare function createElementsClient(options: ElementsClientOptions): ElementsClient;
267
419
 
268
- export { ElementsApiPortRequired, ElementsClient, InheritiClientProvider, MemoryKeyVault, MemoryStatePort, PlanMaterialReconstructorRequired, createElementsClient, getAvailableEnvs, useClient };
269
- export type { CollectedPlanMaterial, ElementsApiPort, ElementsClientOptions, ExportPlanBridgeInput, GovernedRevealSession, GovernedRevealState, GovernedShare, GovernedSharesMaterial, GovernedValidatorMaterial, InheritiClientProviderProps, KeyVault, PlanBridgeEnvelope, PlanMaterialReconstructor, PlanRevealProfile, StatePort, StepUpReadContext };
420
+ /**
421
+ * Opens a plan key that was sealed under a master key.
422
+ *
423
+ * The wrap is AES-GCM with a 12-byte prefixed IV, matching the Core SDK's
424
+ * `wrapKeyWithMasterKeyThenRsa`; the platform only ever removed the outer RSA layer.
425
+ */
426
+ declare function unwrapDekWithMasterKey(wrappedDekBase64: string, masterKeyHex?: string): Promise<string>;
427
+
428
+ interface MasterKeyRelayPort {
429
+ startRelaySession(clientPublicKey: string): Promise<{
430
+ sessionId: string;
431
+ expiresAt: string | Date;
432
+ }>;
433
+ readRelaySession(sessionId: string): Promise<{
434
+ status: 'PENDING' | 'DELIVERED' | 'EXPIRED';
435
+ sealedMasterKey?: string;
436
+ }>;
437
+ }
438
+ declare class MasterKeyRelayTimedOut extends Error {
439
+ readonly sessionId: string;
440
+ constructor(sessionId: string);
441
+ }
442
+ declare class MasterKeyRelayExpired extends Error {
443
+ readonly sessionId: string;
444
+ constructor(sessionId: string);
445
+ }
446
+ interface RelayMasterKeySourceOptions {
447
+ api: MasterKeyRelayPort;
448
+ /** How long to wait for the device before giving up. Defaults to the session lifetime. */
449
+ timeoutMs?: number;
450
+ pollIntervalMs?: number;
451
+ sleep?: (ms: number) => Promise<void>;
452
+ }
453
+ /**
454
+ * Obtains the master key from the device holding it.
455
+ *
456
+ * Elements has no websocket layer, so the host polls. The key is sealed to an ephemeral
457
+ * public key generated here and never leaves this process in the clear: the private half
458
+ * is not persisted, so a relayed key cannot be replayed from stored state.
459
+ */
460
+ declare class RelayMasterKeySource implements MasterKeySource {
461
+ private readonly options;
462
+ constructor(options: RelayMasterKeySourceOptions);
463
+ resolve(): Promise<string>;
464
+ }
465
+
466
+ export { ElementsApiPortRequired, ElementsClient, InheritiClientProvider, MasterKeyRelayExpired, MasterKeyRelayTimedOut, MasterKeyRequired, MemoryKeyVault, MemoryStatePort, PlanMaterialReconstructorRequired, RelayMasterKeySource, StaticMasterKeyResolver, createElementsClient, getAvailableEnvs, masterKeyRefFor, masterKeyRefKey, unwrapDekWithMasterKey, useClient };
467
+ export type { CollectedPlanMaterial, ElementsApiPort, ElementsClientOptions, ExportPlanBridgeInput, GovernedRevealSession, GovernedRevealState, GovernedShare, GovernedSharesMaterial, GovernedValidatorMaterial, InheritiClientProviderProps, KeyVault, MasterKeyRef, MasterKeyRelayPort, MasterKeyResolver, PlanBridgeEnvelope, PlanMaterialReconstructor, PlanRevealProfile, RelayMasterKeySourceOptions, StatePort, StepUpReadContext };
@@ -9,8 +9,30 @@ export interface CollectedPlanMaterial {
9
9
  data: string;
10
10
  }>;
11
11
  verifiedStorageLayerTypes: string[];
12
+ /** True when `planKey` is still sealed under a master key and must be unwrapped. */
13
+ masterKeyWrapped?: boolean;
14
+ /** The tenant holding the plan. With no source reference, this names the key. */
15
+ tenantId?: string;
16
+ /** Present when the plan came from another system, whose key still opens it. */
17
+ sourceReference?: {
18
+ system: string;
19
+ planId: string;
20
+ contextId: string;
21
+ };
22
+ }
23
+ /** Metadata naming the key that opens a plan, without collecting anything. */
24
+ export interface PlanKeyReference {
25
+ planId: string;
26
+ masterKeyWrapped: boolean;
27
+ tenantId: string;
28
+ sourceReference?: {
29
+ system: string;
30
+ planId: string;
31
+ contextId: string;
32
+ };
12
33
  }
13
34
  export interface ElementsApiPort {
35
+ planKeyReference(planId: string): Promise<PlanKeyReference>;
14
36
  collectPlanMaterial(planId: string, stepUp?: StepUpReadContext): Promise<CollectedPlanMaterial>;
15
37
  initializeGovernedReveal(planId: string, stepUp?: StepUpReadContext): Promise<GovernedRevealSession>;
16
38
  getGovernedReveal(processId: string, stepUp?: StepUpReadContext): Promise<GovernedRevealState>;
@@ -113,6 +135,14 @@ export interface GovernedRevealSession {
113
135
  planId: string;
114
136
  mergeThreshold: number;
115
137
  status?: string;
138
+ /** Same key signalling the direct collection route returns, for the governed path. */
139
+ masterKeyWrapped?: boolean;
140
+ tenantId?: string;
141
+ sourceReference?: {
142
+ system: string;
143
+ planId: string;
144
+ contextId: string;
145
+ };
116
146
  }
117
147
  export interface GovernedRevealState {
118
148
  id: string;
@@ -3,12 +3,20 @@ import type { KeyVault } from './key-vault';
3
3
  import type { StatePort } from './state-port';
4
4
  import type { CollectedPlanMaterial, ElementsApiPort, ExportPlanBridgeInput, GovernedRevealSession, GovernedRevealState, PlanBridgeEnvelope, StepUpReadContext } from './elements-api-port';
5
5
  import type { PlanMaterialReconstructor } from './plan-material-reconstructor';
6
+ import type { MasterKeyResolver } from './master-key';
6
7
  export interface ElementsClientOptions {
7
8
  coreSdk: SDKContainer;
8
9
  keyVault?: KeyVault;
9
10
  state?: StatePort;
10
11
  api?: ElementsApiPort;
11
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;
12
20
  }
13
21
  export default class ElementsClient {
14
22
  private readonly coreSdk;
@@ -19,13 +27,59 @@ export default class ElementsClient {
19
27
  state?: StatePort;
20
28
  api?: ElementsApiPort;
21
29
  reconstructor?: PlanMaterialReconstructor;
30
+ masterKeys?: MasterKeyResolver;
31
+ applicationId?: string;
22
32
  });
23
33
  private readonly api?;
24
34
  private readonly reconstructor?;
35
+ private readonly masterKeys?;
36
+ private readonly applicationId?;
25
37
  createPlan<TInput, TResult>(input: TInput): Promise<TResult>;
26
- configurePlan<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>;
27
65
  collectPlanMaterial(planId: string, stepUp?: StepUpReadContext): Promise<CollectedPlanMaterial>;
28
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>;
29
83
  initializeGovernedReveal(planId: string, stepUp?: StepUpReadContext): Promise<GovernedRevealSession>;
30
84
  getGovernedReveal(processId: string, stepUp?: StepUpReadContext): Promise<GovernedRevealState>;
31
85
  exportPlanBridge(planId: string, input: ExportPlanBridgeInput): Promise<PlanBridgeEnvelope>;
@@ -1,5 +1,5 @@
1
1
  import type { BearerTokenResolver, HttpTransport } from '@safetech/inheriti-core-sdk/node';
2
- import type { CollectedPlanMaterial, ElementsApiPort, ExportPlanBridgeInput, GovernedRevealSession, GovernedRevealState, GovernedSharesMaterial, GovernedValidatorMaterial, PlanBridgeEnvelope, StepUpReadContext } from './elements-api-port';
2
+ import type { CollectedPlanMaterial, ElementsApiPort, PlanKeyReference, ExportPlanBridgeInput, GovernedRevealSession, GovernedRevealState, GovernedSharesMaterial, GovernedValidatorMaterial, PlanBridgeEnvelope, StepUpReadContext } from './elements-api-port';
3
3
  export declare class ElementsApiRequestFailed extends Error {
4
4
  readonly status: number;
5
5
  readonly code?: string | undefined;
@@ -13,6 +13,7 @@ export default class HttpElementsApiPort implements ElementsApiPort {
13
13
  private readonly getBearerToken;
14
14
  private readonly transport;
15
15
  constructor(apiUrl: string, environment: 'TEST' | 'LIVE', getBearerToken: BearerTokenResolver, transport: HttpTransport);
16
+ planKeyReference(planId: string): Promise<PlanKeyReference>;
16
17
  collectPlanMaterial(planId: string, stepUp?: StepUpReadContext): Promise<CollectedPlanMaterial>;
17
18
  initializeGovernedReveal(planId: string, stepUp?: StepUpReadContext): Promise<GovernedRevealSession>;
18
19
  getGovernedReveal(processId: string, stepUp?: StepUpReadContext): Promise<GovernedRevealState>;
@@ -10,3 +10,8 @@ export type { ExportPlanBridgeInput, PlanBridgeEnvelope, PlanRevealProfile } fro
10
10
  export { ElementsApiPortRequired } from './elements-api-port';
11
11
  export type { PlanMaterialReconstructor } from './plan-material-reconstructor';
12
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';
@@ -1,11 +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
+ */
1
9
  export interface KeyVault {
2
- store(applicationId: string, key: Uint8Array): Promise<void>;
3
- load(applicationId: string): Promise<Uint8Array | undefined>;
4
- remove(applicationId: string): Promise<void>;
10
+ store(ref: MasterKeyRef, key: Uint8Array): Promise<void>;
11
+ load(ref: MasterKeyRef): Promise<Uint8Array | undefined>;
12
+ remove(ref: MasterKeyRef): Promise<void>;
5
13
  }
6
14
  export declare class MemoryKeyVault implements KeyVault {
7
15
  private readonly keys;
8
- store(applicationId: string, key: Uint8Array): Promise<void>;
9
- load(applicationId: string): Promise<Uint8Array | undefined>;
10
- remove(applicationId: string): Promise<void>;
16
+ store(ref: MasterKeyRef, key: Uint8Array): Promise<void>;
17
+ load(ref: MasterKeyRef): Promise<Uint8Array | undefined>;
18
+ remove(ref: MasterKeyRef): Promise<void>;
11
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
+ }
@@ -1,7 +1,7 @@
1
1
  import type { CollectedPlanMaterial } from './elements-api-port';
2
2
  import type { PlanMaterialReconstructor } from './plan-material-reconstructor';
3
3
  export default class NodePlanMaterialReconstructor implements PlanMaterialReconstructor {
4
- reconstruct(material: CollectedPlanMaterial): Promise<Uint8Array>;
4
+ reconstruct(material: CollectedPlanMaterial, masterKeyHex?: string): Promise<Uint8Array>;
5
5
  private decryptShare;
6
6
  private decodeBase64;
7
7
  }
@@ -1,6 +1,10 @@
1
1
  import type { CollectedPlanMaterial } from './elements-api-port';
2
2
  export interface PlanMaterialReconstructor {
3
- reconstruct(material: CollectedPlanMaterial): Promise<Uint8Array>;
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>;
4
8
  }
5
9
  export declare class PlanMaterialReconstructorRequired extends Error {
6
10
  constructor();
@@ -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
+ }