@novasamatech/host-api 0.9.4 → 0.10.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.
Files changed (53) hide show
  1. package/dist/hostApi.js +102 -3
  2. package/dist/index.d.ts +7 -1
  3. package/dist/index.js +6 -1
  4. package/dist/protocol/callError.d.ts +63 -0
  5. package/dist/protocol/callError.js +57 -0
  6. package/dist/protocol/impl.d.ts +370 -54
  7. package/dist/protocol/impl.js +86 -10
  8. package/dist/protocol/messageCodec.d.ts +903 -109
  9. package/dist/protocol/v1/accounts.d.ts +10 -10
  10. package/dist/protocol/v1/accounts.js +12 -11
  11. package/dist/protocol/v1/chainInteraction.d.ts +44 -12
  12. package/dist/protocol/v1/chainInteraction.js +25 -15
  13. package/dist/protocol/v1/chat.d.ts +3 -3
  14. package/dist/protocol/v1/chat.js +5 -4
  15. package/dist/protocol/v1/coinPayment.d.ts +345 -0
  16. package/dist/protocol/v1/coinPayment.js +105 -0
  17. package/dist/protocol/v1/createTransaction.d.ts +9 -9
  18. package/dist/protocol/v1/createTransaction.js +4 -3
  19. package/dist/protocol/v1/deriveEntropy.d.ts +1 -1
  20. package/dist/protocol/v1/deriveEntropy.js +2 -2
  21. package/dist/protocol/v1/devicePermission.d.ts +1 -1
  22. package/dist/protocol/v1/devicePermission.js +3 -2
  23. package/dist/protocol/v1/feature.d.ts +1 -1
  24. package/dist/protocol/v1/feature.js +3 -2
  25. package/dist/protocol/v1/handshake.d.ts +1 -1
  26. package/dist/protocol/v1/handshake.js +3 -2
  27. package/dist/protocol/v1/localStorage.d.ts +10 -3
  28. package/dist/protocol/v1/localStorage.js +10 -4
  29. package/dist/protocol/v1/locale.d.ts +8 -0
  30. package/dist/protocol/v1/locale.js +7 -0
  31. package/dist/protocol/v1/navigation.d.ts +1 -1
  32. package/dist/protocol/v1/navigation.js +3 -2
  33. package/dist/protocol/v1/notification.d.ts +2 -2
  34. package/dist/protocol/v1/notification.js +4 -3
  35. package/dist/protocol/v1/payments.d.ts +8 -8
  36. package/dist/protocol/v1/payments.js +4 -3
  37. package/dist/protocol/v1/preimage.d.ts +1 -1
  38. package/dist/protocol/v1/preimage.js +3 -2
  39. package/dist/protocol/v1/remotePermission.d.ts +1 -1
  40. package/dist/protocol/v1/remotePermission.js +3 -2
  41. package/dist/protocol/v1/resourceAllocation.d.ts +1 -1
  42. package/dist/protocol/v1/resourceAllocation.js +3 -2
  43. package/dist/protocol/v1/sign.d.ts +4 -4
  44. package/dist/protocol/v1/sign.js +6 -5
  45. package/dist/protocol/v1/statementStore.d.ts +3 -3
  46. package/dist/protocol/v1/statementStore.js +5 -4
  47. package/dist/protocol/v1/system.d.ts +23 -0
  48. package/dist/protocol/v1/system.js +21 -0
  49. package/dist/protocol/v1/worker.d.ts +37 -0
  50. package/dist/protocol/v1/worker.js +20 -0
  51. package/dist/transport.js +16 -2
  52. package/dist/transport.spec.js +18 -0
  53. package/package.json +3 -3
@@ -1,13 +1,17 @@
1
1
  import { Enum } from '@novasamatech/scale';
2
+ import { _void } from 'scale-ts';
3
+ import { interruptError } from './callError.js';
2
4
  import { AccountConnectionStatusV1_interrupt, AccountConnectionStatusV1_receive, AccountConnectionStatusV1_start, AccountCreateProofV1_request, AccountCreateProofV1_response, AccountGetAliasV1_request, AccountGetAliasV1_response, AccountGetV1_request, AccountGetV1_response, AccountListRingVrfKeysV1_request, AccountListRingVrfKeysV1_response, AccountRegisterRingVrfKeyV1_request, AccountRegisterRingVrfKeyV1_response, AccountRingVrfSignV1_request, AccountRingVrfSignV1_response, AccountSignVrfV1_request, AccountSignVrfV1_response, GetLegacyAccountsV1_request, GetLegacyAccountsV1_response, GetUserIdV1_request, GetUserIdV1_response, RequestLoginV1_request, RequestLoginV1_response, } from './v1/accounts.js';
3
- import { ChainHeadBodyV1_request, ChainHeadBodyV1_response, ChainHeadCallV1_request, ChainHeadCallV1_response, ChainHeadContinueV1_request, ChainHeadContinueV1_response, ChainHeadFollowV1_interrupt, ChainHeadFollowV1_receive, ChainHeadFollowV1_start, ChainHeadHeaderV1_request, ChainHeadHeaderV1_response, ChainHeadStopOperationV1_request, ChainHeadStopOperationV1_response, ChainHeadStorageV1_request, ChainHeadStorageV1_response, ChainHeadUnpinV1_request, ChainHeadUnpinV1_response, ChainSpecChainNameV1_request, ChainSpecChainNameV1_response, ChainSpecGenesisHashV1_request, ChainSpecGenesisHashV1_response, ChainSpecPropertiesV1_request, ChainSpecPropertiesV1_response, TransactionBroadcastV1_request, TransactionBroadcastV1_response, TransactionStopV1_request, TransactionStopV1_response, } from './v1/chainInteraction.js';
5
+ import { ChainHeadBodyV1_request, ChainHeadBodyV1_response, ChainHeadCallV1_request, ChainHeadCallV1_response, ChainHeadContinueV1_request, ChainHeadContinueV1_response, ChainHeadFollowV1_interrupt, ChainHeadFollowV1_receive, ChainHeadFollowV1_start, ChainHeadHeaderV1_request, ChainHeadHeaderV1_response, ChainHeadStopOperationV1_request, ChainHeadStopOperationV1_response, ChainHeadStorageV1_request, ChainHeadStorageV1_response, ChainHeadUnpinV1_request, ChainHeadUnpinV1_response, ChainInfoV1_request, ChainInfoV1_response, ChainSpecChainNameV1_request, ChainSpecChainNameV1_response, ChainSpecGenesisHashV1_request, ChainSpecGenesisHashV1_response, ChainSpecPropertiesV1_request, ChainSpecPropertiesV1_response, TransactionBroadcastV1_request, TransactionBroadcastV1_response, TransactionStopV1_request, TransactionStopV1_response, } from './v1/chainInteraction.js';
4
6
  import { ChatActionSubscribeV1_interrupt, ChatActionSubscribeV1_receive, ChatActionSubscribeV1_start, ChatCreateRoomV1_request, ChatCreateRoomV1_response, ChatCustomMessageRenderingV1_interrupt, ChatCustomMessageRenderingV1_receive, ChatCustomMessageRenderingV1_start, ChatListSubscribeV1_interrupt, ChatListSubscribeV1_receive, ChatListSubscribeV1_start, ChatPostMessageV1_request, ChatPostMessageV1_response, ChatRegisterBotV1_request, ChatRegisterBotV1_response, } from './v1/chat.js';
7
+ import { CoinPaymentCreateChequeV1_request, CoinPaymentCreateChequeV1_response, CoinPaymentCreatePurseV1_request, CoinPaymentCreatePurseV1_response, CoinPaymentCreateReceivableV1_request, CoinPaymentCreateReceivableV1_response, CoinPaymentDeletePurseV1_interrupt, CoinPaymentDeletePurseV1_receive, CoinPaymentDeletePurseV1_start, CoinPaymentDepositV1_interrupt, CoinPaymentDepositV1_receive, CoinPaymentDepositV1_start, CoinPaymentListenForPaymentV1_interrupt, CoinPaymentListenForPaymentV1_receive, CoinPaymentListenForPaymentV1_start, CoinPaymentQueryPurseV1_request, CoinPaymentQueryPurseV1_response, CoinPaymentRebalancePurseV1_interrupt, CoinPaymentRebalancePurseV1_receive, CoinPaymentRebalancePurseV1_start, CoinPaymentRefundV1_interrupt, CoinPaymentRefundV1_receive, CoinPaymentRefundV1_start, } from './v1/coinPayment.js';
5
8
  import { CreateTransactionV1_request, CreateTransactionV1_response, CreateTransactionWithLegacyAccountV1_request, CreateTransactionWithLegacyAccountV1_response, } from './v1/createTransaction.js';
6
9
  import { DeriveEntropyV1_request, DeriveEntropyV1_response } from './v1/deriveEntropy.js';
7
10
  import { DevicePermissionV1_request, DevicePermissionV1_response } from './v1/devicePermission.js';
8
11
  import { FeatureV1_request, FeatureV1_response } from './v1/feature.js';
9
12
  import { HandshakeV1_request, HandshakeV1_response } from './v1/handshake.js';
10
- import { StorageClearV1_request, StorageClearV1_response, StorageReadV1_request, StorageReadV1_response, StorageWriteV1_request, StorageWriteV1_response, } from './v1/localStorage.js';
13
+ import { StorageClearV1_request, StorageClearV1_response, StorageReadV1_request, StorageReadV1_response, StorageSubscribeV1_interrupt, StorageSubscribeV1_receive, StorageSubscribeV1_start, StorageWriteV1_request, StorageWriteV1_response, } from './v1/localStorage.js';
14
+ import { LocaleSubscribeV1_interrupt, LocaleSubscribeV1_receive, LocaleSubscribeV1_start } from './v1/locale.js';
11
15
  import { NavigateToV1_request, NavigateToV1_response } from './v1/navigation.js';
12
16
  import { PushNotificationCancelV1_request, PushNotificationCancelV1_response, PushNotificationV1_request, PushNotificationV1_response, } from './v1/notification.js';
13
17
  import { PaymentBalanceSubscribeV1_interrupt, PaymentBalanceSubscribeV1_receive, PaymentBalanceSubscribeV1_start, PaymentRequestV1_request, PaymentRequestV1_response, PaymentStatusSubscribeV1_interrupt, PaymentStatusSubscribeV1_receive, PaymentStatusSubscribeV1_start, PaymentTopUpV1_request, PaymentTopUpV1_response, } from './v1/payments.js';
@@ -16,7 +20,9 @@ import { RemotePermissionV1_request, RemotePermissionV1_response } from './v1/re
16
20
  import { RequestResourceAllocationV1_request, RequestResourceAllocationV1_response } from './v1/resourceAllocation.js';
17
21
  import { SignPayloadV1_request, SignPayloadV1_response, SignPayloadWithLegacyAccountV1_request, SignPayloadWithLegacyAccountV1_response, SignRawV1_request, SignRawV1_response, SignRawWithLegacyAccountV1_request, SignRawWithLegacyAccountV1_response, } from './v1/sign.js';
18
22
  import { StatementStoreCreateProofAuthorizedV1_request, StatementStoreCreateProofAuthorizedV1_response, StatementStoreCreateProofV1_request, StatementStoreCreateProofV1_response, StatementStoreSubmitV1_request, StatementStoreSubmitV1_response, StatementStoreSubscribeV1_interrupt, StatementStoreSubscribeV1_receive, StatementStoreSubscribeV1_start, } from './v1/statementStore.js';
23
+ import { GetProductContextV1_request, GetProductContextV1_response, HostInfoV1_request, HostInfoV1_response, } from './v1/system.js';
19
24
  import { ThemeSubscribeV1_interrupt, ThemeSubscribeV1_receive, ThemeSubscribeV1_start } from './v1/theme.js';
25
+ import { WorkerBeginOperationV1_request, WorkerBeginOperationV1_response, WorkerEndOperationV1_request, WorkerEndOperationV1_response, } from './v1/worker.js';
20
26
  const enumFromArg = (enumValues, n) => {
21
27
  return Enum(Object.fromEntries(Object.entries(enumValues).map(([key, value]) => [key, value[n]])));
22
28
  };
@@ -28,13 +34,21 @@ const versionedRequest = (index, values) => {
28
34
  response: enumFromArg(values, 1),
29
35
  };
30
36
  };
37
+ // Applies the transport-level `CallError` envelope to each typed interrupt
38
+ // codec (leaving `_void` interrupts, which carry no payload, untouched). The
39
+ // wrapped codec decodes back to the plain domain reason, so the static
40
+ // interrupt type is unchanged; only the wire bytes gain the `CallError` layer.
41
+ const wrapInterrupts = (values) => Object.fromEntries(Object.entries(values).map(([key, [start, receive, interrupt]]) => [
42
+ key,
43
+ [start, receive, interrupt === _void ? interrupt : interruptError(interrupt)],
44
+ ]));
31
45
  const versionedSubscription = (index, values) => {
32
46
  return {
33
47
  method: 'subscribe',
34
48
  index,
35
49
  start: enumFromArg(values, 0),
36
50
  receive: enumFromArg(values, 1),
37
- interrupt: enumFromArg(values, 2),
51
+ interrupt: enumFromArg(wrapInterrupts(values), 2),
38
52
  };
39
53
  };
40
54
  // Hands out contiguous serialization indices. Each call reserves the action's
@@ -223,15 +237,51 @@ export const hostApiProtocol = {
223
237
  host_push_notification_cancel: versionedRequest(indexer.request(), {
224
238
  v1: [PushNotificationCancelV1_request, PushNotificationCancelV1_response],
225
239
  }),
226
- // Prefix 28 skips indices 136-163, reserved upstream by the truapi coin-payment
227
- // methods this SDK does not implement, so `sign_vrf` lands on its specified
228
- // `request_id = 164` (RFC-0023).
229
- host_account_sign_vrf: versionedRequest(indexer.request(28), {
240
+ // RFC 0017 CoinPayment ids 136-163. Kept in wire order and directly before
241
+ // `sign_vrf` so the running index fills 136-163 and `sign_vrf` lands on its
242
+ // specified `request_id = 164` (RFC-0023) without a skip.
243
+ host_coin_payment_create_purse: versionedRequest(indexer.request(), {
244
+ v1: [CoinPaymentCreatePurseV1_request, CoinPaymentCreatePurseV1_response],
245
+ }),
246
+ host_coin_payment_query_purse: versionedRequest(indexer.request(), {
247
+ v1: [CoinPaymentQueryPurseV1_request, CoinPaymentQueryPurseV1_response],
248
+ }),
249
+ host_coin_payment_rebalance_purse: versionedSubscription(indexer.subscription(), {
250
+ v1: [CoinPaymentRebalancePurseV1_start, CoinPaymentRebalancePurseV1_receive, CoinPaymentRebalancePurseV1_interrupt],
251
+ }),
252
+ host_coin_payment_delete_purse: versionedSubscription(indexer.subscription(), {
253
+ v1: [CoinPaymentDeletePurseV1_start, CoinPaymentDeletePurseV1_receive, CoinPaymentDeletePurseV1_interrupt],
254
+ }),
255
+ host_coin_payment_create_receivable: versionedRequest(indexer.request(), {
256
+ v1: [CoinPaymentCreateReceivableV1_request, CoinPaymentCreateReceivableV1_response],
257
+ }),
258
+ host_coin_payment_create_cheque: versionedRequest(indexer.request(), {
259
+ v1: [CoinPaymentCreateChequeV1_request, CoinPaymentCreateChequeV1_response],
260
+ }),
261
+ host_coin_payment_deposit: versionedSubscription(indexer.subscription(), {
262
+ v1: [CoinPaymentDepositV1_start, CoinPaymentDepositV1_receive, CoinPaymentDepositV1_interrupt],
263
+ }),
264
+ host_coin_payment_refund: versionedSubscription(indexer.subscription(), {
265
+ v1: [CoinPaymentRefundV1_start, CoinPaymentRefundV1_receive, CoinPaymentRefundV1_interrupt],
266
+ }),
267
+ host_coin_payment_listen_for_payment: versionedSubscription(indexer.subscription(), {
268
+ v1: [
269
+ CoinPaymentListenForPaymentV1_start,
270
+ CoinPaymentListenForPaymentV1_receive,
271
+ CoinPaymentListenForPaymentV1_interrupt,
272
+ ],
273
+ }),
274
+ host_account_sign_vrf: versionedRequest(indexer.request(), {
230
275
  v1: [AccountSignVrfV1_request, AccountSignVrfV1_response],
231
276
  }),
232
- // RFC-0024 explicit ring VRF key management. Appended so every index above
233
- // stays stable; `create_proof` / `get_alias` changed shape in place instead,
234
- // since a key handle is now mandatory there.
277
+ // Resolves a logical chain role (relay, asset hub, ...) to its network and
278
+ // genesis hash. truapi places it at `request_id = 166`, between `sign_vrf`
279
+ // and the ring-VRF block, so it must keep this position to hold that id.
280
+ remote_chain_get_chain_info: versionedRequest(indexer.request(), {
281
+ v1: [ChainInfoV1_request, ChainInfoV1_response],
282
+ }),
283
+ // RFC-0024 — explicit ring VRF key management. `create_proof` / `get_alias`
284
+ // changed shape in place instead, since a key handle is now mandatory there.
235
285
  host_account_register_ring_vrf_key: versionedRequest(indexer.request(), {
236
286
  v1: [AccountRegisterRingVrfKeyV1_request, AccountRegisterRingVrfKeyV1_response],
237
287
  }),
@@ -241,4 +291,30 @@ export const hostApiProtocol = {
241
291
  host_account_ring_vrf_sign: versionedRequest(indexer.request(), {
242
292
  v1: [AccountRingVrfSignV1_request, AccountRingVrfSignV1_response],
243
293
  }),
294
+ // truapi jumps from the ring-VRF block (…172) straight to request_id 190,
295
+ // leaving request_ids 174-188 unassigned. The prefix skips that gap so
296
+ // `get_product_context` lands on its truapi request_id 190.
297
+ host_get_product_context: versionedRequest(indexer.request(16), {
298
+ v1: [GetProductContextV1_request, GetProductContextV1_response],
299
+ }),
300
+ // truapi request_id 192.
301
+ host_info: versionedRequest(indexer.request(), {
302
+ v1: [HostInfoV1_request, HostInfoV1_response],
303
+ }),
304
+ // truapi start_id 194.
305
+ host_locale_subscribe: versionedSubscription(indexer.subscription(), {
306
+ v1: [LocaleSubscribeV1_start, LocaleSubscribeV1_receive, LocaleSubscribeV1_interrupt],
307
+ }),
308
+ // Not in truapi — SDK-only additions from the 0.10.0 release. They sit after
309
+ // every truapi-defined method so truapi keeps sole ownership of ids 0-197 and
310
+ // future truapi methods slot in without colliding with these.
311
+ host_local_storage_subscribe: versionedSubscription(indexer.subscription(), {
312
+ v1: [StorageSubscribeV1_start, StorageSubscribeV1_receive, StorageSubscribeV1_interrupt],
313
+ }),
314
+ host_worker_begin_operation: versionedRequest(indexer.request(), {
315
+ v1: [WorkerBeginOperationV1_request, WorkerBeginOperationV1_response],
316
+ }),
317
+ host_worker_end_operation: versionedRequest(indexer.request(), {
318
+ v1: [WorkerEndOperationV1_request, WorkerEndOperationV1_response],
319
+ }),
244
320
  };