@tinycloud/node-sdk 3.8.0 → 3.8.1-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { NamedKeyClient } from '@tinycloud/sdk-services/encryption/named-keys';
2
2
  export { DecryptManyResult, KeyCallOptions, KeyDescriptor, KeyEncryptOptions, NamedKeyClient, NamedKeyEnvelope, NamedKeyError, NamedKeyErrorCode, PublicKeyDescriptor, buildKeyAdminFacts, buildKeyDescribeFacts } from '@tinycloud/sdk-services/encryption/named-keys';
3
- import { T as TinyCloudNode } from './TinyCloudNode-DaD5vJhL.cjs';
3
+ import { T as TinyCloudNode } from './TinyCloudNode-BhWBbCay.cjs';
4
4
  import '@tinycloud/sdk-core';
5
5
  import '@tinycloud/sdk-services/kv/replication';
6
6
  import '@tinycloud/sdk-services';
@@ -1,6 +1,6 @@
1
1
  import { NamedKeyClient } from '@tinycloud/sdk-services/encryption/named-keys';
2
2
  export { DecryptManyResult, KeyCallOptions, KeyDescriptor, KeyEncryptOptions, NamedKeyClient, NamedKeyEnvelope, NamedKeyError, NamedKeyErrorCode, PublicKeyDescriptor, buildKeyAdminFacts, buildKeyDescribeFacts } from '@tinycloud/sdk-services/encryption/named-keys';
3
- import { T as TinyCloudNode } from './TinyCloudNode-k3TbBwwj.js';
3
+ import { T as TinyCloudNode } from './TinyCloudNode-BjJJIifr.js';
4
4
  import '@tinycloud/sdk-core';
5
5
  import '@tinycloud/sdk-services/kv/replication';
6
6
  import '@tinycloud/sdk-services';
package/dist/index.cjs CHANGED
@@ -26332,7 +26332,7 @@ var _TinyCloudNode = class _TinyCloudNode {
26332
26332
  if (existingGrants.length > 0) {
26333
26333
  return existingGrants.map((grant) => grant.delegation);
26334
26334
  }
26335
- if (!this.signer) {
26335
+ if (!this.signer && options?.signMessage === void 0) {
26336
26336
  throw new Error(
26337
26337
  "grantRuntimePermissions requires wallet mode with a signer or privateKey."
26338
26338
  );
@@ -26396,7 +26396,13 @@ var _TinyCloudNode = class _TinyCloudNode {
26396
26396
  throw new Error("Prepared runtime permission targets a different session key.");
26397
26397
  }
26398
26398
  assertCapturedKey?.();
26399
- const signature2 = await this.signer.signMessage(prepared.siwe);
26399
+ if (options?.signMessage !== void 0) {
26400
+ this.assertRuntimeGrantMessage(prepared.siwe, session);
26401
+ }
26402
+ const signature2 = options?.signMessage !== void 0 ? await options.signMessage(prepared.siwe) : await this.signer.signMessage(prepared.siwe);
26403
+ if (options?.signMessage !== void 0 && !await (0, import_sdk_core10.verifyEip191MessageSignature)(prepared.siwe, signature2, session.address)) {
26404
+ throw new Error("The signature does not match the account that owns this session.");
26405
+ }
26400
26406
  graph.assertActive();
26401
26407
  assertCapturedKey?.();
26402
26408
  const delegatedSession = this.wasmBindings.completeSessionSetup({
@@ -27214,6 +27220,25 @@ var _TinyCloudNode = class _TinyCloudNode {
27214
27220
  expandPermissionEntries(permissions) {
27215
27221
  return (0, import_sdk_core10.expandPermissionEntries)(permissions);
27216
27222
  }
27223
+ /**
27224
+ * Checks the SIWE text a caller-supplied signer is asked to sign: it must be in canonical form (parsing and
27225
+ * re-serializing it gives the same bytes) and name the session's account and chain. The caller then checks the
27226
+ * signature against these exact bytes.
27227
+ */
27228
+ assertRuntimeGrantMessage(siwe, session) {
27229
+ let parsed;
27230
+ try {
27231
+ parsed = new import_siwe2.SiweMessage(siwe);
27232
+ } catch {
27233
+ throw new Error("The prepared sign-in message is not a valid SIWE message.");
27234
+ }
27235
+ if (parsed.prepareMessage() !== siwe) {
27236
+ throw new Error("The prepared sign-in message is not in canonical form.");
27237
+ }
27238
+ if (parsed.chainId !== session.chainId || (0, import_sdk_core10.canonicalizeAddress)(parsed.address) !== (0, import_sdk_core10.canonicalizeAddress)(session.address)) {
27239
+ throw new Error("The prepared sign-in message is for a different account or chain than this session.");
27240
+ }
27241
+ }
27217
27242
  /**
27218
27243
  * The current WASM child-delegation APIs accept action-only maps. Refuse any
27219
27244
  * constrained branch rather than signing a broader action-only child UCAN.