@tinycloud/web-sdk 3.14.0-beta.14 → 3.14.0-beta.16

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.
@@ -1,6 +1,7 @@
1
- import { type IDataVaultService, type ISecretsService, type Manifest, type PermissionEntry, type Result, type SecretScopeOptions, type SecretPutOptions } from "@tinycloud/sdk-core";
1
+ import { type IDataVaultService, type ISecretsService, type Manifest, type PermissionEntry, type Result, type SecretGetOptions, type SecretScopeOptions, type SecretPutOptions } from "@tinycloud/sdk-core";
2
2
  import type { VaultError } from "@tinycloud/sdk-core";
3
- type RequestPermissions = (additional: PermissionEntry[]) => Promise<{
3
+ import type { RequestPermissionsOptions } from "./requestPermissionsCore";
4
+ type RequestPermissions = (additional: PermissionEntry[], options?: RequestPermissionsOptions) => Promise<{
4
5
  approved: boolean;
5
6
  delegations?: readonly unknown[];
6
7
  }>;
@@ -9,6 +10,10 @@ export interface WebSecretsServiceConfig {
9
10
  space?: string;
10
11
  getManifest: () => Manifest | Manifest[] | undefined;
11
12
  requestPermissions: RequestPermissions;
13
+ /** The encryption network of this secrets space; an opted-in read asks only for a key on it. */
14
+ getEncryptionNetworkId?: () => string | undefined;
15
+ /** Whether the node has named keys. `put` is refused before any prompt when it does not (`false`) and when it cannot be checked (`undefined`). */
16
+ namedKeysSupported?: () => boolean | undefined | Promise<boolean | undefined>;
12
17
  resolveSpace?: (space: string) => string;
13
18
  getUnlockSigner?: () => unknown;
14
19
  }
@@ -22,14 +27,24 @@ export declare class WebSecretsService implements ISecretsService {
22
27
  get isUnlocked(): boolean;
23
28
  unlock(signer?: unknown): Promise<Result<void, VaultError>>;
24
29
  lock(): void;
25
- get(name: string, options?: SecretScopeOptions): ReturnType<ISecretsService["get"]>;
26
- getEntry(name: string, options?: SecretScopeOptions): ReturnType<ISecretsService["getEntry"]>;
30
+ /** With `requestPermission: true`, a read missing its own key's decrypt asks for exactly that key once, then reads again. */
31
+ get(name: string, options?: SecretGetOptions): ReturnType<ISecretsService["get"]>;
32
+ /** As {@link get}. */
33
+ getEntry(name: string, options?: SecretGetOptions): ReturnType<ISecretsService["getEntry"]>;
34
+ /**
35
+ * The ask goes through this page's permission prompt, never the node's own
36
+ * escalation, so the node reads without `requestPermission`. A declined or
37
+ * failed ask is PERMISSION_DENIED, as for a put; nothing is remembered, so
38
+ * the next opted-in read asks again.
39
+ */
40
+ private read;
27
41
  put(name: string, value: string, options?: SecretPutOptions): ReturnType<ISecretsService["put"]>;
28
42
  delete(name: string, options?: SecretScopeOptions): ReturnType<ISecretsService["delete"]>;
29
43
  list(options?: SecretScopeOptions): ReturnType<ISecretsService["list"]>;
30
44
  listAll(): ReturnType<ISecretsService["listAll"]>;
31
45
  private get service();
32
46
  private ensureMutationPermission;
47
+ private ask;
33
48
  private restoreUnlockAfterEscalation;
34
49
  private hasMutationPermission;
35
50
  }
@@ -25,8 +25,20 @@ export declare function isPanelResourceSet(resources: readonly Resource[], owner
25
25
  /** True when `grant` is exactly a panel grant of the session owned by `address`. */
26
26
  export declare function isPanelGrant(grant: PortableDelegation, address: string): boolean;
27
27
  /**
28
- * Stores the panel's own grants among `grants` for `address`, replacing a stored grant with the same cid. Other
29
- * delegations (an app's larger grant that already covered the request) are never stored.
28
+ * True when every resource is the exact key of one of this owner's secrets on the owner's default network
29
+ * (`secrets/<name>` or `secrets/scoped/<scope>/<name>`, as `secretKeyPath` derives it), with decrypt and/or
30
+ * key.create only and no caveats (TC-3284). One resource that is anything else (a prefix, another network or owner,
31
+ * another key, any other service) refuses the whole set.
32
+ */
33
+ export declare function isSecretKeyResourceSet(resources: readonly Resource[], owner: {
34
+ readonly address: string;
35
+ readonly chainId: number;
36
+ }): boolean;
37
+ /** True when `grant` is exactly a grant of the session owner's own secrets' keys (see `isSecretKeyResourceSet`). */
38
+ export declare function isSecretKeyGrant(grant: PortableDelegation, address: string): boolean;
39
+ /**
40
+ * Stores the panel's own grants and the owner's secret-key grants among `grants` for `address`, replacing a stored
41
+ * grant with the same cid. Other delegations (an app's larger grant that already covered the request) are never stored.
30
42
  */
31
43
  export declare function rememberRuntimeGrants(store: RuntimeGrantStore, address: string, grants: readonly PortableDelegation[], isCurrent?: () => boolean): Promise<void>;
32
44
  /**
@@ -592,12 +592,16 @@ export declare class TinyCloudWeb {
592
592
  *
593
593
  * An approved request that is not elevated (no decrypt or key creation, nothing in the secrets
594
594
  * space, no caveats) is kept with the session and active again after a page reload, with its own
595
- * signed expiry. An elevated one is not kept across a reload.
595
+ * signed expiry. An elevated one is not kept across a reload, except a grant made only of exact keys of the owner's
596
+ * own secrets (decrypt and/or key creation, any number of keys), which is kept for its signed expiry.
596
597
  */
597
598
  requestPermissions(additional: PermissionEntry[], options?: RequestPermissionsOptions): Promise<RequestPermissionsResult>;
598
599
  /** `requestPermissions`; `keep` stores the issued non-elevated grants beside the session. The panel stores its own. */
599
600
  private requestPermissionsKeeping;
600
- /** Records which app approved each grant, and stores the non-elevated ones when `keep`. */
601
+ /**
602
+ * Records which app approved each grant. A grant of one of the owner's secrets' own keys is always stored beside the
603
+ * session (TC-3284); the other non-elevated grants are stored when `keep`.
604
+ */
601
605
  private keepGrants;
602
606
  /**
603
607
  * The signer a valid `setRuntimePermissionSigner` call bound to the current session, or undefined. A signer bound to a
@@ -1 +1 @@
1
- (()=>{"use strict";var e={d:(s,i)=>{for(var t in i)e.o(i,t)&&!e.o(s,t)&&Object.defineProperty(s,t,{enumerable:!0,get:i[t]})},o:(e,s)=>Object.prototype.hasOwnProperty.call(e,s),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},s={};async function i(e,{graph:s,session:i,sessionExpiry:n,expanded:a,options:o}){const{lib:r}=e;if(!e.signer&&void 0===o?.signMessage)throw new Error("grantRuntimePermissions requires wallet mode with a signer or privateKey.");e.assertCaveats(a);const c=a.filter(s=>e.isEncryption(s)||e.isRawRevocation(s)),d=a.filter(s=>!e.isEncryption(s)&&!e.isRawRevocation(s)),g=new Map;for(const s of d){const t=e.resolveSpace(s.space,i),n=g.get(t)??[];n.push(s),g.set(t,n)}0===g.size&&c.length>0&&g.set(i.spaceId,[]);const l=[...g.keys()].filter(e=>{const s=r.parseSpaceUri(e);return void 0===s?.address||s.chainId!==String(i.chainId)||s.address!==r.canonicalizeAddress(i.address)});if(l.length>0)throw Object.assign(new Error(`Runtime permissions can only be granted in this account's own spaces, not ${l.join(", ")}.`),{code:"SPACE_NOT_OWNED",spaceIds:l});const p=new Date,h=r.expiryMs(o?.expiry);let u=new Date(p.getTime()+h);void 0!==n&&n<u&&(u=r.wholeSecond(n)),r.assertExpiry(u,"siwe");const w=[...g.keys()],f=w[0],v=Object.fromEntries([...g].map(([s,i])=>[s,e.abilities(i)])),m=(()=>{try{return e.wasm.prepareSession({abilities:v[f],...w.length>1?{spaceAbilities:v}:{},...c.length>0?{rawAbilities:t(e,c)}:{},address:e.wasm.ensureEip55(i.address),chainId:i.chainId,domain:e.domain,issuedAt:p.toISOString(),expirationTime:u.toISOString(),spaceId:f,jwk:i.jwk})}catch(s){if(c.some(s=>e.isRawRevocation(s))&&/invalid ReCap resource URI/i.test(s instanceof Error?s.message:String(s)))throw Object.assign(new Error("This WASM build cannot encode raw urn:cid ReCap resources."),{code:"RAW_RECAP_RESOURCE_UNSUPPORTED",cause:s});throw s}})();void 0!==o?.signMessage&&function(e,s,i){let t;try{t=new e.Siwe(s)}catch{throw new Error("The prepared sign-in message is not a valid SIWE message.")}if(t.prepareMessage()!==s)throw new Error("The prepared sign-in message is not in canonical form.");if(t.chainId!==i.chainId||e.canonicalizeAddress(t.address)!==e.canonicalizeAddress(i.address))throw new Error("The prepared sign-in message is for a different account or chain than this session.")}(r,m.siwe,i);const S=void 0!==o?.signMessage?await o.signMessage(m.siwe):await e.signer.signMessage(m.siwe);if(void 0!==o?.signMessage&&!await r.verifySignature(m.siwe,S,i.address))throw new Error("The signature does not match the account that owns this session.");s.assertActive();const E=e.wasm.completeSessionSetup({...m,signature:S});e.retainRoot({delegationHeader:E.delegationHeader,delegationCid:E.delegationCid,spaceId:f,address:i.address,chainId:i.chainId,siwe:m.siwe,signature:S});const R=(s,t)=>{const n=e.resources(t,s),a=n[0];return{cid:E.delegationCid,delegationHeader:E.delegationHeader,spaceId:s,path:a.path,actions:a.actions,resources:n,disableSubDelegation:!1,expiry:u,delegateDID:i.verificationMethod,ownerAddress:i.address,chainId:i.chainId,host:e.host,siweProof:{siwe:m.siwe,signature:S}}},y=await e.activate(E.delegationHeader,w.flatMap((s,i)=>e.activationResources(R(s,[...g.get(s),...0===i?c:[]]))),s.signal).catch(i=>{s.assertActive();const t=i instanceof r.PartialNodeWrite?i.failed.find(({cause:e})=>e instanceof r.ResourceNotRouted)?.cause:void 0;if(void 0!==t)throw t;const n=w.filter(e=>g.get(e).length>0),a=i instanceof r.NodeNotFound&&"registered"===i.verdict.status?i.verdict.record?.spaces.map(({space:e})=>e):void 0;if(void 0!==a&&0===c.length&&n.length>0&&n.every(s=>!a.some(i=>e.spaceIdsEqual(i,s))))throw new r.MissingSpaces(n,[]);throw i}),I=y.success?w.filter(s=>g.get(s).length>0&&y.skipped?.some(i=>e.spaceIdsEqual(i,s))):404===y.status?w.filter(e=>g.get(e).length>0):[];if(!y.success&&0===I.length){if(c.some(s=>e.isRawRevocation(s))&&401===y.status&&/Cannot find parent delegation/i.test(y.error??""))throw Object.assign(new Error("The host cannot activate a root raw-CID revoke authority without a parent delegation."),{code:"RAW_RECAP_RESOURCE_UNSUPPORTED",cause:y});throw Object.assign(new Error(`Failed to activate runtime permission delegation: ${r.describeFailure(y)}`),{cause:y})}s.assertActive();const b=y.success?w.find(e=>!I.includes(e))??(c.length>0?w[0]:void 0):void 0,M=[];for(const s of w){const t=[...I.includes(s)?[]:g.get(s),...s===b?c:[]];if(0===t.length)continue;const n=R(s,t);e.install({session:{delegationHeader:E.delegationHeader,delegationCid:E.delegationCid,spaceId:s,verificationMethod:i.verificationMethod,jwk:i.jwk},delegation:n,operations:e.operations(t,s),expiresAt:u,provenance:"runtime"}),M.push(n)}if(I.length>0)throw new r.MissingSpaces(I,M);return M}function t(e,s){const i={};for(const t of s){if(e.isRawRevocation(t)){i[t.space]=[...new Set(t.actions)];continue}if(!e.isEncryption(t))continue;const s=i[t.path]??[],n=new Set(s);for(const e of t.actions)n.has(e)||(s.push(e),n.add(e));i[t.path]=s}return i}e.r(s),e.d(s,{issueRuntimeGrants:()=>i}),module.exports=s})();
1
+ (()=>{"use strict";var e={d:(s,i)=>{for(var t in i)e.o(i,t)&&!e.o(s,t)&&Object.defineProperty(s,t,{enumerable:!0,get:i[t]})},o:(e,s)=>Object.prototype.hasOwnProperty.call(e,s),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},s={};async function i(e,{graph:s,session:i,sessionExpiry:n,expanded:a,options:o}){const{lib:r}=e;if(!e.signer&&void 0===o?.signMessage)throw new Error("grantRuntimePermissions requires wallet mode with a signer or privateKey.");e.assertCaveats(a);const c=a.filter(s=>e.isEncryption(s)||e.isRawRevocation(s)),d=a.filter(s=>!e.isEncryption(s)&&!e.isRawRevocation(s)),g=new Map;for(const s of d){const t=e.resolveSpace(s.space,i),n=g.get(t)??[];n.push(s),g.set(t,n)}0===g.size&&c.length>0&&g.set(i.spaceId,[]);const l=[...g.keys()].filter(e=>{const s=r.parseSpaceUri(e);return void 0===s?.address||s.chainId!==String(i.chainId)||s.address!==r.canonicalizeAddress(i.address)});if(l.length>0)throw Object.assign(new Error(`Runtime permissions can only be granted in this account's own spaces, not ${l.join(", ")}.`),{code:"SPACE_NOT_OWNED",spaceIds:l});const p=new Date,h=a.some(r.isSecretKey)?r.secretKeyExpiryMs(o?.expiry):r.expiryMs(o?.expiry);let u=new Date(p.getTime()+h);void 0!==n&&n<u&&(u=r.wholeSecond(n)),r.assertExpiry(u,"siwe");const w=[...g.keys()],f=w[0],v=Object.fromEntries([...g].map(([s,i])=>[s,e.abilities(i)])),m=(()=>{try{return e.wasm.prepareSession({abilities:v[f],...w.length>1?{spaceAbilities:v}:{},...c.length>0?{rawAbilities:t(e,c)}:{},address:e.wasm.ensureEip55(i.address),chainId:i.chainId,domain:e.domain,issuedAt:p.toISOString(),expirationTime:u.toISOString(),spaceId:f,jwk:i.jwk})}catch(s){if(c.some(s=>e.isRawRevocation(s))&&/invalid ReCap resource URI/i.test(s instanceof Error?s.message:String(s)))throw Object.assign(new Error("This WASM build cannot encode raw urn:cid ReCap resources."),{code:"RAW_RECAP_RESOURCE_UNSUPPORTED",cause:s});throw s}})();void 0!==o?.signMessage&&function(e,s,i){let t;try{t=new e.Siwe(s)}catch{throw new Error("The prepared sign-in message is not a valid SIWE message.")}if(t.prepareMessage()!==s)throw new Error("The prepared sign-in message is not in canonical form.");if(t.chainId!==i.chainId||e.canonicalizeAddress(t.address)!==e.canonicalizeAddress(i.address))throw new Error("The prepared sign-in message is for a different account or chain than this session.")}(r,m.siwe,i);const S=void 0!==o?.signMessage?await o.signMessage(m.siwe):await e.signer.signMessage(m.siwe);if(void 0!==o?.signMessage&&!await r.verifySignature(m.siwe,S,i.address))throw new Error("The signature does not match the account that owns this session.");s.assertActive();const y=e.wasm.completeSessionSetup({...m,signature:S});e.retainRoot({delegationHeader:y.delegationHeader,delegationCid:y.delegationCid,spaceId:f,address:i.address,chainId:i.chainId,siwe:m.siwe,signature:S});const E=(s,t)=>{const n=e.resources(t,s),a=n[0];return{cid:y.delegationCid,delegationHeader:y.delegationHeader,spaceId:s,path:a.path,actions:a.actions,resources:n,disableSubDelegation:!1,expiry:u,delegateDID:i.verificationMethod,ownerAddress:i.address,chainId:i.chainId,host:e.host,siweProof:{siwe:m.siwe,signature:S}}},R=await e.activate(y.delegationHeader,w.flatMap((s,i)=>e.activationResources(E(s,[...g.get(s),...0===i?c:[]]))),s.signal).catch(i=>{s.assertActive();const t=i instanceof r.PartialNodeWrite?i.failed.find(({cause:e})=>e instanceof r.ResourceNotRouted)?.cause:void 0;if(void 0!==t)throw t;const n=w.filter(e=>g.get(e).length>0),a=i instanceof r.NodeNotFound&&"registered"===i.verdict.status?i.verdict.record?.spaces.map(({space:e})=>e):void 0;if(void 0!==a&&0===c.length&&n.length>0&&n.every(s=>!a.some(i=>e.spaceIdsEqual(i,s))))throw new r.MissingSpaces(n,[]);throw i}),I=R.success?w.filter(s=>g.get(s).length>0&&R.skipped?.some(i=>e.spaceIdsEqual(i,s))):404===R.status?w.filter(e=>g.get(e).length>0):[];if(!R.success&&0===I.length){if(c.some(s=>e.isRawRevocation(s))&&401===R.status&&/Cannot find parent delegation/i.test(R.error??""))throw Object.assign(new Error("The host cannot activate a root raw-CID revoke authority without a parent delegation."),{code:"RAW_RECAP_RESOURCE_UNSUPPORTED",cause:R});throw Object.assign(new Error(`Failed to activate runtime permission delegation: ${r.describeFailure(R)}`),{cause:R})}s.assertActive();const b=R.success?w.find(e=>!I.includes(e))??(c.length>0?w[0]:void 0):void 0,M=[];for(const s of w){const t=[...I.includes(s)?[]:g.get(s),...s===b?c:[]];if(0===t.length)continue;const n=E(s,t);e.install({session:{delegationHeader:y.delegationHeader,delegationCid:y.delegationCid,spaceId:s,verificationMethod:i.verificationMethod,jwk:i.jwk},delegation:n,operations:e.operations(t,s),expiresAt:u,provenance:"runtime"}),M.push(n)}if(I.length>0)throw new r.MissingSpaces(I,M);return M}function t(e,s){const i={};for(const t of s){if(e.isRawRevocation(t)){i[t.space]=[...new Set(t.actions)];continue}if(!e.isEncryption(t))continue;const s=i[t.path]??[],n=new Set(s);for(const e of t.actions)n.has(e)||(s.push(e),n.add(e));i[t.path]=s}return i}e.r(s),e.d(s,{issueRuntimeGrants:()=>i}),module.exports=s})();
@@ -1 +1 @@
1
- var e={};async function s(e,{graph:s,session:t,sessionExpiry:n,expanded:a,options:o}){const{lib:r}=e;if(!e.signer&&void 0===o?.signMessage)throw new Error("grantRuntimePermissions requires wallet mode with a signer or privateKey.");e.assertCaveats(a);const c=a.filter(s=>e.isEncryption(s)||e.isRawRevocation(s)),d=a.filter(s=>!e.isEncryption(s)&&!e.isRawRevocation(s)),g=new Map;for(const s of d){const i=e.resolveSpace(s.space,t),n=g.get(i)??[];n.push(s),g.set(i,n)}0===g.size&&c.length>0&&g.set(t.spaceId,[]);const h=[...g.keys()].filter(e=>{const s=r.parseSpaceUri(e);return void 0===s?.address||s.chainId!==String(t.chainId)||s.address!==r.canonicalizeAddress(t.address)});if(h.length>0)throw Object.assign(new Error(`Runtime permissions can only be granted in this account's own spaces, not ${h.join(", ")}.`),{code:"SPACE_NOT_OWNED",spaceIds:h});const l=new Date,p=r.expiryMs(o?.expiry);let w=new Date(l.getTime()+p);void 0!==n&&n<w&&(w=r.wholeSecond(n)),r.assertExpiry(w,"siwe");const u=[...g.keys()],f=u[0],v=Object.fromEntries([...g].map(([s,i])=>[s,e.abilities(i)])),m=(()=>{try{return e.wasm.prepareSession({abilities:v[f],...u.length>1?{spaceAbilities:v}:{},...c.length>0?{rawAbilities:i(e,c)}:{},address:e.wasm.ensureEip55(t.address),chainId:t.chainId,domain:e.domain,issuedAt:l.toISOString(),expirationTime:w.toISOString(),spaceId:f,jwk:t.jwk})}catch(s){if(c.some(s=>e.isRawRevocation(s))&&/invalid ReCap resource URI/i.test(s instanceof Error?s.message:String(s)))throw Object.assign(new Error("This WASM build cannot encode raw urn:cid ReCap resources."),{code:"RAW_RECAP_RESOURCE_UNSUPPORTED",cause:s});throw s}})();void 0!==o?.signMessage&&function(e,s,i){let t;try{t=new e.Siwe(s)}catch{throw new Error("The prepared sign-in message is not a valid SIWE message.")}if(t.prepareMessage()!==s)throw new Error("The prepared sign-in message is not in canonical form.");if(t.chainId!==i.chainId||e.canonicalizeAddress(t.address)!==e.canonicalizeAddress(i.address))throw new Error("The prepared sign-in message is for a different account or chain than this session.")}(r,m.siwe,t);const E=void 0!==o?.signMessage?await o.signMessage(m.siwe):await e.signer.signMessage(m.siwe);if(void 0!==o?.signMessage&&!await r.verifySignature(m.siwe,E,t.address))throw new Error("The signature does not match the account that owns this session.");s.assertActive();const R=e.wasm.completeSessionSetup({...m,signature:E});e.retainRoot({delegationHeader:R.delegationHeader,delegationCid:R.delegationCid,spaceId:f,address:t.address,chainId:t.chainId,siwe:m.siwe,signature:E});const S=(s,i)=>{const n=e.resources(i,s),a=n[0];return{cid:R.delegationCid,delegationHeader:R.delegationHeader,spaceId:s,path:a.path,actions:a.actions,resources:n,disableSubDelegation:!1,expiry:w,delegateDID:t.verificationMethod,ownerAddress:t.address,chainId:t.chainId,host:e.host,siweProof:{siwe:m.siwe,signature:E}}},I=await e.activate(R.delegationHeader,u.flatMap((s,i)=>e.activationResources(S(s,[...g.get(s),...0===i?c:[]]))),s.signal).catch(i=>{s.assertActive();const t=i instanceof r.PartialNodeWrite?i.failed.find(({cause:e})=>e instanceof r.ResourceNotRouted)?.cause:void 0;if(void 0!==t)throw t;const n=u.filter(e=>g.get(e).length>0),a=i instanceof r.NodeNotFound&&"registered"===i.verdict.status?i.verdict.record?.spaces.map(({space:e})=>e):void 0;if(void 0!==a&&0===c.length&&n.length>0&&n.every(s=>!a.some(i=>e.spaceIdsEqual(i,s))))throw new r.MissingSpaces(n,[]);throw i}),y=I.success?u.filter(s=>g.get(s).length>0&&I.skipped?.some(i=>e.spaceIdsEqual(i,s))):404===I.status?u.filter(e=>g.get(e).length>0):[];if(!I.success&&0===y.length){if(c.some(s=>e.isRawRevocation(s))&&401===I.status&&/Cannot find parent delegation/i.test(I.error??""))throw Object.assign(new Error("The host cannot activate a root raw-CID revoke authority without a parent delegation."),{code:"RAW_RECAP_RESOURCE_UNSUPPORTED",cause:I});throw Object.assign(new Error(`Failed to activate runtime permission delegation: ${r.describeFailure(I)}`),{cause:I})}s.assertActive();const b=I.success?u.find(e=>!y.includes(e))??(c.length>0?u[0]:void 0):void 0,A=[];for(const s of u){const i=[...y.includes(s)?[]:g.get(s),...s===b?c:[]];if(0===i.length)continue;const n=S(s,i);e.install({session:{delegationHeader:R.delegationHeader,delegationCid:R.delegationCid,spaceId:s,verificationMethod:t.verificationMethod,jwk:t.jwk},delegation:n,operations:e.operations(i,s),expiresAt:w,provenance:"runtime"}),A.push(n)}if(y.length>0)throw new r.MissingSpaces(y,A);return A}function i(e,s){const i={};for(const t of s){if(e.isRawRevocation(t)){i[t.space]=[...new Set(t.actions)];continue}if(!e.isEncryption(t))continue;const s=i[t.path]??[],n=new Set(s);for(const e of t.actions)n.has(e)||(s.push(e),n.add(e));i[t.path]=s}return i}e.d=(s,i)=>{for(var t in i)e.o(i,t)&&!e.o(s,t)&&Object.defineProperty(s,t,{enumerable:!0,get:i[t]})},e.o=(e,s)=>Object.prototype.hasOwnProperty.call(e,s);export{s as issueRuntimeGrants};
1
+ var e={};async function s(e,{graph:s,session:t,sessionExpiry:n,expanded:a,options:o}){const{lib:r}=e;if(!e.signer&&void 0===o?.signMessage)throw new Error("grantRuntimePermissions requires wallet mode with a signer or privateKey.");e.assertCaveats(a);const c=a.filter(s=>e.isEncryption(s)||e.isRawRevocation(s)),d=a.filter(s=>!e.isEncryption(s)&&!e.isRawRevocation(s)),g=new Map;for(const s of d){const i=e.resolveSpace(s.space,t),n=g.get(i)??[];n.push(s),g.set(i,n)}0===g.size&&c.length>0&&g.set(t.spaceId,[]);const p=[...g.keys()].filter(e=>{const s=r.parseSpaceUri(e);return void 0===s?.address||s.chainId!==String(t.chainId)||s.address!==r.canonicalizeAddress(t.address)});if(p.length>0)throw Object.assign(new Error(`Runtime permissions can only be granted in this account's own spaces, not ${p.join(", ")}.`),{code:"SPACE_NOT_OWNED",spaceIds:p});const h=new Date,l=a.some(r.isSecretKey)?r.secretKeyExpiryMs(o?.expiry):r.expiryMs(o?.expiry);let w=new Date(h.getTime()+l);void 0!==n&&n<w&&(w=r.wholeSecond(n)),r.assertExpiry(w,"siwe");const u=[...g.keys()],f=u[0],v=Object.fromEntries([...g].map(([s,i])=>[s,e.abilities(i)])),m=(()=>{try{return e.wasm.prepareSession({abilities:v[f],...u.length>1?{spaceAbilities:v}:{},...c.length>0?{rawAbilities:i(e,c)}:{},address:e.wasm.ensureEip55(t.address),chainId:t.chainId,domain:e.domain,issuedAt:h.toISOString(),expirationTime:w.toISOString(),spaceId:f,jwk:t.jwk})}catch(s){if(c.some(s=>e.isRawRevocation(s))&&/invalid ReCap resource URI/i.test(s instanceof Error?s.message:String(s)))throw Object.assign(new Error("This WASM build cannot encode raw urn:cid ReCap resources."),{code:"RAW_RECAP_RESOURCE_UNSUPPORTED",cause:s});throw s}})();void 0!==o?.signMessage&&function(e,s,i){let t;try{t=new e.Siwe(s)}catch{throw new Error("The prepared sign-in message is not a valid SIWE message.")}if(t.prepareMessage()!==s)throw new Error("The prepared sign-in message is not in canonical form.");if(t.chainId!==i.chainId||e.canonicalizeAddress(t.address)!==e.canonicalizeAddress(i.address))throw new Error("The prepared sign-in message is for a different account or chain than this session.")}(r,m.siwe,t);const E=void 0!==o?.signMessage?await o.signMessage(m.siwe):await e.signer.signMessage(m.siwe);if(void 0!==o?.signMessage&&!await r.verifySignature(m.siwe,E,t.address))throw new Error("The signature does not match the account that owns this session.");s.assertActive();const R=e.wasm.completeSessionSetup({...m,signature:E});e.retainRoot({delegationHeader:R.delegationHeader,delegationCid:R.delegationCid,spaceId:f,address:t.address,chainId:t.chainId,siwe:m.siwe,signature:E});const S=(s,i)=>{const n=e.resources(i,s),a=n[0];return{cid:R.delegationCid,delegationHeader:R.delegationHeader,spaceId:s,path:a.path,actions:a.actions,resources:n,disableSubDelegation:!1,expiry:w,delegateDID:t.verificationMethod,ownerAddress:t.address,chainId:t.chainId,host:e.host,siweProof:{siwe:m.siwe,signature:E}}},y=await e.activate(R.delegationHeader,u.flatMap((s,i)=>e.activationResources(S(s,[...g.get(s),...0===i?c:[]]))),s.signal).catch(i=>{s.assertActive();const t=i instanceof r.PartialNodeWrite?i.failed.find(({cause:e})=>e instanceof r.ResourceNotRouted)?.cause:void 0;if(void 0!==t)throw t;const n=u.filter(e=>g.get(e).length>0),a=i instanceof r.NodeNotFound&&"registered"===i.verdict.status?i.verdict.record?.spaces.map(({space:e})=>e):void 0;if(void 0!==a&&0===c.length&&n.length>0&&n.every(s=>!a.some(i=>e.spaceIdsEqual(i,s))))throw new r.MissingSpaces(n,[]);throw i}),I=y.success?u.filter(s=>g.get(s).length>0&&y.skipped?.some(i=>e.spaceIdsEqual(i,s))):404===y.status?u.filter(e=>g.get(e).length>0):[];if(!y.success&&0===I.length){if(c.some(s=>e.isRawRevocation(s))&&401===y.status&&/Cannot find parent delegation/i.test(y.error??""))throw Object.assign(new Error("The host cannot activate a root raw-CID revoke authority without a parent delegation."),{code:"RAW_RECAP_RESOURCE_UNSUPPORTED",cause:y});throw Object.assign(new Error(`Failed to activate runtime permission delegation: ${r.describeFailure(y)}`),{cause:y})}s.assertActive();const b=y.success?u.find(e=>!I.includes(e))??(c.length>0?u[0]:void 0):void 0,A=[];for(const s of u){const i=[...I.includes(s)?[]:g.get(s),...s===b?c:[]];if(0===i.length)continue;const n=S(s,i);e.install({session:{delegationHeader:R.delegationHeader,delegationCid:R.delegationCid,spaceId:s,verificationMethod:t.verificationMethod,jwk:t.jwk},delegation:n,operations:e.operations(i,s),expiresAt:w,provenance:"runtime"}),A.push(n)}if(I.length>0)throw new r.MissingSpaces(I,A);return A}function i(e,s){const i={};for(const t of s){if(e.isRawRevocation(t)){i[t.space]=[...new Set(t.actions)];continue}if(!e.isEncryption(t))continue;const s=i[t.path]??[],n=new Set(s);for(const e of t.actions)n.has(e)||(s.push(e),n.add(e));i[t.path]=s}return i}e.d=(s,i)=>{for(var t in i)e.o(i,t)&&!e.o(s,t)&&Object.defineProperty(s,t,{enumerable:!0,get:i[t]})},e.o=(e,s)=>Object.prototype.hasOwnProperty.call(e,s);export{s as issueRuntimeGrants};
@@ -1 +1 @@
1
- (()=>{"use strict";var e={d:(t,r)=>{for(var a in r)e.o(r,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:r[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(e,t,r,i){if(!t)throw new Error("This delegated access was created without encryption.");const s=t.encryption();s.initialize(e),e.registerService("encryption",s),r.initialize(e);const n=t.vault(r,s);return n.initialize(e),{encryption:s,read:async e=>a(await n.readNetworkEncrypted(e),i)}}function a(e,t){if("ok"!==e.status){if("permission_required"===e.status){const r=t(e.hint);return void 0===r?{status:"read_failed"}:{status:"permission_required",hint:{service:r.service,...void 0===r.space?{}:{space:r.space},path:r.path,actions:[...r.actions]}}}return"aad_mismatch"===e.status?{status:"read_failed"}:{status:e.status}}return"object"==typeof(r=e.entry.value)&&null!==r&&"value"in r&&"string"==typeof r.value&&"createdAt"in r&&"string"==typeof r.createdAt&&"updatedAt"in r&&"string"==typeof r.updatedAt?{status:"ok",value:e.entry.value.value}:{status:"invalid_payload"};var r}e.r(t),e.d(t,{delegatedSecrets:()=>r,secretReadResult:()=>a}),module.exports=t})();
1
+ (()=>{"use strict";var e={d:(t,r)=>{for(var a in r)e.o(r,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:r[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(e,t,r,i){if(!t)throw new Error("This delegated access was created without encryption.");const s=t.encryption();s.initialize(e),e.registerService("encryption",s),r.initialize(e);const n=t.vault(r,s);return n.initialize(e),{encryption:s,read:async(e,t)=>a(await n.readNetworkEncrypted(e,t),i)}}function a(e,t){if("ok"!==e.status){if("permission_required"===e.status){const r=t(e.hint);return void 0===r?{status:"read_failed"}:{status:"permission_required",hint:{service:r.service,...void 0===r.space?{}:{space:r.space},path:r.path,actions:[...r.actions]}}}return"aad_mismatch"===e.status?{status:"read_failed"}:{status:e.status}}return"object"==typeof(r=e.entry.value)&&null!==r&&"value"in r&&"string"==typeof r.value&&"createdAt"in r&&"string"==typeof r.createdAt&&"updatedAt"in r&&"string"==typeof r.updatedAt?{status:"ok",value:e.entry.value.value}:{status:"invalid_payload"};var r}e.r(t),e.d(t,{delegatedSecrets:()=>r,secretReadResult:()=>a}),module.exports=t})();
@@ -1 +1 @@
1
- var t={};function e(t,e,i,r){if(!e)throw new Error("This delegated access was created without encryption.");const n=e.encryption();n.initialize(t),t.registerService("encryption",n),i.initialize(t);const s=e.vault(i,n);return s.initialize(t),{encryption:n,read:async t=>a(await s.readNetworkEncrypted(t),r)}}function a(t,e){if("ok"!==t.status){if("permission_required"===t.status){const a=e(t.hint);return void 0===a?{status:"read_failed"}:{status:"permission_required",hint:{service:a.service,...void 0===a.space?{}:{space:a.space},path:a.path,actions:[...a.actions]}}}return"aad_mismatch"===t.status?{status:"read_failed"}:{status:t.status}}return"object"==typeof(a=t.entry.value)&&null!==a&&"value"in a&&"string"==typeof a.value&&"createdAt"in a&&"string"==typeof a.createdAt&&"updatedAt"in a&&"string"==typeof a.updatedAt?{status:"ok",value:t.entry.value.value}:{status:"invalid_payload"};var a}t.d=(e,a)=>{for(var i in a)t.o(a,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:a[i]})},t.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);export{e as delegatedSecrets,a as secretReadResult};
1
+ var t={};function e(t,e,i,r){if(!e)throw new Error("This delegated access was created without encryption.");const n=e.encryption();n.initialize(t),t.registerService("encryption",n),i.initialize(t);const s=e.vault(i,n);return s.initialize(t),{encryption:n,read:async(t,e)=>a(await s.readNetworkEncrypted(t,e),r)}}function a(t,e){if("ok"!==t.status){if("permission_required"===t.status){const a=e(t.hint);return void 0===a?{status:"read_failed"}:{status:"permission_required",hint:{service:a.service,...void 0===a.space?{}:{space:a.space},path:a.path,actions:[...a.actions]}}}return"aad_mismatch"===t.status?{status:"read_failed"}:{status:t.status}}return"object"==typeof(a=t.entry.value)&&null!==a&&"value"in a&&"string"==typeof a.value&&"createdAt"in a&&"string"==typeof a.createdAt&&"updatedAt"in a&&"string"==typeof a.updatedAt?{status:"ok",value:t.entry.value.value}:{status:"invalid_payload"};var a}t.d=(e,a)=>{for(var i in a)t.o(a,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:a[i]})},t.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);export{e as delegatedSecrets,a as secretReadResult};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinycloud/web-sdk",
3
- "version": "3.14.0-beta.14",
3
+ "version": "3.14.0-beta.16",
4
4
  "description": "A set of tools and utilities to help you build your app with TinyCloud.",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -67,9 +67,9 @@
67
67
  "@multiformats/multiaddr": "^13.0.1",
68
68
  "@multiformats/multiaddr-to-uri": "^12.0.0",
69
69
  "@noble/curves": "^1.9.7",
70
- "@tinycloud/node-sdk": "3.14.0-beta.14",
71
- "@tinycloud/replica": "0.4.7-beta.1",
72
- "@tinycloud/sdk-core": "3.14.0-beta.14",
70
+ "@tinycloud/node-sdk": "3.14.0-beta.16",
71
+ "@tinycloud/replica": "0.4.7-beta.2",
72
+ "@tinycloud/sdk-core": "3.14.0-beta.15",
73
73
  "@tinycloud/share-envelope": "1.6.0",
74
74
  "@tinycloud/share-sdk": "1.6.0",
75
75
  "@tinycloud/web-sdk-wasm": "1.8.0-beta.0",