@tinycloud/web-sdk 3.14.0-beta.6 → 3.14.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/adapters/BrowserWasmBindings.d.ts +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/modules/browserSessionPersistence.d.ts +2 -0
- package/dist/modules/tcw.d.ts +12 -0
- package/dist/runtime-grants.cjs +1 -1
- package/dist/runtime-grants.mjs +1 -1
- package/dist/session-retire-entry.d.ts +3 -0
- package/dist/session-retire.cjs +1 -0
- package/dist/session-retire.mjs +1 -0
- package/package.json +4 -4
|
@@ -18,6 +18,8 @@ export interface RestorableSessionData {
|
|
|
18
18
|
* before this field existed; in that case the node re-resolves lazily.
|
|
19
19
|
*/
|
|
20
20
|
tinycloudHosts?: string[];
|
|
21
|
+
/** Hosts the session's delegations were posted to; sign-out retires the key on each. */
|
|
22
|
+
activatedHosts?: string[];
|
|
21
23
|
/** Replica gate stamp from sign-in; `node.restoreSession` validates it against the gate. */
|
|
22
24
|
replicaStamp?: PersistedSessionData["replicaStamp"];
|
|
23
25
|
}
|
package/dist/modules/tcw.d.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* @packageDocumentation
|
|
11
11
|
*/
|
|
12
12
|
import { TinyCloudNode, TinyCloudNodeConfig, type OpenKeyAuthorizeTinyCloud, type BootstrapWarning, type DelegateToOptions, type DelegateToResult, type ISessionStorage, type SignStrategy, type ValidatedRuntimeDelegation, type UnifiedOwnerRootInput, type UnifiedOwnerRootReceipt, type RegisterPolicyV3Input, type RegisterPolicyV3Receipt } from "@tinycloud/node-sdk/core";
|
|
13
|
+
import type { NodeSignOutStatus } from "@tinycloud/node-sdk";
|
|
13
14
|
import { type LocalCopyPurgeFailedEvent } from "./replica-wiring";
|
|
14
15
|
import { IKVService, ISQLService, IDuckDbService, IDataVaultService, ISecretsService, ISpaceService, ISpace, ISharingService, ICapabilityKeyRegistry, IHooksService, IEncryptionService, DelegationManager, Delegation, DelegationRevocationReceipt, Result, DelegationError, ClientSession, Extension, type TelemetryConfig, type RetryPolicy, ISpaceCreationHandler, type Manifest, type ComposedManifestRequest, type AccountService, type ResolvedDelegate, type PermissionEntry, type NetworkDescriptor, type CreateOwnerDelegationParams, type OwnerDelegationReceipt, type LocalNodeIdentityStore, type OnNodeNotFound, type RegistrySequenceStore, SignInOptions, type RegistryCacheStore, type StorageFullEvent, type IStorageService } from "@tinycloud/sdk-core";
|
|
15
16
|
import { type RequestPermissionsOptions } from "./requestPermissionsCore";
|
|
@@ -238,6 +239,8 @@ export declare class TinyCloudWeb {
|
|
|
238
239
|
private runtimeSigner?;
|
|
239
240
|
private signOutInFlight;
|
|
240
241
|
private signOutOperation?;
|
|
242
|
+
/** The node the latest sign-out ended; it holds that sign-out's node status. */
|
|
243
|
+
private signedOutNode?;
|
|
241
244
|
private persistedRestoreBlocked;
|
|
242
245
|
private signOutCleanupFailed;
|
|
243
246
|
private remoteSignOutTimeoutMs;
|
|
@@ -274,6 +277,8 @@ export declare class TinyCloudWeb {
|
|
|
274
277
|
private _testHooks?;
|
|
275
278
|
constructor(callerConfig?: Config);
|
|
276
279
|
private bootstrapSignInPolicy;
|
|
280
|
+
/** Outside a browser, an app with no domain and no manifest gets the folder every such app shares. */
|
|
281
|
+
private warnIfWithoutAppHost;
|
|
277
282
|
/**
|
|
278
283
|
* Async initialization: ensure WASM is ready, then create TinyCloudNode.
|
|
279
284
|
* @internal
|
|
@@ -441,6 +446,13 @@ export declare class TinyCloudWeb {
|
|
|
441
446
|
* unavailable until a fresh sign-in; prior persisted sessions cannot restore.
|
|
442
447
|
*/
|
|
443
448
|
signOut: () => Promise<void>;
|
|
449
|
+
/**
|
|
450
|
+
* Which nodes stopped accepting the session key at the latest sign-out that ended a session; see
|
|
451
|
+
* `TinyCloudNode.nodeSignOutStatus()`. Resolves `undefined` before any. `signOut()` does not wait for these node
|
|
452
|
+
* calls, and only a node's first request, within a 48 KiB keepalive allowance, may outlive a page that unloads
|
|
453
|
+
* right after it, once the retire code (loaded when the session starts) has loaded.
|
|
454
|
+
*/
|
|
455
|
+
nodeSignOutStatus: () => Promise<NodeSignOutStatus | undefined>;
|
|
444
456
|
/**
|
|
445
457
|
* Clears the stored session for `address` only while it is the signing-out session (`ownSignature`); a newer
|
|
446
458
|
* session saved for the same address is left alone. The session is fenced first, so that a clear that fails
|
package/dist/runtime-grants.cjs
CHANGED
|
@@ -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}),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}),
|
|
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})();
|
package/dist/runtime-grants.mjs
CHANGED
|
@@ -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
|
|
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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(()=>{"use strict";var e={d:(t,o)=>{for(var n in o)e.o(o,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:o[n]})},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={};e.r(t),e.d(t,{retireLeavingSession:()=>h});var o="urn:tinycloud:session:self",n="tinycloud.session/retire",a=3,i=[250,1e3],s=5e3,r=8,d=49152,c=e=>e.trim().slice(0,200)||void 0,l=e=>429===e||503===e;async function f(e,t,o){try{return await e(t,{...o,redirect:"error",signal:AbortSignal.timeout(s)})}catch(e){return{reason:"unreachable",message:c(e instanceof Error?e.message:String(e)),retry:!0}}}async function u(e,t,a,i,s){const r=e.fetch;if(!a.value){const e=await f(r,`${t}/info`,{});if(!(e instanceof Response))return e;const o=e.ok?(await e.json().catch(()=>{}))?.nodeId:void 0;if("string"!=typeof o||!o)return{reason:"failed",status:e.status,retry:l(e.status)};a.value=o}let d;try{d=await e.signer.signJwt({alg:"EdDSA",typ:"JWT",ucv:"0.10.0"},{iss:e.signer.verificationMethod,aud:a.value,exp:Math.floor((e.now??Date.now)()/1e3)+60,nnc:crypto.randomUUID(),prf:[],att:{[o]:{[n]:[{}]}}})}catch(e){return{reason:"failed",message:c(String(e))}}const u=i.length?JSON.stringify({delegations:i}):void 0,g=void 0!==s&&(u?.length??0)<=s.bytes;g&&(s.bytes-=u?.length??0);const h=await f(r,`${t}/session/retire`,{method:"POST",headers:i.length?{Authorization:`Bearer ${d}`,"Content-Type":"application/json"}:{Authorization:`Bearer ${d}`},body:u,keepalive:g});if(!(h instanceof Response))return h;if(h.ok)return!0===(await h.json().catch(()=>{}))?.recorded;const p=await h.text().catch(()=>""),y={reason:"failed",status:h.status,message:c(p),retry:l(h.status)};if(404===h.status&&(y.reason="unsupported"),401===h.status){y.reason="refused";const e=/^session_retire_invalid: delegation (\d+):/.exec(p)?.[1];e&&(y.delegation=Number(e))}return y}async function g(e,t,o){const n={value:e.knownNodeIds?.get(t)},s=[...new Set(e.delegations??[])],d=e.sleep??(e=>new Promise(t=>setTimeout(t,e))),c=async s=>{let r=!1;for(let c=0;c<a&&(c>0&&await d(i[c-1]),r=await u(e,t,n,s,0===c?o:void 0),"boolean"!=typeof r&&r.retry);c++);if("boolean"==typeof r)return r;const{retry:c,...l}=r;return l};let l,f=!0;for(let e=0;0===e||e<s.length;e+=r){const t=s.slice(e,e+r);let o=await c(t);if("boolean"!=typeof o&&void 0!==o.delegation&&!l){const n=o.delegation;l={...o,delegation:e+n},o=await c(t.filter((e,t)=>t!==n)),"boolean"!=typeof o&&void 0!==o.delegation&&o.delegation>=n&&(o.delegation+=1)}if("boolean"!=typeof o)return void 0!==o.delegation&&(o.delegation+=e),o;f&&(f=o)}return l??f}function h(e){const t=[...e.roots];for(const o of e.grants)void 0!==o.siweProof&&t.push({delegationHeader:o.delegationHeader,delegationCid:o.cid,spaceId:o.spaceId,address:o.ownerAddress,chainId:o.chainId,siwe:o.siweProof.siwe,signature:o.siweProof.signature});const o=new Map;for(const{verificationMethod:t,jwk:n}of e.keys)o.has(t)||o.set(t,n);return async function(e){const t={bytes:d},o=await Promise.all(e.map(e=>(e={...e,fetch:e.fetch??globalThis.fetch.bind(globalThis)},Promise.all([...new Set(e.hosts)].map(async o=>[o,await g(e,o,t).catch(e=>({reason:"failed",message:c(String(e))}))]))))),n={confirmed:[],nothingToRecord:[],notConfirmed:[]};for(const t of new Set(e.flatMap(e=>e.hosts))){const e=o.flatMap(e=>e.filter(([e])=>e===t).map(([,e])=>e)),a=e.find(e=>"boolean"!=typeof e);a?n.notConfirmed.push({host:t,...a}):e.includes(!0)?n.confirmed.push(t):n.nothingToRecord.push(t)}return n}([...o].map(([o,n])=>{const a=new Set;for(const o of t){const t=o.delegationHeader.Authorization;if(!a.has(t)&&e.validate)try{e.validate({delegationHeader:{Authorization:t},delegationCid:o.delegationCid,spaceId:o.spaceId,jwk:n,address:e.canonicalizeAddress(o.address),chainId:o.chainId,siwe:o.siwe,signature:o.signature}),a.add(t)}catch{}}return{signer:{verificationMethod:o,signJwt:async(t,o)=>{const a=`${p(JSON.stringify(t))}.${p(JSON.stringify(o))}`;return`${a}.${p(await e.signBytes((new TextEncoder).encode(a),n))}`}},hosts:e.hosts,delegations:[...a],knownNodeIds:e.knownNodeIds}}))}function p(e){let t="";for(const o of"string"==typeof e?(new TextEncoder).encode(e):e)t+=String.fromCharCode(o);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}module.exports=t})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e="urn:tinycloud:session:self",t="tinycloud.session/retire",n=[250,1e3],o=e=>e.trim().slice(0,200)||void 0,a=e=>429===e||503===e;async function s(e,t,n){try{return await e(t,{...n,redirect:"error",signal:AbortSignal.timeout(5e3)})}catch(e){return{reason:"unreachable",message:o(e instanceof Error?e.message:String(e)),retry:!0}}}async function i(n,i,r,d,c){const l=n.fetch;if(!r.value){const e=await s(l,`${i}/info`,{});if(!(e instanceof Response))return e;const t=e.ok?(await e.json().catch(()=>{}))?.nodeId:void 0;if("string"!=typeof t||!t)return{reason:"failed",status:e.status,retry:a(e.status)};r.value=t}let f;try{f=await n.signer.signJwt({alg:"EdDSA",typ:"JWT",ucv:"0.10.0"},{iss:n.signer.verificationMethod,aud:r.value,exp:Math.floor((n.now??Date.now)()/1e3)+60,nnc:crypto.randomUUID(),prf:[],att:{[e]:{[t]:[{}]}}})}catch(e){return{reason:"failed",message:o(String(e))}}const g=d.length?JSON.stringify({delegations:d}):void 0,u=void 0!==c&&(g?.length??0)<=c.bytes;u&&(c.bytes-=g?.length??0);const h=await s(l,`${i}/session/retire`,{method:"POST",headers:d.length?{Authorization:`Bearer ${f}`,"Content-Type":"application/json"}:{Authorization:`Bearer ${f}`},body:g,keepalive:u});if(!(h instanceof Response))return h;if(h.ok)return!0===(await h.json().catch(()=>{}))?.recorded;const p=await h.text().catch(()=>""),w={reason:"failed",status:h.status,message:o(p),retry:a(h.status)};if(404===h.status&&(w.reason="unsupported"),401===h.status){w.reason="refused";const e=/^session_retire_invalid: delegation (\d+):/.exec(p)?.[1];e&&(w.delegation=Number(e))}return w}async function r(e,t,o){const a={value:e.knownNodeIds?.get(t)},s=[...new Set(e.delegations??[])],r=e.sleep??(e=>new Promise(t=>setTimeout(t,e))),d=async s=>{let d=!1;for(let c=0;c<3&&(c>0&&await r(n[c-1]),d=await i(e,t,a,s,0===c?o:void 0),"boolean"!=typeof d&&d.retry);c++);if("boolean"==typeof d)return d;const{retry:c,...l}=d;return l};let c,l=!0;for(let e=0;0===e||e<s.length;e+=8){const t=s.slice(e,e+8);let n=await d(t);if("boolean"!=typeof n&&void 0!==n.delegation&&!c){const o=n.delegation;c={...n,delegation:e+o},n=await d(t.filter((e,t)=>t!==o)),"boolean"!=typeof n&&void 0!==n.delegation&&n.delegation>=o&&(n.delegation+=1)}if("boolean"!=typeof n)return void 0!==n.delegation&&(n.delegation+=e),n;l&&(l=n)}return c??l}function d(e){const t=[...e.roots];for(const n of e.grants)void 0!==n.siweProof&&t.push({delegationHeader:n.delegationHeader,delegationCid:n.cid,spaceId:n.spaceId,address:n.ownerAddress,chainId:n.chainId,siwe:n.siweProof.siwe,signature:n.siweProof.signature});const n=new Map;for(const{verificationMethod:t,jwk:o}of e.keys)n.has(t)||n.set(t,o);return async function(e){const t={bytes:49152},n=await Promise.all(e.map(e=>(e={...e,fetch:e.fetch??globalThis.fetch.bind(globalThis)},Promise.all([...new Set(e.hosts)].map(async n=>[n,await r(e,n,t).catch(e=>({reason:"failed",message:o(String(e))}))]))))),a={confirmed:[],nothingToRecord:[],notConfirmed:[]};for(const t of new Set(e.flatMap(e=>e.hosts))){const e=n.flatMap(e=>e.filter(([e])=>e===t).map(([,e])=>e)),o=e.find(e=>"boolean"!=typeof e);o?a.notConfirmed.push({host:t,...o}):e.includes(!0)?a.confirmed.push(t):a.nothingToRecord.push(t)}return a}([...n].map(([n,o])=>{const a=new Set;for(const n of t){const t=n.delegationHeader.Authorization;if(!a.has(t)&&e.validate)try{e.validate({delegationHeader:{Authorization:t},delegationCid:n.delegationCid,spaceId:n.spaceId,jwk:o,address:e.canonicalizeAddress(n.address),chainId:n.chainId,siwe:n.siwe,signature:n.signature}),a.add(t)}catch{}}return{signer:{verificationMethod:n,signJwt:async(t,n)=>{const a=`${c(JSON.stringify(t))}.${c(JSON.stringify(n))}`;return`${a}.${c(await e.signBytes((new TextEncoder).encode(a),o))}`}},hosts:e.hosts,delegations:[...a],knownNodeIds:e.knownNodeIds}}))}function c(e){let t="";for(const n of"string"==typeof e?(new TextEncoder).encode(e):e)t+=String.fromCharCode(n);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}export{d as retireLeavingSession};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinycloud/web-sdk",
|
|
3
|
-
"version": "3.14.0-beta.
|
|
3
|
+
"version": "3.14.0-beta.8",
|
|
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,12 +67,12 @@
|
|
|
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.
|
|
70
|
+
"@tinycloud/node-sdk": "3.14.0-beta.8",
|
|
71
71
|
"@tinycloud/replica": "0.4.7-beta.0",
|
|
72
|
-
"@tinycloud/sdk-core": "3.14.0-beta.
|
|
72
|
+
"@tinycloud/sdk-core": "3.14.0-beta.8",
|
|
73
73
|
"@tinycloud/share-envelope": "1.6.0",
|
|
74
74
|
"@tinycloud/share-sdk": "1.6.0",
|
|
75
|
-
"@tinycloud/web-sdk-wasm": "1.
|
|
75
|
+
"@tinycloud/web-sdk-wasm": "1.8.0-beta.0",
|
|
76
76
|
"axios": "^1.7.9",
|
|
77
77
|
"viem": "^2.45.0",
|
|
78
78
|
"zod": "^3.22.0"
|