@novasamatech/host-container 0.7.5 → 0.7.7

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,4 +1,4 @@
1
- import { ChatBotRegistrationErr, ChatMessagePostingErr, ChatRoomRegistrationErr, CreateProofErr, CreateTransactionErr, DeriveEntropyErr, DevicePermission, GenericError, GetUserIdErr, LoginErr, NavigateToErr, PaymentBalanceErr, PaymentRequestErr, PaymentStatusErr, PaymentTopUpErr, PreimageSubmitErr, RemotePermission, RequestCredentialsErr, SigningErr, StatementProofErr, StorageErr, createTransport, enumValue, isEnumVariant, resultErr, resultOk, } from '@novasamatech/host-api';
1
+ import { ChatBotRegistrationErr, ChatMessagePostingErr, ChatRoomRegistrationErr, CreateProofErr, CreateTransactionErr, DeriveEntropyErr, DevicePermission, GenericError, GetUserIdErr, LoginErr, NavigateToErr, PaymentBalanceErr, PaymentRequestErr, PaymentStatusErr, PaymentTopUpErr, PreimageSubmitErr, RemotePermission, RequestCredentialsErr, ResourceAllocationErr, SigningErr, StatementProofErr, StorageErr, createTransport, enumValue, isEnumVariant, resultErr, resultOk, } from '@novasamatech/host-api';
2
2
  import { err, errAsync, ok, okAsync } from 'neverthrow';
3
3
  import { createChainConnectionManager } from './chainConnectionManager.js';
4
4
  const UNSUPPORTED_MESSAGE_FORMAT_ERROR = 'Unsupported message format';
@@ -183,10 +183,13 @@ export function createContainer(provider) {
183
183
  const handleChatPostMessageSlot = makeNotImplementedSlot('host_chat_post_message', () => new ChatMessagePostingErr.Unknown({ reason: NOT_IMPLEMENTED }));
184
184
  const handleStatementStoreSubmitSlot = makePermissionGatedRequestSlot('remote_statement_store_submit', 'StatementSubmit', () => new GenericError({ reason: NOT_IMPLEMENTED }));
185
185
  const handleStatementStoreCreateProofSlot = makeNotImplementedSlot('remote_statement_store_create_proof', () => new StatementProofErr.Unknown({ reason: NOT_IMPLEMENTED }));
186
+ const handleStatementStoreCreateProofAuthorizedSlot = makeNotImplementedSlot('remote_statement_store_create_proof_authorized', () => new StatementProofErr.Unknown({ reason: NOT_IMPLEMENTED }));
186
187
  const handlePreimageSubmitSlot = makePermissionGatedRequestSlot('remote_preimage_submit', 'PreimageSubmit', () => new PreimageSubmitErr.Unknown({ reason: NOT_IMPLEMENTED }));
187
188
  // payment request slots
188
189
  const handlePaymentTopUpSlot = makeNotImplementedSlot('host_payment_top_up', () => new PaymentTopUpErr.Unknown({ reason: NOT_IMPLEMENTED }));
189
190
  const handlePaymentRequestSlot = makeNotImplementedSlot('host_payment_request', () => new PaymentRequestErr.Unknown({ reason: NOT_IMPLEMENTED }));
191
+ // resource allocation slot
192
+ const handleRequestResourceAllocationSlot = makeNotImplementedSlot('host_request_resource_allocation', () => new ResourceAllocationErr.Unknown({ reason: NOT_IMPLEMENTED }));
190
193
  // subscription slots — default interrupts on next microtask so that
191
194
  // the caller has a chance to register an onInterrupt listener first
192
195
  const handleThemeSubscribeSlot = makeInterruptSlot('host_theme_subscribe', () => enumValue('v1', undefined));
@@ -296,6 +299,9 @@ export function createContainer(provider) {
296
299
  handleStatementStoreCreateProof(handler) {
297
300
  return handleV1Request(handleStatementStoreCreateProofSlot, () => new StatementProofErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR }), handler);
298
301
  },
302
+ handleStatementStoreCreateProofAuthorized(handler) {
303
+ return handleV1Request(handleStatementStoreCreateProofAuthorizedSlot, () => new StatementProofErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR }), handler);
304
+ },
299
305
  handleStatementStoreSubmit(handler) {
300
306
  return handleV1Request(handleStatementStoreSubmitSlot, () => new GenericError({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR }), handler);
301
307
  },
@@ -317,6 +323,9 @@ export function createContainer(provider) {
317
323
  handlePaymentStatusSubscribe(handler) {
318
324
  return handleV1Subscription(handlePaymentStatusSubscribeSlot, handler);
319
325
  },
326
+ handleRequestResourceAllocation(handler) {
327
+ return handleV1Request(handleRequestResourceAllocationSlot, () => new ResourceAllocationErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR }), handler);
328
+ },
320
329
  // chain interaction
321
330
  handleChainConnection(factory) {
322
331
  init();
@@ -544,26 +553,27 @@ export function createContainer(provider) {
544
553
  return enumValue('v1', resultErr(new GenericError({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR })));
545
554
  }
546
555
  const { genesisHash, transaction } = message.value;
556
+ const permissionResponse = await handleRemotePermissionSlot.call(enumValue('v1', enumValue('ChainSubmit', undefined)));
557
+ const permissionGranted = isEnumVariant(permissionResponse, 'v1') &&
558
+ permissionResponse.value.success === true &&
559
+ permissionResponse.value.value === true;
560
+ if (!permissionGranted) {
561
+ return enumValue('v1', resultErr(new GenericError({ reason: 'Permission denied' })));
562
+ }
563
+ const entry = manager.getOrCreateChain(genesisHash);
564
+ if (!entry) {
565
+ return enumValue('v1', resultErr(new GenericError({ reason: 'Chain not supported' })));
566
+ }
547
567
  try {
548
- const permissionResponse = await handleRemotePermissionSlot.call(enumValue('v1', enumValue('ChainSubmit', undefined)));
549
- const permissionGranted = isEnumVariant(permissionResponse, 'v1') &&
550
- permissionResponse.value.success === true &&
551
- permissionResponse.value.value === true;
552
- if (!permissionGranted) {
553
- return enumValue('v1', resultErr(new GenericError({ reason: 'Permission denied' })));
554
- }
555
- const entry = manager.getOrCreateChain(genesisHash);
556
- if (!entry) {
557
- return enumValue('v1', resultErr(new GenericError({ reason: 'Chain not supported' })));
558
- }
559
568
  const result = await manager.sendRequest(genesisHash, 'transaction_v1_broadcast', [transaction]);
560
- manager.releaseChain(genesisHash);
561
569
  return enumValue('v1', resultOk(result ?? null));
562
570
  }
563
571
  catch (e) {
564
- manager.releaseChain(genesisHash);
565
572
  return enumValue('v1', resultErr(new GenericError({ reason: String(e) })));
566
573
  }
574
+ finally {
575
+ manager.releaseChain(genesisHash);
576
+ }
567
577
  }));
568
578
  // Transaction stop
569
579
  cleanups.push(transport.handleRequest('remote_chain_transaction_stop', async (message) => {
@@ -25,14 +25,17 @@ export function createWebviewProvider({ webview, logger, openDevTools }) {
25
25
  const portInitMessage = `HOST_API_PORT_INIT_${nanoid(12)}`;
26
26
  await webview
27
27
  .executeJavaScript(`
28
- window.addEventListener('message', e => {
29
- if (e.data === '${portInitMessage}') {
28
+ (function() {
29
+ function handler(e) {
30
+ if (e.data !== '${portInitMessage}') return;
31
+ window.removeEventListener('message', handler);
30
32
  const port = e.ports[0];
31
33
  if (port) {
32
34
  window['${WEBVIEW_HOST_PORT_NAME}'] = port;
33
35
  }
34
36
  }
35
- });
37
+ window.addEventListener('message', handler);
38
+ })();
36
39
  `)
37
40
  .catch(reject);
38
41
  // @ts-expect-error contentWindow is undefined somehow
package/dist/types.d.ts CHANGED
@@ -88,6 +88,7 @@ export type Container = {
88
88
  }, callback: (node: CodecType<typeof CustomRendererNode>) => void): Subscription;
89
89
  handleStatementStoreSubscribe: InferHandler<'v1', HostApiProtocol['remote_statement_store_subscribe']>;
90
90
  handleStatementStoreCreateProof: InferHandler<'v1', HostApiProtocol['remote_statement_store_create_proof']>;
91
+ handleStatementStoreCreateProofAuthorized: InferHandler<'v1', HostApiProtocol['remote_statement_store_create_proof_authorized']>;
91
92
  handleStatementStoreSubmit: InferHandler<'v1', HostApiProtocol['remote_statement_store_submit']>;
92
93
  handlePreimageLookupSubscribe: InferHandler<'v1', HostApiProtocol['remote_preimage_lookup_subscribe']>;
93
94
  handlePreimageSubmit: InferHandler<'v1', HostApiProtocol['remote_preimage_submit']>;
@@ -95,6 +96,7 @@ export type Container = {
95
96
  handlePaymentTopUp: InferHandler<'v1', HostApiProtocol['host_payment_top_up']>;
96
97
  handlePaymentRequest: InferHandler<'v1', HostApiProtocol['host_payment_request']>;
97
98
  handlePaymentStatusSubscribe: InferHandler<'v1', HostApiProtocol['host_payment_status_subscribe']>;
99
+ handleRequestResourceAllocation: InferHandler<'v1', HostApiProtocol['host_request_resource_allocation']>;
98
100
  handleChainConnection: (factory: (genesisHash: HexString) => JsonRpcProvider | null) => VoidFunction;
99
101
  isReady(): Promise<boolean>;
100
102
  dispose(): void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@novasamatech/host-container",
3
3
  "type": "module",
4
- "version": "0.7.5",
4
+ "version": "0.7.7",
5
5
  "description": "Host container for hosting and managing products within the Polkadot ecosystem.",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -28,7 +28,7 @@
28
28
  "@noble/hashes": "2.2.0",
29
29
  "polkadot-api": ">=2",
30
30
  "@polkadot-api/substrate-client": "^0.7.0",
31
- "@novasamatech/host-api": "0.7.5",
31
+ "@novasamatech/host-api": "0.7.7",
32
32
  "nanoid": "5.1.9",
33
33
  "neverthrow": "^8.2.0"
34
34
  },