@tinycloudlabs/node-sdk 1.0.0
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/LICENSE.md +320 -0
- package/dist/DelegatedAccess.d.ts +33 -0
- package/dist/DelegatedAccess.d.ts.map +1 -0
- package/dist/DelegatedAccess.js +61 -0
- package/dist/DelegatedAccess.js.map +1 -0
- package/dist/TinyCloudNode.d.ts +441 -0
- package/dist/TinyCloudNode.d.ts.map +1 -0
- package/dist/TinyCloudNode.js +987 -0
- package/dist/TinyCloudNode.js.map +1 -0
- package/dist/authorization/NodeUserAuthorization.d.ts +200 -0
- package/dist/authorization/NodeUserAuthorization.d.ts.map +1 -0
- package/dist/authorization/NodeUserAuthorization.js +516 -0
- package/dist/authorization/NodeUserAuthorization.js.map +1 -0
- package/dist/authorization/strategies.d.ts +57 -0
- package/dist/authorization/strategies.d.ts.map +1 -0
- package/dist/authorization/strategies.js +15 -0
- package/dist/authorization/strategies.js.map +1 -0
- package/dist/delegation.d.ts +35 -0
- package/dist/delegation.d.ts.map +1 -0
- package/dist/delegation.js +21 -0
- package/dist/delegation.js.map +1 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +73 -0
- package/dist/index.js.map +1 -0
- package/dist/keys/WasmKeyProvider.d.ts +101 -0
- package/dist/keys/WasmKeyProvider.d.ts.map +1 -0
- package/dist/keys/WasmKeyProvider.js +113 -0
- package/dist/keys/WasmKeyProvider.js.map +1 -0
- package/dist/keys/index.d.ts +7 -0
- package/dist/keys/index.d.ts.map +1 -0
- package/dist/keys/index.js +7 -0
- package/dist/keys/index.js.map +1 -0
- package/dist/signers/PrivateKeySigner.d.ts +47 -0
- package/dist/signers/PrivateKeySigner.d.ts.map +1 -0
- package/dist/signers/PrivateKeySigner.js +89 -0
- package/dist/signers/PrivateKeySigner.js.map +1 -0
- package/dist/storage/FileSessionStorage.d.ts +59 -0
- package/dist/storage/FileSessionStorage.d.ts.map +1 -0
- package/dist/storage/FileSessionStorage.js +148 -0
- package/dist/storage/FileSessionStorage.js.map +1 -0
- package/dist/storage/MemorySessionStorage.d.ts +49 -0
- package/dist/storage/MemorySessionStorage.d.ts.map +1 -0
- package/dist/storage/MemorySessionStorage.js +88 -0
- package/dist/storage/MemorySessionStorage.js.map +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialize a PortableDelegation for transport (e.g., over network).
|
|
3
|
+
*/
|
|
4
|
+
export function serializeDelegation(delegation) {
|
|
5
|
+
return JSON.stringify({
|
|
6
|
+
...delegation,
|
|
7
|
+
expiry: delegation.expiry.toISOString(),
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Deserialize a PortableDelegation from transport.
|
|
12
|
+
*/
|
|
13
|
+
export function deserializeDelegation(data) {
|
|
14
|
+
const parsed = JSON.parse(data);
|
|
15
|
+
return {
|
|
16
|
+
...parsed,
|
|
17
|
+
cid: parsed.cid,
|
|
18
|
+
expiry: new Date(parsed.expiry),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=delegation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delegation.js","sourceRoot":"","sources":["../src/delegation.ts"],"names":[],"mappings":"AA8BA;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,UAA8B;IAChE,OAAO,IAAI,CAAC,SAAS,CAAC;QACpB,GAAG,UAAU;QACb,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,WAAW,EAAE;KACxC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAChC,OAAO;QACL,GAAG,MAAM;QACT,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,MAAM,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;KAChC,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tinycloudlabs/node-sdk
|
|
3
|
+
*
|
|
4
|
+
* TinyCloud SDK for Node.js environments.
|
|
5
|
+
*
|
|
6
|
+
* This package provides Node.js-specific implementations of the TinyCloud SDK:
|
|
7
|
+
* - PrivateKeySigner: Sign messages using a private key
|
|
8
|
+
* - NodeUserAuthorization: Authorize users with configurable sign strategies
|
|
9
|
+
* - MemorySessionStorage: Store sessions in memory
|
|
10
|
+
* - FileSessionStorage: Persist sessions to the file system
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { TinyCloud } from '@tinycloudlabs/sdk-core';
|
|
15
|
+
* import {
|
|
16
|
+
* NodeUserAuthorization,
|
|
17
|
+
* PrivateKeySigner,
|
|
18
|
+
* FileSessionStorage,
|
|
19
|
+
* } from '@tinycloudlabs/node-sdk';
|
|
20
|
+
*
|
|
21
|
+
* const signer = new PrivateKeySigner(process.env.PRIVATE_KEY);
|
|
22
|
+
* const auth = new NodeUserAuthorization({
|
|
23
|
+
* signer,
|
|
24
|
+
* signStrategy: { type: 'auto-sign' },
|
|
25
|
+
* domain: 'api.myapp.com',
|
|
26
|
+
* sessionStorage: new FileSessionStorage('/tmp/sessions'),
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* const tc = new TinyCloud(auth);
|
|
30
|
+
* await tc.signIn();
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @packageDocumentation
|
|
34
|
+
*/
|
|
35
|
+
export { TinyCloud, TinyCloudConfig, ISigner, ISessionStorage, IUserAuthorization, ClientSession, Extension, PersistedSessionData, TinyCloudSession, } from "@tinycloudlabs/sdk-core";
|
|
36
|
+
export { PrivateKeySigner } from "./signers/PrivateKeySigner";
|
|
37
|
+
export { MemorySessionStorage } from "./storage/MemorySessionStorage";
|
|
38
|
+
export { FileSessionStorage } from "./storage/FileSessionStorage";
|
|
39
|
+
export { NodeUserAuthorization, NodeUserAuthorizationConfig, } from "./authorization/NodeUserAuthorization";
|
|
40
|
+
export { SignRequest, SignResponse, SignCallback, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, defaultSignStrategy, NodeEventEmitterStrategy, SignStrategy, } from "./authorization/strategies";
|
|
41
|
+
export { TinyCloudNode, TinyCloudNodeConfig } from "./TinyCloudNode";
|
|
42
|
+
export { DelegatedAccess } from "./DelegatedAccess";
|
|
43
|
+
export { PortableDelegation, serializeDelegation, deserializeDelegation, } from "./delegation";
|
|
44
|
+
export { IKVService, KVService, KVServiceConfig, KVResponse, PrefixedKVService, IPrefixedKVService, } from "@tinycloudlabs/sdk-core";
|
|
45
|
+
export { DelegationManager, DelegationManagerConfig, SharingService, ISharingService, SharingServiceConfig, createSharingService, EncodedShareData, ReceiveOptions, ShareAccess, Delegation, CreateDelegationParams, DelegationChain, DelegationChainV2, DelegationDirection, DelegationFilters, DelegationResult, DelegationError, DelegationErrorCodes, DelegationErrorCode, JWK, KeyType, KeyInfo, CapabilityEntry, DelegationRecord, SpaceOwnership, SpaceInfo, ShareSchema, ShareLink, ShareLinkData, IngestOptions, GenerateShareParams, } from "@tinycloudlabs/sdk-core";
|
|
46
|
+
export { CapabilityKeyRegistry, ICapabilityKeyRegistry, createCapabilityKeyRegistry, StoredDelegationChain, CapabilityKeyRegistryErrorCodes, CapabilityKeyRegistryErrorCode, } from "@tinycloudlabs/sdk-core";
|
|
47
|
+
export { SpaceService, ISpaceService, SpaceServiceConfig, SpaceErrorCodes, SpaceErrorCode, createSpaceService, parseSpaceUri, buildSpaceUri, Space, ISpace, SpaceConfig, ISpaceScopedDelegations, ISpaceScopedSharing, } from "@tinycloudlabs/sdk-core";
|
|
48
|
+
export { ProtocolMismatchError, VersionCheckError, checkNodeVersion, } from "@tinycloudlabs/sdk-core";
|
|
49
|
+
export { ServiceContext, ServiceContextConfig, ServiceSession, InvokeFunction, FetchFunction, } from "@tinycloudlabs/sdk-core";
|
|
50
|
+
export type { KeyProvider } from "@tinycloudlabs/sdk-core";
|
|
51
|
+
export { WasmKeyProvider, WasmKeyProviderConfig, createWasmKeyProvider, } from "./keys/WasmKeyProvider";
|
|
52
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAGH,OAAO,EACL,SAAS,EACT,eAAe,EACf,OAAO,EACP,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,SAAS,EACT,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAG9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAGlE,OAAO,EACL,qBAAqB,EACrB,2BAA2B,GAC5B,MAAM,uCAAuC,CAAC;AAG/C,OAAO,EAEL,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EAEnB,wBAAwB,EACxB,YAAY,GACb,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAGrE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,UAAU,EACV,SAAS,EACT,eAAe,EACf,UAAU,EAEV,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAEL,iBAAiB,EACjB,uBAAuB,EAEvB,cAAc,EACd,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAChB,cAAc,EACd,WAAW,EAEX,UAAU,EACV,sBAAsB,EACtB,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EAEjB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACpB,mBAAmB,EAEnB,GAAG,EACH,OAAO,EACP,OAAO,EACP,eAAe,EACf,gBAAgB,EAEhB,cAAc,EACd,SAAS,EAET,WAAW,EACX,SAAS,EACT,aAAa,EACb,aAAa,EACb,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,2BAA2B,EAC3B,qBAAqB,EACrB,+BAA+B,EAC/B,8BAA8B,GAC/B,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EACL,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,aAAa,EAEb,KAAK,EACL,MAAM,EACN,WAAW,EACX,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,cAAc,EACd,cAAc,EACd,aAAa,GACd,MAAM,yBAAyB,CAAC;AAGjC,YAAY,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAG3D,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,wBAAwB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tinycloudlabs/node-sdk
|
|
3
|
+
*
|
|
4
|
+
* TinyCloud SDK for Node.js environments.
|
|
5
|
+
*
|
|
6
|
+
* This package provides Node.js-specific implementations of the TinyCloud SDK:
|
|
7
|
+
* - PrivateKeySigner: Sign messages using a private key
|
|
8
|
+
* - NodeUserAuthorization: Authorize users with configurable sign strategies
|
|
9
|
+
* - MemorySessionStorage: Store sessions in memory
|
|
10
|
+
* - FileSessionStorage: Persist sessions to the file system
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { TinyCloud } from '@tinycloudlabs/sdk-core';
|
|
15
|
+
* import {
|
|
16
|
+
* NodeUserAuthorization,
|
|
17
|
+
* PrivateKeySigner,
|
|
18
|
+
* FileSessionStorage,
|
|
19
|
+
* } from '@tinycloudlabs/node-sdk';
|
|
20
|
+
*
|
|
21
|
+
* const signer = new PrivateKeySigner(process.env.PRIVATE_KEY);
|
|
22
|
+
* const auth = new NodeUserAuthorization({
|
|
23
|
+
* signer,
|
|
24
|
+
* signStrategy: { type: 'auto-sign' },
|
|
25
|
+
* domain: 'api.myapp.com',
|
|
26
|
+
* sessionStorage: new FileSessionStorage('/tmp/sessions'),
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* const tc = new TinyCloud(auth);
|
|
30
|
+
* await tc.signIn();
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @packageDocumentation
|
|
34
|
+
*/
|
|
35
|
+
// Re-export core types for convenience
|
|
36
|
+
export { TinyCloud, } from "@tinycloudlabs/sdk-core";
|
|
37
|
+
// Signers
|
|
38
|
+
export { PrivateKeySigner } from "./signers/PrivateKeySigner";
|
|
39
|
+
// Storage implementations
|
|
40
|
+
export { MemorySessionStorage } from "./storage/MemorySessionStorage";
|
|
41
|
+
export { FileSessionStorage } from "./storage/FileSessionStorage";
|
|
42
|
+
// Authorization
|
|
43
|
+
export { NodeUserAuthorization, } from "./authorization/NodeUserAuthorization";
|
|
44
|
+
// Sign strategies (re-exported from sdk-core + Node.js-specific types)
|
|
45
|
+
export { defaultSignStrategy, } from "./authorization/strategies";
|
|
46
|
+
// High-level API
|
|
47
|
+
export { TinyCloudNode } from "./TinyCloudNode";
|
|
48
|
+
// Delegation
|
|
49
|
+
export { DelegatedAccess } from "./DelegatedAccess";
|
|
50
|
+
export { serializeDelegation, deserializeDelegation, } from "./delegation";
|
|
51
|
+
// Re-export KV service for direct usage
|
|
52
|
+
export { KVService,
|
|
53
|
+
// Prefixed KV
|
|
54
|
+
PrefixedKVService, } from "@tinycloudlabs/sdk-core";
|
|
55
|
+
// Re-export v2 Delegation services and types
|
|
56
|
+
export {
|
|
57
|
+
// DelegationManager (v2 DelegationService)
|
|
58
|
+
DelegationManager,
|
|
59
|
+
// SharingService (v2)
|
|
60
|
+
SharingService, createSharingService, DelegationErrorCodes, } from "@tinycloudlabs/sdk-core";
|
|
61
|
+
// Re-export CapabilityKeyRegistry (v2)
|
|
62
|
+
export { CapabilityKeyRegistry, createCapabilityKeyRegistry, CapabilityKeyRegistryErrorCodes, } from "@tinycloudlabs/sdk-core";
|
|
63
|
+
// Re-export SpaceService (v2)
|
|
64
|
+
export { SpaceService, SpaceErrorCodes, createSpaceService, parseSpaceUri, buildSpaceUri,
|
|
65
|
+
// Space object
|
|
66
|
+
Space, } from "@tinycloudlabs/sdk-core";
|
|
67
|
+
// Protocol version checking
|
|
68
|
+
export { ProtocolMismatchError, VersionCheckError, checkNodeVersion, } from "@tinycloudlabs/sdk-core";
|
|
69
|
+
// Re-export ServiceContext and related types for advanced usage
|
|
70
|
+
export { ServiceContext, } from "@tinycloudlabs/sdk-core";
|
|
71
|
+
// Key management for node-sdk
|
|
72
|
+
export { WasmKeyProvider, createWasmKeyProvider, } from "./keys/WasmKeyProvider";
|
|
73
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,uCAAuC;AACvC,OAAO,EACL,SAAS,GASV,MAAM,yBAAyB,CAAC;AAEjC,UAAU;AACV,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D,0BAA0B;AAC1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,gBAAgB;AAChB,OAAO,EACL,qBAAqB,GAEtB,MAAM,uCAAuC,CAAC;AAE/C,uEAAuE;AACvE,OAAO,EAQL,mBAAmB,GAIpB,MAAM,4BAA4B,CAAC;AAEpC,iBAAiB;AACjB,OAAO,EAAE,aAAa,EAAuB,MAAM,iBAAiB,CAAC;AAErE,aAAa;AACb,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAEL,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,cAAc,CAAC;AAEtB,wCAAwC;AACxC,OAAO,EAEL,SAAS;AAGT,cAAc;AACd,iBAAiB,GAElB,MAAM,yBAAyB,CAAC;AAEjC,6CAA6C;AAC7C,OAAO;AACL,2CAA2C;AAC3C,iBAAiB;AAEjB,sBAAsB;AACtB,cAAc,EAGd,oBAAoB,EAcpB,oBAAoB,GAiBrB,MAAM,yBAAyB,CAAC;AAEjC,uCAAuC;AACvC,OAAO,EACL,qBAAqB,EAErB,2BAA2B,EAE3B,+BAA+B,GAEhC,MAAM,yBAAyB,CAAC;AAEjC,8BAA8B;AAC9B,OAAO,EACL,YAAY,EAGZ,eAAe,EAEf,kBAAkB,EAClB,aAAa,EACb,aAAa;AACb,eAAe;AACf,KAAK,GAKN,MAAM,yBAAyB,CAAC;AAEjC,4BAA4B;AAC5B,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,yBAAyB,CAAC;AAEjC,gEAAgE;AAChE,OAAO,EACL,cAAc,GAKf,MAAM,yBAAyB,CAAC;AAKjC,8BAA8B;AAC9B,OAAO,EACL,eAAe,EAEf,qBAAqB,GACtB,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WasmKeyProvider - KeyProvider implementation using WASM session manager.
|
|
3
|
+
*
|
|
4
|
+
* This provider wraps the SessionManager from node-sdk-wasm to provide
|
|
5
|
+
* cryptographic key operations required by the SharingService.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import type { KeyProvider, JWK } from "@tinycloudlabs/sdk-core";
|
|
10
|
+
import type { TCWSessionManager as SessionManager } from "@tinycloudlabs/node-sdk-wasm";
|
|
11
|
+
/**
|
|
12
|
+
* Configuration for WasmKeyProvider.
|
|
13
|
+
*/
|
|
14
|
+
export interface WasmKeyProviderConfig {
|
|
15
|
+
/**
|
|
16
|
+
* The WASM session manager instance.
|
|
17
|
+
* Must be created before constructing the KeyProvider.
|
|
18
|
+
*/
|
|
19
|
+
sessionManager: SessionManager;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* KeyProvider implementation that wraps the WASM session manager.
|
|
23
|
+
*
|
|
24
|
+
* This allows the SharingService to create new session keys for sharing links
|
|
25
|
+
* using the same cryptographic operations as the main session management.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { SessionManager } from "@tinycloudlabs/node-sdk-wasm";
|
|
30
|
+
* import { WasmKeyProvider } from "@tinycloudlabs/node-sdk";
|
|
31
|
+
*
|
|
32
|
+
* const sessionManager = new SessionManager();
|
|
33
|
+
* const keyProvider = new WasmKeyProvider({ sessionManager });
|
|
34
|
+
*
|
|
35
|
+
* // Create a session key for a sharing link
|
|
36
|
+
* const keyId = await keyProvider.createSessionKey("share:abc123");
|
|
37
|
+
* const jwk = keyProvider.getJWK(keyId);
|
|
38
|
+
* const did = await keyProvider.getDID(keyId);
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare class WasmKeyProvider implements KeyProvider {
|
|
42
|
+
private sessionManager;
|
|
43
|
+
/**
|
|
44
|
+
* Create a new WasmKeyProvider.
|
|
45
|
+
*
|
|
46
|
+
* @param config - Configuration with the WASM session manager
|
|
47
|
+
*/
|
|
48
|
+
constructor(config: WasmKeyProviderConfig);
|
|
49
|
+
/**
|
|
50
|
+
* Generate a new session key with the given name.
|
|
51
|
+
*
|
|
52
|
+
* This creates a new Ed25519 key pair in the WASM session manager.
|
|
53
|
+
* The key can then be used for signing delegations in sharing links.
|
|
54
|
+
*
|
|
55
|
+
* @param name - A unique name/ID for the key (e.g., "share:timestamp:random")
|
|
56
|
+
* @returns The key ID (same as the name provided)
|
|
57
|
+
*/
|
|
58
|
+
createSessionKey(name: string): Promise<string>;
|
|
59
|
+
/**
|
|
60
|
+
* Get the JWK (JSON Web Key) for a key.
|
|
61
|
+
*
|
|
62
|
+
* Returns the full JWK including the private key (d parameter),
|
|
63
|
+
* which is required for signing and for embedding in sharing links.
|
|
64
|
+
*
|
|
65
|
+
* @param keyId - The key ID to retrieve
|
|
66
|
+
* @returns The JWK object with public and private key components
|
|
67
|
+
* @throws Error if the key is not found
|
|
68
|
+
*/
|
|
69
|
+
getJWK(keyId: string): JWK;
|
|
70
|
+
/**
|
|
71
|
+
* Get the DID (Decentralized Identifier) for a key.
|
|
72
|
+
*
|
|
73
|
+
* Returns the did:key format DID derived from the key's public key.
|
|
74
|
+
* This DID can be used as the delegatee in delegations.
|
|
75
|
+
*
|
|
76
|
+
* @param keyId - The key ID to retrieve
|
|
77
|
+
* @returns The DID in did:key format (e.g., "did:key:z6Mk...")
|
|
78
|
+
*/
|
|
79
|
+
getDID(keyId: string): Promise<string>;
|
|
80
|
+
/**
|
|
81
|
+
* List all session keys currently held by the provider.
|
|
82
|
+
*
|
|
83
|
+
* @returns Array of key IDs
|
|
84
|
+
*/
|
|
85
|
+
listKeys(): string[];
|
|
86
|
+
/**
|
|
87
|
+
* Check if a key exists in the provider.
|
|
88
|
+
*
|
|
89
|
+
* @param keyId - The key ID to check
|
|
90
|
+
* @returns True if the key exists
|
|
91
|
+
*/
|
|
92
|
+
hasKey(keyId: string): boolean;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Create a new WasmKeyProvider instance.
|
|
96
|
+
*
|
|
97
|
+
* @param sessionManager - The WASM session manager
|
|
98
|
+
* @returns A new WasmKeyProvider instance
|
|
99
|
+
*/
|
|
100
|
+
export declare function createWasmKeyProvider(sessionManager: SessionManager): WasmKeyProvider;
|
|
101
|
+
//# sourceMappingURL=WasmKeyProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WasmKeyProvider.d.ts","sourceRoot":"","sources":["../../src/keys/WasmKeyProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,iBAAiB,IAAI,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAExF;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,cAAc,EAAE,cAAc,CAAC;CAChC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,eAAgB,YAAW,WAAW;IACjD,OAAO,CAAC,cAAc,CAAiB;IAEvC;;;;OAIG;gBACS,MAAM,EAAE,qBAAqB;IAIzC;;;;;;;;OAQG;IACG,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAMrD;;;;;;;;;OASG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG;IAU1B;;;;;;;;OAQG;IACG,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAK5C;;;;OAIG;IACH,QAAQ,IAAI,MAAM,EAAE;IAKpB;;;;;OAKG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAI/B;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,cAAc,EAAE,cAAc,GAAG,eAAe,CAErF"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WasmKeyProvider - KeyProvider implementation using WASM session manager.
|
|
3
|
+
*
|
|
4
|
+
* This provider wraps the SessionManager from node-sdk-wasm to provide
|
|
5
|
+
* cryptographic key operations required by the SharingService.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* KeyProvider implementation that wraps the WASM session manager.
|
|
11
|
+
*
|
|
12
|
+
* This allows the SharingService to create new session keys for sharing links
|
|
13
|
+
* using the same cryptographic operations as the main session management.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { SessionManager } from "@tinycloudlabs/node-sdk-wasm";
|
|
18
|
+
* import { WasmKeyProvider } from "@tinycloudlabs/node-sdk";
|
|
19
|
+
*
|
|
20
|
+
* const sessionManager = new SessionManager();
|
|
21
|
+
* const keyProvider = new WasmKeyProvider({ sessionManager });
|
|
22
|
+
*
|
|
23
|
+
* // Create a session key for a sharing link
|
|
24
|
+
* const keyId = await keyProvider.createSessionKey("share:abc123");
|
|
25
|
+
* const jwk = keyProvider.getJWK(keyId);
|
|
26
|
+
* const did = await keyProvider.getDID(keyId);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export class WasmKeyProvider {
|
|
30
|
+
/**
|
|
31
|
+
* Create a new WasmKeyProvider.
|
|
32
|
+
*
|
|
33
|
+
* @param config - Configuration with the WASM session manager
|
|
34
|
+
*/
|
|
35
|
+
constructor(config) {
|
|
36
|
+
this.sessionManager = config.sessionManager;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Generate a new session key with the given name.
|
|
40
|
+
*
|
|
41
|
+
* This creates a new Ed25519 key pair in the WASM session manager.
|
|
42
|
+
* The key can then be used for signing delegations in sharing links.
|
|
43
|
+
*
|
|
44
|
+
* @param name - A unique name/ID for the key (e.g., "share:timestamp:random")
|
|
45
|
+
* @returns The key ID (same as the name provided)
|
|
46
|
+
*/
|
|
47
|
+
async createSessionKey(name) {
|
|
48
|
+
// The WASM session manager's createSessionKey returns the key_id
|
|
49
|
+
// and stores the key internally
|
|
50
|
+
return this.sessionManager.createSessionKey(name);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get the JWK (JSON Web Key) for a key.
|
|
54
|
+
*
|
|
55
|
+
* Returns the full JWK including the private key (d parameter),
|
|
56
|
+
* which is required for signing and for embedding in sharing links.
|
|
57
|
+
*
|
|
58
|
+
* @param keyId - The key ID to retrieve
|
|
59
|
+
* @returns The JWK object with public and private key components
|
|
60
|
+
* @throws Error if the key is not found
|
|
61
|
+
*/
|
|
62
|
+
getJWK(keyId) {
|
|
63
|
+
// The WASM session manager returns the JWK as a JSON string
|
|
64
|
+
const jwkJson = this.sessionManager.jwk(keyId);
|
|
65
|
+
if (!jwkJson) {
|
|
66
|
+
throw new Error(`Key not found: ${keyId}`);
|
|
67
|
+
}
|
|
68
|
+
// Parse the JSON string to get the JWK object
|
|
69
|
+
return JSON.parse(jwkJson);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get the DID (Decentralized Identifier) for a key.
|
|
73
|
+
*
|
|
74
|
+
* Returns the did:key format DID derived from the key's public key.
|
|
75
|
+
* This DID can be used as the delegatee in delegations.
|
|
76
|
+
*
|
|
77
|
+
* @param keyId - The key ID to retrieve
|
|
78
|
+
* @returns The DID in did:key format (e.g., "did:key:z6Mk...")
|
|
79
|
+
*/
|
|
80
|
+
async getDID(keyId) {
|
|
81
|
+
// The WASM session manager has a synchronous getDID method
|
|
82
|
+
return this.sessionManager.getDID(keyId);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* List all session keys currently held by the provider.
|
|
86
|
+
*
|
|
87
|
+
* @returns Array of key IDs
|
|
88
|
+
*/
|
|
89
|
+
listKeys() {
|
|
90
|
+
const keys = this.sessionManager.listSessionKeys();
|
|
91
|
+
return Array.isArray(keys) ? keys : [];
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Check if a key exists in the provider.
|
|
95
|
+
*
|
|
96
|
+
* @param keyId - The key ID to check
|
|
97
|
+
* @returns True if the key exists
|
|
98
|
+
*/
|
|
99
|
+
hasKey(keyId) {
|
|
100
|
+
const jwk = this.sessionManager.jwk(keyId);
|
|
101
|
+
return jwk !== undefined;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Create a new WasmKeyProvider instance.
|
|
106
|
+
*
|
|
107
|
+
* @param sessionManager - The WASM session manager
|
|
108
|
+
* @returns A new WasmKeyProvider instance
|
|
109
|
+
*/
|
|
110
|
+
export function createWasmKeyProvider(sessionManager) {
|
|
111
|
+
return new WasmKeyProvider({ sessionManager });
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=WasmKeyProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WasmKeyProvider.js","sourceRoot":"","sources":["../../src/keys/WasmKeyProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAgBH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,eAAe;IAG1B;;;;OAIG;IACH,YAAY,MAA6B;QACvC,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC;IAC9C,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,gBAAgB,CAAC,IAAY;QACjC,iEAAiE;QACjE,gCAAgC;QAChC,OAAO,IAAI,CAAC,cAAc,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACpD,CAAC;IAED;;;;;;;;;OASG;IACH,MAAM,CAAC,KAAa;QAClB,4DAA4D;QAC5D,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC/C,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,kBAAkB,KAAK,EAAE,CAAC,CAAC;QAC7C,CAAC;QACD,8CAA8C;QAC9C,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAQ,CAAC;IACpC,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,MAAM,CAAC,KAAa;QACxB,2DAA2D;QAC3D,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;IAED;;;;OAIG;IACH,QAAQ;QACN,MAAM,IAAI,GAAG,IAAI,CAAC,cAAc,CAAC,eAAe,EAAE,CAAC;QACnD,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IACzC,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,KAAa;QAClB,MAAM,GAAG,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC3C,OAAO,GAAG,KAAK,SAAS,CAAC;IAC3B,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,cAA8B;IAClE,OAAO,IAAI,eAAe,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/keys/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/keys/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,eAAe,EAAyB,qBAAqB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ISigner, Bytes } from "@tinycloudlabs/sdk-core";
|
|
2
|
+
/**
|
|
3
|
+
* Private key signer for Node.js environments.
|
|
4
|
+
*
|
|
5
|
+
* Uses the node-sdk-wasm package for Ethereum signing operations.
|
|
6
|
+
* The private key should be a hex string (with or without 0x prefix).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const signer = new PrivateKeySigner(process.env.PRIVATE_KEY);
|
|
11
|
+
* const address = await signer.getAddress();
|
|
12
|
+
* const signature = await signer.signMessage("Hello, world!");
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare class PrivateKeySigner implements ISigner {
|
|
16
|
+
private readonly privateKeyHex;
|
|
17
|
+
private readonly chainId;
|
|
18
|
+
private cachedAddress?;
|
|
19
|
+
/**
|
|
20
|
+
* Create a new PrivateKeySigner.
|
|
21
|
+
*
|
|
22
|
+
* @param privateKey - Hex-encoded private key (with or without 0x prefix)
|
|
23
|
+
* @param chainId - Chain ID for signing (default: 1 for mainnet)
|
|
24
|
+
*/
|
|
25
|
+
constructor(privateKey: string, chainId?: number);
|
|
26
|
+
/**
|
|
27
|
+
* Get the Ethereum address for this signer.
|
|
28
|
+
*/
|
|
29
|
+
getAddress(): Promise<string>;
|
|
30
|
+
/**
|
|
31
|
+
* Derive Ethereum address from private key.
|
|
32
|
+
* Uses secp256k1 public key derivation via ethers.js.
|
|
33
|
+
*/
|
|
34
|
+
private deriveAddress;
|
|
35
|
+
/**
|
|
36
|
+
* Get the chain ID for this signer.
|
|
37
|
+
*/
|
|
38
|
+
getChainId(): Promise<number>;
|
|
39
|
+
/**
|
|
40
|
+
* Sign a message.
|
|
41
|
+
*
|
|
42
|
+
* @param message - The message to sign (string or bytes)
|
|
43
|
+
* @returns The signature as a hex string
|
|
44
|
+
*/
|
|
45
|
+
signMessage(message: Bytes | string): Promise<string>;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=PrivateKeySigner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrivateKeySigner.d.ts","sourceRoot":"","sources":["../../src/signers/PrivateKeySigner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAMzD;;;;;;;;;;;;GAYG;AACH,qBAAa,gBAAiB,YAAW,OAAO;IAC9C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,aAAa,CAAC,CAAS;IAE/B;;;;;OAKG;gBACS,UAAU,EAAE,MAAM,EAAE,OAAO,GAAE,MAAU;IAanD;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IASnC;;;OAGG;IACH,OAAO,CAAC,aAAa;IAoBrB;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAInC;;;;;OAKG;IACG,WAAW,CAAC,OAAO,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAa5D"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { signEthereumMessage, ensureEip55, } from "@tinycloudlabs/node-sdk-wasm";
|
|
2
|
+
/**
|
|
3
|
+
* Private key signer for Node.js environments.
|
|
4
|
+
*
|
|
5
|
+
* Uses the node-sdk-wasm package for Ethereum signing operations.
|
|
6
|
+
* The private key should be a hex string (with or without 0x prefix).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const signer = new PrivateKeySigner(process.env.PRIVATE_KEY);
|
|
11
|
+
* const address = await signer.getAddress();
|
|
12
|
+
* const signature = await signer.signMessage("Hello, world!");
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export class PrivateKeySigner {
|
|
16
|
+
/**
|
|
17
|
+
* Create a new PrivateKeySigner.
|
|
18
|
+
*
|
|
19
|
+
* @param privateKey - Hex-encoded private key (with or without 0x prefix)
|
|
20
|
+
* @param chainId - Chain ID for signing (default: 1 for mainnet)
|
|
21
|
+
*/
|
|
22
|
+
constructor(privateKey, chainId = 1) {
|
|
23
|
+
// Normalize private key format (remove 0x prefix)
|
|
24
|
+
this.privateKeyHex = privateKey.startsWith("0x")
|
|
25
|
+
? privateKey.slice(2)
|
|
26
|
+
: privateKey;
|
|
27
|
+
this.chainId = chainId;
|
|
28
|
+
// Validate private key length
|
|
29
|
+
if (this.privateKeyHex.length !== 64) {
|
|
30
|
+
throw new Error("Invalid private key: must be 32 bytes (64 hex chars)");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get the Ethereum address for this signer.
|
|
35
|
+
*/
|
|
36
|
+
async getAddress() {
|
|
37
|
+
if (this.cachedAddress) {
|
|
38
|
+
return this.cachedAddress;
|
|
39
|
+
}
|
|
40
|
+
this.cachedAddress = this.deriveAddress();
|
|
41
|
+
return this.cachedAddress;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Derive Ethereum address from private key.
|
|
45
|
+
* Uses secp256k1 public key derivation via ethers.js.
|
|
46
|
+
*/
|
|
47
|
+
deriveAddress() {
|
|
48
|
+
try {
|
|
49
|
+
// Derive public key from private key using secp256k1
|
|
50
|
+
const { keccak256 } = require("ethers/lib/utils");
|
|
51
|
+
const { SigningKey } = require("ethers/lib/utils");
|
|
52
|
+
const signingKey = new SigningKey("0x" + this.privateKeyHex);
|
|
53
|
+
const publicKey = signingKey.publicKey;
|
|
54
|
+
// Remove '0x04' prefix (uncompressed point indicator)
|
|
55
|
+
const pubKeyWithoutPrefix = publicKey.slice(4);
|
|
56
|
+
const hash = keccak256("0x" + pubKeyWithoutPrefix);
|
|
57
|
+
// Take last 20 bytes
|
|
58
|
+
const address = "0x" + hash.slice(-40);
|
|
59
|
+
return ensureEip55(address);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// Fallback: use dummy address for testing
|
|
63
|
+
return "0x" + this.privateKeyHex.slice(0, 40);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get the chain ID for this signer.
|
|
68
|
+
*/
|
|
69
|
+
async getChainId() {
|
|
70
|
+
return this.chainId;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Sign a message.
|
|
74
|
+
*
|
|
75
|
+
* @param message - The message to sign (string or bytes)
|
|
76
|
+
* @returns The signature as a hex string
|
|
77
|
+
*/
|
|
78
|
+
async signMessage(message) {
|
|
79
|
+
const messageStr = typeof message === "string"
|
|
80
|
+
? message
|
|
81
|
+
: Buffer.from(message).toString("utf-8");
|
|
82
|
+
// Use WASM to sign with Ethereum personal_sign format
|
|
83
|
+
// WASM now accepts hex-encoded private key directly
|
|
84
|
+
const signature = signEthereumMessage(messageStr, this.privateKeyHex);
|
|
85
|
+
// Ensure signature has 0x prefix
|
|
86
|
+
return signature.startsWith("0x") ? signature : "0x" + signature;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=PrivateKeySigner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrivateKeySigner.js","sourceRoot":"","sources":["../../src/signers/PrivateKeySigner.ts"],"names":[],"mappings":"AACA,OAAO,EACL,mBAAmB,EACnB,WAAW,GACZ,MAAM,8BAA8B,CAAC;AAEtC;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,gBAAgB;IAK3B;;;;;OAKG;IACH,YAAY,UAAkB,EAAE,UAAkB,CAAC;QACjD,kDAAkD;QAClD,IAAI,CAAC,aAAa,GAAG,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC;YAC9C,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;YACrB,CAAC,CAAC,UAAU,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,8BAA8B;QAC9B,IAAI,IAAI,CAAC,aAAa,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;YACrC,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;QAC1E,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU;QACd,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC,aAAa,CAAC;QAC5B,CAAC;QAED,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QAC1C,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACK,aAAa;QACnB,IAAI,CAAC;YACH,qDAAqD;YACrD,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;YAClD,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;YAEnD,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC;YAC7D,MAAM,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC;YACvC,sDAAsD;YACtD,MAAM,mBAAmB,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAC/C,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,GAAG,mBAAmB,CAAC,CAAC;YACnD,qBAAqB;YACrB,MAAM,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;YACvC,OAAO,WAAW,CAAC,OAAO,CAAC,CAAC;QAC9B,CAAC;QAAC,MAAM,CAAC;YACP,0CAA0C;YAC1C,OAAO,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU;QACd,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,WAAW,CAAC,OAAuB;QACvC,MAAM,UAAU,GACd,OAAO,OAAO,KAAK,QAAQ;YACzB,CAAC,CAAC,OAAO;YACT,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAA4B,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAElE,sDAAsD;QACtD,oDAAoD;QACpD,MAAM,SAAS,GAAG,mBAAmB,CAAC,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAEtE,iCAAiC;QACjC,OAAO,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,GAAG,SAAS,CAAC;IACnE,CAAC;CACF"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ISessionStorage, PersistedSessionData } from "@tinycloudlabs/sdk-core";
|
|
2
|
+
/**
|
|
3
|
+
* File-based session storage for Node.js.
|
|
4
|
+
*
|
|
5
|
+
* Sessions are persisted to the file system and survive process restarts.
|
|
6
|
+
* Suitable for:
|
|
7
|
+
* - CLI applications
|
|
8
|
+
* - Long-running server processes
|
|
9
|
+
* - Development environments
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const storage = new FileSessionStorage("/tmp/tinycloud-sessions");
|
|
14
|
+
* await storage.save("0x123...", sessionData);
|
|
15
|
+
* // Session persists across process restarts
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare class FileSessionStorage implements ISessionStorage {
|
|
19
|
+
private readonly baseDir;
|
|
20
|
+
/**
|
|
21
|
+
* Create a new FileSessionStorage.
|
|
22
|
+
*
|
|
23
|
+
* @param baseDir - Directory to store session files (default: ~/.tinycloud/sessions)
|
|
24
|
+
*/
|
|
25
|
+
constructor(baseDir?: string);
|
|
26
|
+
/**
|
|
27
|
+
* Get the default session storage directory.
|
|
28
|
+
*/
|
|
29
|
+
private getDefaultDir;
|
|
30
|
+
/**
|
|
31
|
+
* Ensure the storage directory exists.
|
|
32
|
+
*/
|
|
33
|
+
private ensureDirectoryExists;
|
|
34
|
+
/**
|
|
35
|
+
* Get the file path for an address.
|
|
36
|
+
*/
|
|
37
|
+
private getFilePath;
|
|
38
|
+
/**
|
|
39
|
+
* Save a session for an address.
|
|
40
|
+
*/
|
|
41
|
+
save(address: string, session: PersistedSessionData): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Load a session for an address.
|
|
44
|
+
*/
|
|
45
|
+
load(address: string): Promise<PersistedSessionData | null>;
|
|
46
|
+
/**
|
|
47
|
+
* Clear a session for an address.
|
|
48
|
+
*/
|
|
49
|
+
clear(address: string): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Check if a session exists for an address.
|
|
52
|
+
*/
|
|
53
|
+
exists(address: string): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Check if file system storage is available.
|
|
56
|
+
*/
|
|
57
|
+
isAvailable(): boolean;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=FileSessionStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileSessionStorage.d.ts","sourceRoot":"","sources":["../../src/storage/FileSessionStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAgC,MAAM,yBAAyB,CAAC;AAI9G;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,kBAAmB,YAAW,eAAe;IACxD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC;;;;OAIG;gBACS,OAAO,CAAC,EAAE,MAAM;IAK5B;;OAEG;IACH,OAAO,CAAC,aAAa;IAKrB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAM7B;;OAEG;IACH,OAAO,CAAC,WAAW;IAOnB;;OAEG;IACG,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAMzE;;OAEG;IACG,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IA0CjE;;OAEG;IACG,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO3C;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAwBhC;;OAEG;IACH,WAAW,IAAI,OAAO;CAQvB"}
|