@novasamatech/host-container 0.6.14 → 0.6.16

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.
@@ -22,15 +22,18 @@ export function createContainer(provider) {
22
22
  let current = defaultHandler;
23
23
  let version = 0;
24
24
  transport.handleRequest(method, params => current(params));
25
- return handler => {
26
- current = handler;
27
- const myVersion = ++version;
28
- return () => {
29
- if (myVersion !== version)
30
- return;
31
- version++;
32
- current = defaultHandler;
33
- };
25
+ return {
26
+ update: handler => {
27
+ current = handler;
28
+ const myVersion = ++version;
29
+ return () => {
30
+ if (myVersion !== version)
31
+ return;
32
+ version++;
33
+ current = defaultHandler;
34
+ };
35
+ },
36
+ call: (...args) => current(...args),
34
37
  };
35
38
  }
36
39
  function makeSubscriptionSlot(method, defaultHandler) {
@@ -103,7 +106,7 @@ export function createContainer(provider) {
103
106
  const error = new GenericError({ reason: NOT_IMPLEMENTED });
104
107
  return enumValue('v1', resultErr(error));
105
108
  });
106
- const handlePermissionSlot = makeRequestSlot('remote_permission', async () => {
109
+ const handleRemotePermissionSlot = makeRequestSlot('remote_permission', async () => {
107
110
  const error = new GenericError({ reason: NOT_IMPLEMENTED });
108
111
  return enumValue('v1', resultErr(error));
109
112
  });
@@ -174,7 +177,7 @@ export function createContainer(provider) {
174
177
  return {
175
178
  handleFeatureSupported(handler) {
176
179
  init();
177
- return handleFeatureSupportedSlot(async (message) => {
180
+ return handleFeatureSupportedSlot.update(async (message) => {
178
181
  const version = 'v1';
179
182
  const error = new GenericError({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
180
183
  return guardVersion(message, version, error)
@@ -186,7 +189,7 @@ export function createContainer(provider) {
186
189
  },
187
190
  handleDevicePermission(handler) {
188
191
  init();
189
- return handleDevicePermissionSlot(async (message) => {
192
+ return handleDevicePermissionSlot.update(async (message) => {
190
193
  const version = 'v1';
191
194
  const error = new GenericError({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
192
195
  return guardVersion(message, version, error)
@@ -198,7 +201,7 @@ export function createContainer(provider) {
198
201
  },
199
202
  handlePermission(handler) {
200
203
  init();
201
- return handlePermissionSlot(async (message) => {
204
+ return handleRemotePermissionSlot.update(async (message) => {
202
205
  const version = 'v1';
203
206
  const error = new GenericError({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
204
207
  return guardVersion(message, version, error)
@@ -210,7 +213,7 @@ export function createContainer(provider) {
210
213
  },
211
214
  handlePushNotification(handler) {
212
215
  init();
213
- return handlePushNotificationSlot(async (message) => {
216
+ return handlePushNotificationSlot.update(async (message) => {
214
217
  const version = 'v1';
215
218
  const error = new GenericError({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
216
219
  return guardVersion(message, version, error)
@@ -222,7 +225,7 @@ export function createContainer(provider) {
222
225
  },
223
226
  handleNavigateTo(handler) {
224
227
  init();
225
- return handleNavigateToSlot(async (message) => {
228
+ return handleNavigateToSlot.update(async (message) => {
226
229
  const version = 'v1';
227
230
  const error = new NavigateToErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
228
231
  return guardVersion(message, version, error)
@@ -234,7 +237,7 @@ export function createContainer(provider) {
234
237
  },
235
238
  handleLocalStorageRead(handler) {
236
239
  init();
237
- return handleLocalStorageReadSlot(async (message) => {
240
+ return handleLocalStorageReadSlot.update(async (message) => {
238
241
  const version = 'v1';
239
242
  const error = new StorageErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
240
243
  return guardVersion(message, version, error)
@@ -246,7 +249,7 @@ export function createContainer(provider) {
246
249
  },
247
250
  handleLocalStorageWrite(handler) {
248
251
  init();
249
- return handleLocalStorageWriteSlot(async (message) => {
252
+ return handleLocalStorageWriteSlot.update(async (message) => {
250
253
  const version = 'v1';
251
254
  const error = new StorageErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
252
255
  return guardVersion(message, version, error)
@@ -258,7 +261,7 @@ export function createContainer(provider) {
258
261
  },
259
262
  handleLocalStorageClear(handler) {
260
263
  init();
261
- return handleLocalStorageClearSlot(async (message) => {
264
+ return handleLocalStorageClearSlot.update(async (message) => {
262
265
  const version = 'v1';
263
266
  const error = new StorageErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
264
267
  return guardVersion(message, version, error)
@@ -282,7 +285,7 @@ export function createContainer(provider) {
282
285
  },
283
286
  handleAccountGet(handler) {
284
287
  init();
285
- return handleAccountGetSlot(async (params) => {
288
+ return handleAccountGetSlot.update(async (params) => {
286
289
  const version = 'v1';
287
290
  const error = new RequestCredentialsErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
288
291
  return guardVersion(params, version, error)
@@ -294,7 +297,7 @@ export function createContainer(provider) {
294
297
  },
295
298
  handleAccountGetAlias(handler) {
296
299
  init();
297
- return handleAccountGetAliasSlot(async (params) => {
300
+ return handleAccountGetAliasSlot.update(async (params) => {
298
301
  const version = 'v1';
299
302
  const error = new RequestCredentialsErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
300
303
  return guardVersion(params, version, error)
@@ -306,7 +309,7 @@ export function createContainer(provider) {
306
309
  },
307
310
  handleAccountCreateProof(handler) {
308
311
  init();
309
- return handleAccountCreateProofSlot(async (params) => {
312
+ return handleAccountCreateProofSlot.update(async (params) => {
310
313
  const version = 'v1';
311
314
  const error = new CreateProofErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
312
315
  return guardVersion(params, version, error)
@@ -318,7 +321,7 @@ export function createContainer(provider) {
318
321
  },
319
322
  handleGetNonProductAccounts(handler) {
320
323
  init();
321
- return handleGetNonProductAccountsSlot(async (params) => {
324
+ return handleGetNonProductAccountsSlot.update(async (params) => {
322
325
  const version = 'v1';
323
326
  const error = new RequestCredentialsErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
324
327
  return guardVersion(params, version, error)
@@ -330,7 +333,7 @@ export function createContainer(provider) {
330
333
  },
331
334
  handleCreateTransaction(handler) {
332
335
  init();
333
- return handleCreateTransactionSlot(async (params) => {
336
+ return handleCreateTransactionSlot.update(async (params) => {
334
337
  const version = 'v1';
335
338
  const error = new CreateTransactionErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
336
339
  return guardVersion(params, version, error)
@@ -342,7 +345,7 @@ export function createContainer(provider) {
342
345
  },
343
346
  handleCreateTransactionWithNonProductAccount(handler) {
344
347
  init();
345
- return handleCreateTransactionWithNonProductAccountSlot(async (params) => {
348
+ return handleCreateTransactionWithNonProductAccountSlot.update(async (params) => {
346
349
  const version = 'v1';
347
350
  const error = new CreateTransactionErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
348
351
  return guardVersion(params, version, error)
@@ -354,7 +357,7 @@ export function createContainer(provider) {
354
357
  },
355
358
  handleSignRaw(handler) {
356
359
  init();
357
- return handleSignRawSlot(async (params) => {
360
+ return handleSignRawSlot.update(async (params) => {
358
361
  const version = 'v1';
359
362
  const error = new SigningErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
360
363
  return guardVersion(params, version, error)
@@ -366,7 +369,7 @@ export function createContainer(provider) {
366
369
  },
367
370
  handleSignPayload(handler) {
368
371
  init();
369
- return handleSignPayloadSlot(async (params) => {
372
+ return handleSignPayloadSlot.update(async (params) => {
370
373
  const version = 'v1';
371
374
  const error = new SigningErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
372
375
  return guardVersion(params, version, error)
@@ -378,7 +381,7 @@ export function createContainer(provider) {
378
381
  },
379
382
  handleChatCreateRoom(handler) {
380
383
  init();
381
- return handleChatCreateRoomSlot(async (params) => {
384
+ return handleChatCreateRoomSlot.update(async (params) => {
382
385
  const version = 'v1';
383
386
  const error = new ChatRoomRegistrationErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
384
387
  return guardVersion(params, version, error)
@@ -390,7 +393,7 @@ export function createContainer(provider) {
390
393
  },
391
394
  handleChatBotRegistration(handler) {
392
395
  init();
393
- return handleChatBotRegistrationSlot(async (params) => {
396
+ return handleChatBotRegistrationSlot.update(async (params) => {
394
397
  const version = 'v1';
395
398
  const error = new ChatBotRegistrationErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
396
399
  return guardVersion(params, version, error)
@@ -414,7 +417,7 @@ export function createContainer(provider) {
414
417
  },
415
418
  handleChatPostMessage(handler) {
416
419
  init();
417
- return handleChatPostMessageSlot(async (params) => {
420
+ return handleChatPostMessageSlot.update(async (params) => {
418
421
  const version = 'v1';
419
422
  const error = new ChatMessagePostingErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
420
423
  return guardVersion(params, version, error)
@@ -458,7 +461,7 @@ export function createContainer(provider) {
458
461
  },
459
462
  handleStatementStoreCreateProof(handler) {
460
463
  init();
461
- return handleStatementStoreCreateProofSlot(async (params) => {
464
+ return handleStatementStoreCreateProofSlot.update(async (params) => {
462
465
  const version = 'v1';
463
466
  const error = new StatementProofErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
464
467
  return guardVersion(params, version, error)
@@ -470,7 +473,7 @@ export function createContainer(provider) {
470
473
  },
471
474
  handleStatementStoreSubmit(handler) {
472
475
  init();
473
- return handleStatementStoreSubmitSlot(async (params) => {
476
+ return handleStatementStoreSubmitSlot.update(async (params) => {
474
477
  const version = 'v1';
475
478
  const error = new GenericError({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
476
479
  return guardVersion(params, version, error)
@@ -494,7 +497,7 @@ export function createContainer(provider) {
494
497
  },
495
498
  handlePreimageSubmit(handler) {
496
499
  init();
497
- return handlePreimageSubmitSlot(async (params) => {
500
+ return handlePreimageSubmitSlot.update(async (params) => {
498
501
  const version = 'v1';
499
502
  const error = new PreimageSubmitErr.Unknown({ reason: UNSUPPORTED_MESSAGE_FORMAT_ERROR });
500
503
  return guardVersion(params, version, error)
@@ -505,7 +508,7 @@ export function createContainer(provider) {
505
508
  });
506
509
  },
507
510
  // chain interaction
508
- handleChainConnection({ factory, submitPermission }) {
511
+ handleChainConnection(factory) {
509
512
  init();
510
513
  const manager = createChainConnectionManager(factory);
511
514
  const cleanups = [];
@@ -741,7 +744,10 @@ export function createContainer(provider) {
741
744
  }
742
745
  const { genesisHash, transaction } = message.value;
743
746
  try {
744
- const permissionGranted = await submitPermission(transaction);
747
+ const permissionResponse = await handleRemotePermissionSlot.call(enumValue('v1', enumValue('TransactionSubmit', undefined)));
748
+ const permissionGranted = isEnumVariant(permissionResponse, 'v1') &&
749
+ permissionResponse.value.success === true &&
750
+ permissionResponse.value.value === true;
745
751
  if (!permissionGranted) {
746
752
  return enumValue('v1', resultErr(new GenericError({ reason: 'Permission denied' })));
747
753
  }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Derives 32 bytes of deterministic entropy using the three-layer
3
+ * BLAKE2b-256 scheme specified in RFC-0007.
4
+ *
5
+ * @param rootAccountSecret - Raw BIP-39 entropy bytes of the root account
6
+ * @param productId - Identifier of the calling product (arbitrary-length string)
7
+ * @param key - Caller-chosen key, up to 32 bytes
8
+ */
9
+ export declare function deriveProductEntropy(rootAccountSecret: Uint8Array, productId: string, key: Uint8Array): Uint8Array;
@@ -0,0 +1,24 @@
1
+ import { blake2b } from '@noble/hashes/blake2.js';
2
+ function blake2b256Keyed(message, key) {
3
+ return blake2b(message, { dkLen: 32, key });
4
+ }
5
+ function blake2b256(message) {
6
+ return blake2b(message, { dkLen: 32 });
7
+ }
8
+ /**
9
+ * Derives 32 bytes of deterministic entropy using the three-layer
10
+ * BLAKE2b-256 scheme specified in RFC-0007.
11
+ *
12
+ * @param rootAccountSecret - Raw BIP-39 entropy bytes of the root account
13
+ * @param productId - Identifier of the calling product (arbitrary-length string)
14
+ * @param key - Caller-chosen key, up to 32 bytes
15
+ */
16
+ export function deriveProductEntropy(rootAccountSecret, productId, key) {
17
+ if (key.length === 0 || key.length > 32) {
18
+ throw new Error(`"key" must be between 1 and 32 bytes, got ${key.length}`);
19
+ }
20
+ const textEncoder = new TextEncoder();
21
+ const rootEntropySource = blake2b256Keyed(rootAccountSecret, textEncoder.encode('product-entropy-derivation'));
22
+ const perProductEntropy = blake2b256Keyed(rootEntropySource, blake2b256(textEncoder.encode(productId)));
23
+ return blake2b256Keyed(perProductEntropy, key);
24
+ }
package/dist/types.d.ts CHANGED
@@ -83,10 +83,7 @@ export type Container = {
83
83
  handleStatementStoreSubmit: InferHandler<'v1', HostApiProtocol['remote_statement_store_submit']>;
84
84
  handlePreimageLookupSubscribe: InferHandler<'v1', HostApiProtocol['remote_preimage_lookup_subscribe']>;
85
85
  handlePreimageSubmit: InferHandler<'v1', HostApiProtocol['remote_preimage_submit']>;
86
- handleChainConnection: (params: {
87
- factory: (genesisHash: HexString) => JsonRpcProvider | null;
88
- submitPermission: (transaction: HexString) => Promise<boolean> | boolean;
89
- }) => VoidFunction;
86
+ handleChainConnection: (factory: (genesisHash: HexString) => JsonRpcProvider | null) => VoidFunction;
90
87
  isReady(): Promise<boolean>;
91
88
  dispose(): void;
92
89
  subscribeProductConnectionStatus(callback: (connectionStatus: ConnectionStatus) => void): VoidFunction;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@novasamatech/host-container",
3
3
  "type": "module",
4
- "version": "0.6.14",
4
+ "version": "0.6.16",
5
5
  "description": "Host container for hosting and managing products within the Polkadot ecosystem.",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -27,11 +27,11 @@
27
27
  "dependencies": {
28
28
  "@polkadot-api/utils": "^0.2.0",
29
29
  "@polkadot-api/json-rpc-provider": "^0.0.4",
30
- "@novasamatech/host-api": "0.6.14",
30
+ "@novasamatech/host-api": "0.6.16",
31
31
  "nanoid": "5.1.7"
32
32
  },
33
33
  "devDependencies": {
34
- "electron": "^41.0.2"
34
+ "electron": "^41.1.0"
35
35
  },
36
36
  "publishConfig": {
37
37
  "access": "public"