@tinycloud/sdk-core 2.3.0-beta.2 → 2.3.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +144 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -1
- package/dist/index.d.ts +30 -1
- package/dist/index.js +129 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -67,6 +67,7 @@ __export(index_exports, {
|
|
|
67
67
|
EnsDataSchema: () => EnsDataSchema,
|
|
68
68
|
ErrorCodes: () => import_sdk_services5.ErrorCodes,
|
|
69
69
|
HooksService: () => import_sdk_services5.HooksService,
|
|
70
|
+
IdentityParseError: () => IdentityParseError,
|
|
70
71
|
KVService: () => import_sdk_services5.KVService,
|
|
71
72
|
LocationRecordValidationError: () => LocationRecordValidationError,
|
|
72
73
|
ManifestValidationError: () => ManifestValidationError,
|
|
@@ -97,6 +98,7 @@ __export(index_exports, {
|
|
|
97
98
|
VaultPublicSpaceKVActions: () => import_sdk_services5.VaultPublicSpaceKVActions,
|
|
98
99
|
VersionCheckError: () => VersionCheckError,
|
|
99
100
|
activateSessionWithHost: () => activateSessionWithHost,
|
|
101
|
+
addressStorageKey: () => addressStorageKey,
|
|
100
102
|
applyPrefix: () => applyPrefix,
|
|
101
103
|
buildCanonicalDecryptRequest: () => import_sdk_services5.buildCanonicalDecryptRequest,
|
|
102
104
|
buildDecryptAttenuation: () => import_sdk_services5.buildDecryptAttenuation,
|
|
@@ -107,6 +109,9 @@ __export(index_exports, {
|
|
|
107
109
|
canonicalHashHex: () => import_sdk_services5.canonicalHashHex,
|
|
108
110
|
canonicalLocationPayload: () => canonicalLocationPayload,
|
|
109
111
|
canonicalSignedResponse: () => import_sdk_services5.canonicalSignedResponse,
|
|
112
|
+
canonicalizeAddress: () => canonicalizeAddress,
|
|
113
|
+
canonicalizeDid: () => canonicalizeDid,
|
|
114
|
+
canonicalizeDidUrl: () => canonicalizeDidUrl,
|
|
110
115
|
canonicalizeEncryptionJson: () => import_sdk_services5.canonicalizeEncryptionJson,
|
|
111
116
|
canonicalizeSecretScope: () => import_sdk_services5.canonicalizeSecretScope,
|
|
112
117
|
checkDecryptInvocationInput: () => import_sdk_services5.checkDecryptInvocationInput,
|
|
@@ -121,6 +126,8 @@ __export(index_exports, {
|
|
|
121
126
|
defaultSignStrategy: () => defaultSignStrategy,
|
|
122
127
|
defaultSpaceCreationHandler: () => defaultSpaceCreationHandler,
|
|
123
128
|
deriveSignedReceiverKey: () => import_sdk_services5.deriveSignedReceiverKey,
|
|
129
|
+
didCacheKey: () => didCacheKey,
|
|
130
|
+
didEquals: () => didEquals,
|
|
124
131
|
discoverNetwork: () => import_sdk_services5.discoverNetwork,
|
|
125
132
|
encryptToNetwork: () => import_sdk_services5.encryptToNetwork,
|
|
126
133
|
encryptionBase64Decode: () => import_sdk_services5.base64Decode,
|
|
@@ -140,9 +147,11 @@ __export(index_exports, {
|
|
|
140
147
|
hexEncode: () => import_sdk_services5.hexEncode,
|
|
141
148
|
httpUrlToMultiaddr: () => httpUrlToMultiaddr,
|
|
142
149
|
isCapabilitySubset: () => isCapabilitySubset,
|
|
150
|
+
isEvmAddress: () => isEvmAddress,
|
|
143
151
|
isNetworkId: () => import_sdk_services5.isNetworkId,
|
|
144
152
|
loadManifest: () => loadManifest,
|
|
145
153
|
locationPayloadForRecord: () => locationPayloadForRecord,
|
|
154
|
+
makePkhSpaceId: () => makePkhSpaceId,
|
|
146
155
|
makePublicSpaceId: () => makePublicSpaceId,
|
|
147
156
|
manifestAbilitiesUnion: () => manifestAbilitiesUnion,
|
|
148
157
|
multiaddrToHttpUrl: () => multiaddrToHttpUrl,
|
|
@@ -152,8 +161,12 @@ __export(index_exports, {
|
|
|
152
161
|
openWrappedKey: () => import_sdk_services5.openWrappedKey,
|
|
153
162
|
parseExpiry: () => parseExpiry,
|
|
154
163
|
parseNetworkId: () => import_sdk_services5.parseNetworkId,
|
|
164
|
+
parsePkhDid: () => parsePkhDid,
|
|
155
165
|
parseRecapCapabilities: () => parseRecapCapabilities,
|
|
156
166
|
parseSpaceUri: () => parseSpaceUri,
|
|
167
|
+
pkhDid: () => pkhDid,
|
|
168
|
+
principalDid: () => principalDid,
|
|
169
|
+
principalDidEquals: () => principalDidEquals,
|
|
157
170
|
resolveCloudLocation: () => resolveCloudLocation,
|
|
158
171
|
resolveManifest: () => resolveManifest,
|
|
159
172
|
resolveSecretListPrefix: () => import_sdk_services5.resolveSecretListPrefix,
|
|
@@ -218,6 +231,97 @@ var SilentNotificationHandler = class {
|
|
|
218
231
|
}
|
|
219
232
|
};
|
|
220
233
|
|
|
234
|
+
// src/identity.ts
|
|
235
|
+
var import_viem = require("viem");
|
|
236
|
+
var IdentityParseError = class extends Error {
|
|
237
|
+
constructor(message) {
|
|
238
|
+
super(message);
|
|
239
|
+
this.name = "IdentityParseError";
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
var PKH_DID_RE = /^did:pkh:eip155:(\d+):(0x[a-fA-F0-9]{40})$/;
|
|
243
|
+
var DID_RE = /^did:[a-z0-9]+:.+$/;
|
|
244
|
+
function splitDidUrl(input) {
|
|
245
|
+
const fragmentIndex = input.indexOf("#");
|
|
246
|
+
if (fragmentIndex < 0) {
|
|
247
|
+
return { did: input, fragment: "" };
|
|
248
|
+
}
|
|
249
|
+
return {
|
|
250
|
+
did: input.slice(0, fragmentIndex),
|
|
251
|
+
fragment: input.slice(fragmentIndex)
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
function assertValidChainId(chainId) {
|
|
255
|
+
if (!Number.isSafeInteger(chainId) || chainId <= 0) {
|
|
256
|
+
throw new IdentityParseError(`Invalid EIP-155 chain ID: ${chainId}`);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function isEvmAddress(input) {
|
|
260
|
+
return (0, import_viem.isAddress)(input, { strict: false });
|
|
261
|
+
}
|
|
262
|
+
function canonicalizeAddress(address) {
|
|
263
|
+
if (!isEvmAddress(address)) {
|
|
264
|
+
throw new IdentityParseError(`Invalid EVM address: ${address}`);
|
|
265
|
+
}
|
|
266
|
+
return (0, import_viem.getAddress)(address);
|
|
267
|
+
}
|
|
268
|
+
function addressStorageKey(address) {
|
|
269
|
+
return canonicalizeAddress(address).toLowerCase();
|
|
270
|
+
}
|
|
271
|
+
function pkhDid(address, chainId = 1) {
|
|
272
|
+
assertValidChainId(chainId);
|
|
273
|
+
return `did:pkh:eip155:${chainId}:${canonicalizeAddress(address)}`;
|
|
274
|
+
}
|
|
275
|
+
function parsePkhDid(did) {
|
|
276
|
+
const match = did.match(PKH_DID_RE);
|
|
277
|
+
if (!match) return null;
|
|
278
|
+
const chainId = Number(match[1]);
|
|
279
|
+
assertValidChainId(chainId);
|
|
280
|
+
return {
|
|
281
|
+
method: "pkh",
|
|
282
|
+
namespace: "eip155",
|
|
283
|
+
chainId,
|
|
284
|
+
address: canonicalizeAddress(match[2])
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
function canonicalizeDid(did) {
|
|
288
|
+
const pkh = parsePkhDid(did);
|
|
289
|
+
if (pkh) {
|
|
290
|
+
return pkhDid(pkh.address, pkh.chainId);
|
|
291
|
+
}
|
|
292
|
+
if (DID_RE.test(did)) {
|
|
293
|
+
return did;
|
|
294
|
+
}
|
|
295
|
+
throw new IdentityParseError(`Invalid DID: ${did}`);
|
|
296
|
+
}
|
|
297
|
+
function canonicalizeDidUrl(didUrl) {
|
|
298
|
+
const { did, fragment } = splitDidUrl(didUrl);
|
|
299
|
+
return `${canonicalizeDid(did)}${fragment}`;
|
|
300
|
+
}
|
|
301
|
+
function principalDid(didUrl) {
|
|
302
|
+
return canonicalizeDid(splitDidUrl(didUrl).did);
|
|
303
|
+
}
|
|
304
|
+
function didEquals(a, b, options = {}) {
|
|
305
|
+
const canonicalize = options.ignoreFragment ? principalDid : canonicalizeDidUrl;
|
|
306
|
+
return canonicalize(a) === canonicalize(b);
|
|
307
|
+
}
|
|
308
|
+
function principalDidEquals(a, b) {
|
|
309
|
+
return didEquals(a, b, { ignoreFragment: true });
|
|
310
|
+
}
|
|
311
|
+
function didCacheKey(input, options = {}) {
|
|
312
|
+
const { did, fragment } = splitDidUrl(input);
|
|
313
|
+
const pkh = parsePkhDid(did);
|
|
314
|
+
const base = pkh ? `did:pkh:eip155:${pkh.chainId}:${addressStorageKey(pkh.address)}` : canonicalizeDid(did);
|
|
315
|
+
return options.preserveFragment ? `${base}${fragment}` : base;
|
|
316
|
+
}
|
|
317
|
+
function makePkhSpaceId(address, chainId, name) {
|
|
318
|
+
assertValidChainId(chainId);
|
|
319
|
+
if (!name) {
|
|
320
|
+
throw new IdentityParseError("Space name cannot be empty");
|
|
321
|
+
}
|
|
322
|
+
return `tinycloud:pkh:eip155:${chainId}:${canonicalizeAddress(address)}:${name}`;
|
|
323
|
+
}
|
|
324
|
+
|
|
221
325
|
// src/storage.schema.ts
|
|
222
326
|
var import_zod2 = require("zod");
|
|
223
327
|
var ethereumAddressPattern = /^0x[a-fA-F0-9]{40}$/;
|
|
@@ -915,6 +1019,14 @@ var DEFAULT_SIGNED_READ_URL_EXPIRY_MS = EXPIRY.SIGNED_READ_URL_MS;
|
|
|
915
1019
|
|
|
916
1020
|
// src/spaces/SpaceService.ts
|
|
917
1021
|
var SERVICE_NAME = "space";
|
|
1022
|
+
function ownerDidEquals(a, b) {
|
|
1023
|
+
if (!b) return false;
|
|
1024
|
+
try {
|
|
1025
|
+
return principalDidEquals(a, b);
|
|
1026
|
+
} catch {
|
|
1027
|
+
return a === b;
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
918
1030
|
var SpaceErrorCodes = {
|
|
919
1031
|
/** Space not found */
|
|
920
1032
|
NOT_FOUND: "SPACE_NOT_FOUND",
|
|
@@ -932,7 +1044,7 @@ var SpaceErrorCodes = {
|
|
|
932
1044
|
NOT_INITIALIZED: "NOT_INITIALIZED"
|
|
933
1045
|
};
|
|
934
1046
|
function makePublicSpaceId(address, chainId) {
|
|
935
|
-
return
|
|
1047
|
+
return makePkhSpaceId(address, chainId, "public");
|
|
936
1048
|
}
|
|
937
1049
|
function parseSpaceUri(uri) {
|
|
938
1050
|
const fullUriMatch = uri.match(
|
|
@@ -940,12 +1052,18 @@ function parseSpaceUri(uri) {
|
|
|
940
1052
|
);
|
|
941
1053
|
if (fullUriMatch) {
|
|
942
1054
|
const [, chainId, address, name] = fullUriMatch;
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
1055
|
+
try {
|
|
1056
|
+
const chainIdNumber = Number(chainId);
|
|
1057
|
+
const canonicalAddress = canonicalizeAddress(address);
|
|
1058
|
+
return {
|
|
1059
|
+
owner: pkhDid(canonicalAddress, chainIdNumber),
|
|
1060
|
+
name,
|
|
1061
|
+
chainId: String(chainIdNumber),
|
|
1062
|
+
address: canonicalAddress
|
|
1063
|
+
};
|
|
1064
|
+
} catch {
|
|
1065
|
+
return null;
|
|
1066
|
+
}
|
|
949
1067
|
}
|
|
950
1068
|
if (/^[a-zA-Z0-9_-]+$/.test(uri)) {
|
|
951
1069
|
return {
|
|
@@ -957,10 +1075,9 @@ function parseSpaceUri(uri) {
|
|
|
957
1075
|
return null;
|
|
958
1076
|
}
|
|
959
1077
|
function buildSpaceUri(owner, name) {
|
|
960
|
-
const
|
|
961
|
-
if (
|
|
962
|
-
|
|
963
|
-
return `tinycloud:pkh:eip155:${chainId}:${address}:${name}`;
|
|
1078
|
+
const pkh = parsePkhDid(owner);
|
|
1079
|
+
if (pkh) {
|
|
1080
|
+
return makePkhSpaceId(pkh.address, pkh.chainId, name);
|
|
964
1081
|
}
|
|
965
1082
|
return `tinycloud:${owner}:${name}`;
|
|
966
1083
|
}
|
|
@@ -1409,7 +1526,7 @@ var SpaceService = class {
|
|
|
1409
1526
|
id: data.id,
|
|
1410
1527
|
name: data.name ?? this.extractNameFromId(data.id),
|
|
1411
1528
|
owner: data.owner,
|
|
1412
|
-
type: data.type ?? (data.owner
|
|
1529
|
+
type: data.type ?? (ownerDidEquals(data.owner, this.userDid) ? "owned" : "delegated"),
|
|
1413
1530
|
permissions: data.permissions,
|
|
1414
1531
|
expiresAt: data.expiresAt ? new Date(data.expiresAt) : void 0
|
|
1415
1532
|
};
|
|
@@ -4762,7 +4879,7 @@ var import_multiaddr_to_uri = require("@multiformats/multiaddr-to-uri");
|
|
|
4762
4879
|
var import_uri_to_multiaddr = require("@multiformats/uri-to-multiaddr");
|
|
4763
4880
|
var import_ed25519 = require("@noble/curves/ed25519");
|
|
4764
4881
|
var import_basics = require("multiformats/basics");
|
|
4765
|
-
var
|
|
4882
|
+
var import_viem2 = require("viem");
|
|
4766
4883
|
var DEFAULT_TINYCLOUD_LOCATION_REGISTRY_URL = "https://registry.tinycloud.xyz";
|
|
4767
4884
|
var DEFAULT_TINYCLOUD_FALLBACK_HOST = "https://node.tinycloud.xyz";
|
|
4768
4885
|
var LocationRecordValidationError = class extends Error {
|
|
@@ -5068,7 +5185,7 @@ async function verifyPkhSignature(did, payload, signature) {
|
|
|
5068
5185
|
if (!/^0x[0-9a-fA-F]+$/.test(signature)) {
|
|
5069
5186
|
throw new LocationRecordValidationError("did:pkh signature must be hex");
|
|
5070
5187
|
}
|
|
5071
|
-
return (0,
|
|
5188
|
+
return (0, import_viem2.verifyMessage)({
|
|
5072
5189
|
address,
|
|
5073
5190
|
message: payload,
|
|
5074
5191
|
signature
|
|
@@ -5303,6 +5420,7 @@ function parseRecapCapabilities(parseWasm, siwe) {
|
|
|
5303
5420
|
EnsDataSchema,
|
|
5304
5421
|
ErrorCodes,
|
|
5305
5422
|
HooksService,
|
|
5423
|
+
IdentityParseError,
|
|
5306
5424
|
KVService,
|
|
5307
5425
|
LocationRecordValidationError,
|
|
5308
5426
|
ManifestValidationError,
|
|
@@ -5333,6 +5451,7 @@ function parseRecapCapabilities(parseWasm, siwe) {
|
|
|
5333
5451
|
VaultPublicSpaceKVActions,
|
|
5334
5452
|
VersionCheckError,
|
|
5335
5453
|
activateSessionWithHost,
|
|
5454
|
+
addressStorageKey,
|
|
5336
5455
|
applyPrefix,
|
|
5337
5456
|
buildCanonicalDecryptRequest,
|
|
5338
5457
|
buildDecryptAttenuation,
|
|
@@ -5343,6 +5462,9 @@ function parseRecapCapabilities(parseWasm, siwe) {
|
|
|
5343
5462
|
canonicalHashHex,
|
|
5344
5463
|
canonicalLocationPayload,
|
|
5345
5464
|
canonicalSignedResponse,
|
|
5465
|
+
canonicalizeAddress,
|
|
5466
|
+
canonicalizeDid,
|
|
5467
|
+
canonicalizeDidUrl,
|
|
5346
5468
|
canonicalizeEncryptionJson,
|
|
5347
5469
|
canonicalizeSecretScope,
|
|
5348
5470
|
checkDecryptInvocationInput,
|
|
@@ -5357,6 +5479,8 @@ function parseRecapCapabilities(parseWasm, siwe) {
|
|
|
5357
5479
|
defaultSignStrategy,
|
|
5358
5480
|
defaultSpaceCreationHandler,
|
|
5359
5481
|
deriveSignedReceiverKey,
|
|
5482
|
+
didCacheKey,
|
|
5483
|
+
didEquals,
|
|
5360
5484
|
discoverNetwork,
|
|
5361
5485
|
encryptToNetwork,
|
|
5362
5486
|
encryptionBase64Decode,
|
|
@@ -5376,9 +5500,11 @@ function parseRecapCapabilities(parseWasm, siwe) {
|
|
|
5376
5500
|
hexEncode,
|
|
5377
5501
|
httpUrlToMultiaddr,
|
|
5378
5502
|
isCapabilitySubset,
|
|
5503
|
+
isEvmAddress,
|
|
5379
5504
|
isNetworkId,
|
|
5380
5505
|
loadManifest,
|
|
5381
5506
|
locationPayloadForRecord,
|
|
5507
|
+
makePkhSpaceId,
|
|
5382
5508
|
makePublicSpaceId,
|
|
5383
5509
|
manifestAbilitiesUnion,
|
|
5384
5510
|
multiaddrToHttpUrl,
|
|
@@ -5388,8 +5514,12 @@ function parseRecapCapabilities(parseWasm, siwe) {
|
|
|
5388
5514
|
openWrappedKey,
|
|
5389
5515
|
parseExpiry,
|
|
5390
5516
|
parseNetworkId,
|
|
5517
|
+
parsePkhDid,
|
|
5391
5518
|
parseRecapCapabilities,
|
|
5392
5519
|
parseSpaceUri,
|
|
5520
|
+
pkhDid,
|
|
5521
|
+
principalDid,
|
|
5522
|
+
principalDidEquals,
|
|
5393
5523
|
resolveCloudLocation,
|
|
5394
5524
|
resolveManifest,
|
|
5395
5525
|
resolveSecretListPrefix,
|