@tinycloudlabs/web-sdk-wasm 0.2.0 → 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/index.d.ts +4 -1
- package/dist/index.js +868 -654
- package/dist/tinycloud_web_sdk_rs.d.ts +136 -90
- package/package.json +13 -18
- package/README.md +0 -92
- package/tsconfig.json +0 -5
|
@@ -1,26 +1,5 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
-
/**
|
|
4
|
-
* Initialise console-error-panic-hook to improve debug output for panics.
|
|
5
|
-
*
|
|
6
|
-
* Run once on initialisation.
|
|
7
|
-
*/
|
|
8
|
-
export function initPanicHook(): void;
|
|
9
|
-
export function makeOrbitId(address: string, chainId: number, name?: string | null): string;
|
|
10
|
-
export function prepareSession(config: string): Promise<any>;
|
|
11
|
-
export function completeSessionSetup(config: string): string;
|
|
12
|
-
export function invoke(session: string, service: string, path: string, action: string): Promise<any>;
|
|
13
|
-
export function generateHostSIWEMessage(config: string): string;
|
|
14
|
-
export function siweToDelegationHeaders(signedSIWEMessage: string): string;
|
|
15
|
-
|
|
16
|
-
export type ExtraFields = {
|
|
17
|
-
/** Any extra fields that are needed for the capability.
|
|
18
|
-
* This object must be serializable with JSON.stringify().
|
|
19
|
-
*/
|
|
20
|
-
[key: string]: any
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
3
|
|
|
25
4
|
export type SiweConfig = {
|
|
26
5
|
/**Ethereum address performing the signing conformant to capitalization
|
|
@@ -56,6 +35,15 @@ export type SiweConfig = {
|
|
|
56
35
|
|
|
57
36
|
|
|
58
37
|
|
|
38
|
+
export type ExtraFields = {
|
|
39
|
+
/** Any extra fields that are needed for the capability.
|
|
40
|
+
* This object must be serializable with JSON.stringify().
|
|
41
|
+
*/
|
|
42
|
+
[key: string]: any
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
59
47
|
/**
|
|
60
48
|
* Configuration object for starting a TinyCloud session.
|
|
61
49
|
*/
|
|
@@ -70,8 +58,8 @@ export type SessionConfig = {
|
|
|
70
58
|
domain: string,
|
|
71
59
|
/** Current time for SIWE message. */
|
|
72
60
|
issuedAt: string,
|
|
73
|
-
/** The
|
|
74
|
-
|
|
61
|
+
/** The space that is the target resource of the delegation. */
|
|
62
|
+
spaceId: string,
|
|
75
63
|
/** The earliest time that the session will be valid from. */
|
|
76
64
|
notBefore?: string,
|
|
77
65
|
/** The latest time that the session will be valid until. */
|
|
@@ -85,25 +73,7 @@ export type SessionConfig = {
|
|
|
85
73
|
|
|
86
74
|
|
|
87
75
|
/**
|
|
88
|
-
*
|
|
89
|
-
*/
|
|
90
|
-
export type Session = {
|
|
91
|
-
/** The delegation from the user to the session key. */
|
|
92
|
-
delegationHeader: { Authorization: string },
|
|
93
|
-
/** The delegation reference from the user to the session key. */
|
|
94
|
-
delegationCid: string,
|
|
95
|
-
/** The session key. */
|
|
96
|
-
jwk: object,
|
|
97
|
-
/** The orbit that the session key is permitted to perform actions against. */
|
|
98
|
-
orbitId: string,
|
|
99
|
-
/** The verification method of the session key. */
|
|
100
|
-
verificationMethod: string,
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Configuration object for generating a TinyCloud Orbit Host Delegation SIWE message.
|
|
76
|
+
* Configuration object for generating a TinyCloud Space Host Delegation SIWE message.
|
|
107
77
|
*/
|
|
108
78
|
export type HostConfig = {
|
|
109
79
|
/** Ethereum address. */
|
|
@@ -114,93 +84,169 @@ export type HostConfig = {
|
|
|
114
84
|
domain: string,
|
|
115
85
|
/** Current time for SIWE message. */
|
|
116
86
|
issuedAt: string,
|
|
117
|
-
/** The
|
|
118
|
-
|
|
87
|
+
/** The space that is the target resource of the delegation. */
|
|
88
|
+
spaceId: string,
|
|
119
89
|
/** The peer that is the target/invoker in the delegation. */
|
|
120
90
|
peerId: string,
|
|
121
91
|
}
|
|
122
92
|
|
|
123
93
|
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* A TinyCloud session.
|
|
97
|
+
*/
|
|
98
|
+
export type Session = {
|
|
99
|
+
/** The delegation from the user to the session key. */
|
|
100
|
+
delegationHeader: { Authorization: string },
|
|
101
|
+
/** The delegation reference from the user to the session key. */
|
|
102
|
+
delegationCid: string,
|
|
103
|
+
/** The session key. */
|
|
104
|
+
jwk: object,
|
|
105
|
+
/** The space that the session key is permitted to perform actions against. */
|
|
106
|
+
spaceId: string,
|
|
107
|
+
/** The verification method of the session key. */
|
|
108
|
+
verificationMethod: string,
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
124
113
|
export class TCWSessionManager {
|
|
125
114
|
free(): void;
|
|
115
|
+
[Symbol.dispose](): void;
|
|
126
116
|
/**
|
|
127
|
-
*
|
|
117
|
+
* List the available session keys.
|
|
128
118
|
*/
|
|
129
|
-
|
|
119
|
+
listSessionKeys(): any;
|
|
130
120
|
/**
|
|
131
121
|
* Reset the SIWE message builder to its initial state.
|
|
132
122
|
*/
|
|
133
123
|
resetCapability(): void;
|
|
134
124
|
/**
|
|
135
|
-
*
|
|
136
|
-
*/
|
|
137
|
-
build(config: SiweConfig, key_id?: string | null, custom_uri?: string | null): Promise<string>;
|
|
138
|
-
/**
|
|
139
|
-
* Add default actions to a capability.
|
|
125
|
+
* Create a new session key with the given key ID (Defaults to 'default').
|
|
140
126
|
*/
|
|
141
|
-
|
|
127
|
+
createSessionKey(key_id?: string | null): string;
|
|
142
128
|
/**
|
|
143
129
|
* Add actions for a specific target to a capability.
|
|
144
130
|
*/
|
|
145
|
-
addTargetedActions(
|
|
131
|
+
addTargetedActions(target: string, actions: string[]): boolean;
|
|
146
132
|
/**
|
|
147
|
-
*
|
|
133
|
+
* Rename the key_id to retrieve session data.
|
|
148
134
|
*/
|
|
149
|
-
|
|
135
|
+
renameSessionKeyId(old_key_id: string, new_key_id: string): void;
|
|
150
136
|
/**
|
|
151
|
-
*
|
|
137
|
+
* Get the full JWK associated with a the session key key_id.
|
|
152
138
|
*/
|
|
153
|
-
|
|
139
|
+
jwk(key_id?: string | null): string | undefined;
|
|
154
140
|
/**
|
|
155
|
-
*
|
|
141
|
+
* Initialize a new TinyCloudWebSessionManager.
|
|
156
142
|
*/
|
|
157
|
-
|
|
143
|
+
constructor();
|
|
158
144
|
/**
|
|
159
|
-
*
|
|
145
|
+
* Build a SIWE message for signing.
|
|
160
146
|
*/
|
|
161
|
-
|
|
147
|
+
build(config: SiweConfig, key_id?: string | null, custom_uri?: string | null): string;
|
|
162
148
|
/**
|
|
163
|
-
* Get the
|
|
149
|
+
* Get the DID associated with a the session key key_id.
|
|
164
150
|
*/
|
|
165
|
-
|
|
151
|
+
getDID(key_id?: string | null): string;
|
|
166
152
|
}
|
|
167
153
|
|
|
154
|
+
export function completeSessionSetup(config: any): any;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Compute a CID from data bytes using Blake3_256 hash.
|
|
158
|
+
*
|
|
159
|
+
* This uses the same hashing algorithm as the TinyCloud server,
|
|
160
|
+
* ensuring CID consistency between client and server.
|
|
161
|
+
*
|
|
162
|
+
* # Arguments
|
|
163
|
+
* * `data` - The bytes to hash
|
|
164
|
+
* * `codec` - The multicodec code (e.g., 0x55 for raw)
|
|
165
|
+
*
|
|
166
|
+
* # Returns
|
|
167
|
+
* The CID as a string (base32 multibase encoded)
|
|
168
|
+
*/
|
|
169
|
+
export function computeCid(data: Uint8Array, codec: bigint): string;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Create a delegation UCAN from a session to another DID.
|
|
173
|
+
* This allows session keys to delegate capabilities to other users client-side.
|
|
174
|
+
*
|
|
175
|
+
* # Arguments
|
|
176
|
+
* * `session` - The current session (with JWK and delegation info)
|
|
177
|
+
* * `delegateDID` - The recipient's DID (audience of the delegation)
|
|
178
|
+
* * `spaceId` - The space being delegated (e.g., "tinycloud:pkh:eip155:1:0x....:default")
|
|
179
|
+
* * `path` - Path scope for the delegation
|
|
180
|
+
* * `actions` - Actions to delegate (e.g., ["tinycloud.kv/get", "tinycloud.kv/put"])
|
|
181
|
+
* * `expirationSecs` - Expiration timestamp in seconds since epoch
|
|
182
|
+
* * `notBeforeSecs` - Optional not-before timestamp in seconds since epoch
|
|
183
|
+
*
|
|
184
|
+
* # Returns
|
|
185
|
+
* A `DelegationResult` containing:
|
|
186
|
+
* * `delegation` - Base64url-encoded UCAN JWT string
|
|
187
|
+
* * `cid` - CID of the delegation (for referencing in proof chains)
|
|
188
|
+
* * `delegateDID` - The delegate's DID
|
|
189
|
+
* * `path` - Path scope
|
|
190
|
+
* * `actions` - Delegated actions
|
|
191
|
+
* * `expiry` - Expiration timestamp
|
|
192
|
+
*/
|
|
193
|
+
export function createDelegation(session: any, delegateDID: string, spaceId: string, path: string, actions: string[], expirationSecs: number, notBeforeSecs: any): any;
|
|
194
|
+
|
|
195
|
+
export function ensureEip55(address: string): string;
|
|
196
|
+
|
|
197
|
+
export function generateHostSIWEMessage(config: any): string;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Initialise console-error-panic-hook to improve debug output for panics.
|
|
201
|
+
*
|
|
202
|
+
* Run once on initialisation.
|
|
203
|
+
*/
|
|
204
|
+
export function initPanicHook(): void;
|
|
205
|
+
|
|
206
|
+
export function invoke(session: any, service: string, path: string, action: string, facts: any): any;
|
|
207
|
+
|
|
208
|
+
export function makeSpaceId(address: string, chainId: number, name: string): string;
|
|
209
|
+
|
|
210
|
+
export function prepareSession(config: any): any;
|
|
211
|
+
|
|
212
|
+
export function protocolVersion(): number;
|
|
213
|
+
|
|
214
|
+
export function siweToDelegationHeaders(signedSIWEMessage: any): any;
|
|
215
|
+
|
|
168
216
|
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
169
217
|
|
|
170
218
|
export interface InitOutput {
|
|
171
219
|
readonly memory: WebAssembly.Memory;
|
|
172
|
-
readonly initPanicHook: () => void;
|
|
173
220
|
readonly __wbg_tcwsessionmanager_free: (a: number, b: number) => void;
|
|
174
|
-
readonly
|
|
221
|
+
readonly initPanicHook: () => void;
|
|
222
|
+
readonly tcwsessionmanager_addTargetedActions: (a: number, b: number, c: number, d: number, e: number) => number;
|
|
223
|
+
readonly tcwsessionmanager_build: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
224
|
+
readonly tcwsessionmanager_createSessionKey: (a: number, b: number, c: number, d: number) => void;
|
|
225
|
+
readonly tcwsessionmanager_getDID: (a: number, b: number, c: number, d: number) => void;
|
|
226
|
+
readonly tcwsessionmanager_jwk: (a: number, b: number, c: number, d: number) => void;
|
|
227
|
+
readonly tcwsessionmanager_listSessionKeys: (a: number, b: number) => void;
|
|
228
|
+
readonly tcwsessionmanager_new: (a: number) => void;
|
|
229
|
+
readonly tcwsessionmanager_renameSessionKeyId: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
175
230
|
readonly tcwsessionmanager_resetCapability: (a: number) => void;
|
|
176
|
-
readonly
|
|
177
|
-
readonly
|
|
178
|
-
readonly
|
|
179
|
-
readonly
|
|
180
|
-
readonly
|
|
181
|
-
readonly
|
|
182
|
-
readonly
|
|
183
|
-
readonly
|
|
184
|
-
readonly
|
|
185
|
-
readonly
|
|
186
|
-
readonly
|
|
187
|
-
readonly
|
|
188
|
-
readonly
|
|
189
|
-
readonly
|
|
190
|
-
readonly
|
|
191
|
-
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
192
|
-
readonly __wbindgen_exn_store: (a: number) => void;
|
|
193
|
-
readonly __externref_table_alloc: () => number;
|
|
194
|
-
readonly __wbindgen_export_4: WebAssembly.Table;
|
|
195
|
-
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
196
|
-
readonly __wbindgen_export_6: WebAssembly.Table;
|
|
197
|
-
readonly __externref_table_dealloc: (a: number) => void;
|
|
198
|
-
readonly closure467_externref_shim: (a: number, b: number, c: any) => void;
|
|
199
|
-
readonly closure964_externref_shim: (a: number, b: number, c: any, d: any) => void;
|
|
200
|
-
readonly __wbindgen_start: () => void;
|
|
231
|
+
readonly completeSessionSetup: (a: number, b: number) => void;
|
|
232
|
+
readonly computeCid: (a: number, b: number, c: number, d: bigint) => void;
|
|
233
|
+
readonly createDelegation: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number) => void;
|
|
234
|
+
readonly ensureEip55: (a: number, b: number, c: number) => void;
|
|
235
|
+
readonly generateHostSIWEMessage: (a: number, b: number) => void;
|
|
236
|
+
readonly invoke: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
|
|
237
|
+
readonly makeSpaceId: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
238
|
+
readonly prepareSession: (a: number, b: number) => void;
|
|
239
|
+
readonly protocolVersion: () => number;
|
|
240
|
+
readonly siweToDelegationHeaders: (a: number, b: number) => void;
|
|
241
|
+
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
242
|
+
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
243
|
+
readonly __wbindgen_export3: (a: number) => void;
|
|
244
|
+
readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
|
|
245
|
+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
201
246
|
}
|
|
202
247
|
|
|
203
248
|
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
249
|
+
|
|
204
250
|
/**
|
|
205
251
|
* Instantiates the given `module`, which can either be bytes or
|
|
206
252
|
* a precompiled `WebAssembly.Module`.
|
package/package.json
CHANGED
|
@@ -1,35 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinycloudlabs/web-sdk-wasm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "TinyCloud WASM bindings for web browsers",
|
|
4
5
|
"main": "dist/index.js",
|
|
5
6
|
"types": "dist/index.d.ts",
|
|
6
7
|
"author": "TinyCloud, Inc.",
|
|
7
|
-
"license": "
|
|
8
|
+
"license": "EGPL",
|
|
8
9
|
"scripts": {
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
"bundle": "rollup -c && $PWD/fixup-types.sh",
|
|
15
|
-
"clean": "rm -rf dist pkg",
|
|
16
|
-
"dev": "bun run build:wasm && bun run bundle",
|
|
17
|
-
"release": "bun run build-release && bun run bundle",
|
|
18
|
-
"fmt": "prettier -w src package.json rollup.config.js tsconfig.json",
|
|
19
|
-
"publish-gh": "npm config set @tinycloudlabs:registry=https://npm.pkg.github.com && npm publish",
|
|
20
|
-
"publish-npm": "npm config set @tinycloudlabs:registry=https://registry.npmjs.org && npm publish --access public"
|
|
10
|
+
"build": "rollup -c && ./fixup-types.sh",
|
|
11
|
+
"clean": "rm -rf dist"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@tinycloudlabs/sdk-rs": "^1.0.0"
|
|
21
15
|
},
|
|
22
16
|
"devDependencies": {
|
|
23
|
-
"@changesets/cli": "^2.27.12",
|
|
24
17
|
"@rollup/plugin-wasm": "^5.2.0",
|
|
25
|
-
"prettier": "^2.8.8",
|
|
26
18
|
"rollup": "^2.79.2",
|
|
27
19
|
"rollup-plugin-typescript2": "^0.32.1",
|
|
28
20
|
"tslib": "^2.8.1",
|
|
29
21
|
"typescript": "^4.9.5"
|
|
30
22
|
},
|
|
31
23
|
"files": [
|
|
32
|
-
"tsconfig.json",
|
|
33
24
|
"dist"
|
|
34
|
-
]
|
|
25
|
+
],
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/tinycloudlabs/web-sdk"
|
|
29
|
+
}
|
|
35
30
|
}
|
package/README.md
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
# TinyCloud Web SDK (Rust/WASM)
|
|
2
|
-
|
|
3
|
-
<img src="https://github.com/TinyCloudLabs/web-sdk/blob/main/documentation/static/img/tinycloudheader.png?raw=true" alt="TinyCloud" width="100%" />
|
|
4
|
-
|
|
5
|
-
WebAssembly library written in Rust for the TinyCloud Web SDK.
|
|
6
|
-
|
|
7
|
-
[](https://www.npmjs.com/package/@tinycloudlabs/web-sdk-rs)
|
|
8
|
-
[](https://github.com/TinyCloudLabs/web-sdk/blob/main/LICENSE-MIT)
|
|
9
|
-
|
|
10
|
-
## Overview
|
|
11
|
-
|
|
12
|
-
This package provides high-performance WebAssembly components for TinyCloud Web SDK. It uses `rollup` to encode the `.wasm` as a base64-encoded string, meaning there is no configuration needed downstream to support WebAssembly (other than a compatible browser).
|
|
13
|
-
|
|
14
|
-
## Features
|
|
15
|
-
|
|
16
|
-
- **High Performance** - Critical operations implemented in Rust for maximum efficiency
|
|
17
|
-
- **Small Footprint** - Minimal bundle size overhead
|
|
18
|
-
- **Seamless Integration** - Works directly with the JavaScript SDK without configuration
|
|
19
|
-
|
|
20
|
-
## Installation
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
# Using npm
|
|
24
|
-
npm install @tinycloudlabs/web-sdk-rs
|
|
25
|
-
|
|
26
|
-
# Using Yarn
|
|
27
|
-
yarn add @tinycloudlabs/web-sdk-rs
|
|
28
|
-
|
|
29
|
-
# Using Bun (recommended)
|
|
30
|
-
bun add @tinycloudlabs/web-sdk-rs
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## Usage
|
|
34
|
-
|
|
35
|
-
This package is typically used internally by the main TinyCloud Web SDK, but you can also use it directly:
|
|
36
|
-
|
|
37
|
-
```typescript
|
|
38
|
-
import { initialize } from '@tinycloudlabs/web-sdk-rs';
|
|
39
|
-
|
|
40
|
-
// Initialize the WASM module
|
|
41
|
-
await initialize();
|
|
42
|
-
|
|
43
|
-
// Use the WASM functions
|
|
44
|
-
// ...
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
## Building from Source
|
|
48
|
-
|
|
49
|
-
### Requirements
|
|
50
|
-
|
|
51
|
-
* [Rust](https://www.rust-lang.org/tools/install)
|
|
52
|
-
* [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/)
|
|
53
|
-
* [Bun](https://bun.sh) or [Yarn](https://yarnpkg.com/getting-started/install)
|
|
54
|
-
|
|
55
|
-
### Building
|
|
56
|
-
|
|
57
|
-
For development builds:
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
bun run build-dev
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
For optimized release builds:
|
|
64
|
-
|
|
65
|
-
```bash
|
|
66
|
-
bun run build-release
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
Then bundle the package:
|
|
70
|
-
|
|
71
|
-
```bash
|
|
72
|
-
bun run bundle
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
## Documentation
|
|
76
|
-
|
|
77
|
-
For complete documentation, please visit:
|
|
78
|
-
|
|
79
|
-
- [**TinyCloud SDK Documentation**](https://docs.tinycloud.xyz/)
|
|
80
|
-
|
|
81
|
-
## Contributing
|
|
82
|
-
|
|
83
|
-
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
84
|
-
|
|
85
|
-
## License
|
|
86
|
-
|
|
87
|
-
This project is licensed under the MIT License - see the [LICENSE-MIT](https://github.com/TinyCloudLabs/web-sdk/blob/main/LICENSE-MIT) file for details.
|
|
88
|
-
|
|
89
|
-
## Related Packages
|
|
90
|
-
|
|
91
|
-
- [**@tinycloudlabs/web-sdk**](https://www.npmjs.com/package/@tinycloudlabs/web-sdk) - The main TinyCloud Web SDK package
|
|
92
|
-
- [**@tinycloudlabs/web-core**](https://www.npmjs.com/package/@tinycloudlabs/web-core) - Core utilities and types
|